-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.tsx
80 lines (69 loc) · 2.13 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { PureComponent } from 'react';
import { Col, Container, Row } from 'react-bootstrap';
import { ArticleListLayout } from '../../../components/Article/List';
import { CommentBox } from '../../../components/CommentBox';
import PageHead from '../../../components/PageHead';
import {
Article,
ArticleModel,
SearchArticleModel,
} from '../../../models/Article';
import { i18n } from '../../../models/Translation';
import { withErrorLog } from '../../api/base';
export const getServerSideProps = withErrorLog<
{ id: string },
{ article: Article; recommends: Article[] }
>(async ({ params }) => {
const articleStore = new ArticleModel();
const article = await articleStore.getOne(params!.id);
return {
props: {
article,
recommends: articleStore.currentRecommend!.currentPage,
},
};
});
export default class ArticleDetailPage extends PureComponent<
InferGetServerSidePropsType<typeof getServerSideProps>
> {
renderAuthorization() {
const { license = 'CC-4.0' } = this.props.article;
return (
<>
<p className="text-muted mt-3 small">版权声明:{license}</p>
</>
);
}
render() {
const { title, content, tags } = this.props.article,
{ recommends } = this.props;
return (
<Container className="py-5">
<PageHead title={title + ''} />
<Row>
<Col
as="article"
xs={12}
sm={9}
dangerouslySetInnerHTML={{ __html: content! }}
/>
<Col xs={12} sm={3}>
{this.renderAuthorization()}
<ScrollList
translator={i18n}
store={new SearchArticleModel()}
filter={{ tags: (tags + '').split(/\s+/) }}
renderList={allItems => (
<ArticleListLayout defaultData={allItems} rowCols={{ xs: 1 }} />
)}
defaultData={recommends}
/>
</Col>
</Row>
<CommentBox category="General" categoryId="DIC_kwDOB88JLM4COLSV" />
</Container>
);
}
}