Skip to content

Commit a1415fa

Browse files
committed
Article page
1 parent 972abe6 commit a1415fa

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed

src/components/Article.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
.loading-container {
2+
height: 100%;
3+
display: flex;
4+
justify-content: center;
5+
align-items: center;
6+
7+
.loading {
8+
font-size: 32px;
9+
}
10+
}
11+
112
.article-banner {
213
height: 240px;
14+
background: linear-gradient(10deg, #3a7bd5, #00d2ff);
315
background-size: cover;
4-
background-position: center;
516
justify-content: flex-end;
617

718
.banner-head {
819
font-size: 32px;
9-
padding-bottom: 16px;
1020
}
1121
}

src/components/Article.tsx

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,29 @@ import ArticleType from '../types/Article';
88
interface ArticleRouterProps { id: number; }
99
interface ArticleProps extends RouteComponentProps<ArticleRouterProps> {}
1010

11+
enum Status {
12+
Loading,
13+
OK,
14+
NotFound,
15+
}
16+
1117
interface State {
12-
article?: ArticleType;
18+
status: Status;
19+
article: ArticleType;
1320
}
1421

1522
export default class Article extends React.Component<ArticleProps> {
16-
state: State = {};
23+
state: State = {
24+
status: Status.Loading,
25+
article: {
26+
id: 0,
27+
title: '',
28+
author: 0,
29+
tag: [],
30+
date: new Date(),
31+
content: ''
32+
}
33+
};
1734

1835
componentDidMount() {
1936
const id = this.props.match.params.id;
@@ -29,36 +46,44 @@ export default class Article extends React.Component<ArticleProps> {
2946
技术随着时间推移变得愈发出神入化,智慧的足迹踏遍银河系的颗行星,\
3047
冒险家的故事传颂在整个星河。'
3148
};
32-
this.setState({ article });
49+
50+
this.setState({
51+
article,
52+
status: Status.OK
53+
});
3354
}
3455

3556
render() {
57+
if (this.state.status === Status.Loading) {
58+
return (
59+
<div className="flex-spacer">
60+
<div className="container loading-container">
61+
<div className="loading">Loading...</div>
62+
</div>
63+
</div>
64+
);
65+
}
66+
67+
const article = this.state.article;
68+
3669
return (
37-
<div>
70+
<div className="flex-spacer">
3871
<Layout.Content className="banner article-banner">
3972
<div className="container">
4073
<div className="banner-head">
41-
{this.state.article ? this.state.article.title : ''}
74+
{article.title}
4275
</div>
76+
<p>{article.date.toLocaleDateString() + ' ' + article.date.toLocaleTimeString()}</p>
4377
</div>
4478
</Layout.Content>
4579

4680
<Layout.Content className="container main">
4781
<Row>
4882
<Col span={16} className="news">
49-
{typeof this.state.article === 'undefined' ? ('404') : (
50-
<Card
51-
key={this.state.article.id}
52-
bordered={false}
53-
className="article"
54-
>
55-
<div>{this.state.article.content}</div>
56-
<div>
57-
<Tag>{this.state.article.tag[0]}</Tag>
58-
<Tag>{this.state.article.tag[1]}</Tag>
59-
</div>
60-
</Card>
61-
)}
83+
<Card key={article.id} bordered={false} className="article">
84+
<div>{article.content}</div>
85+
<div>{article.tag.map((tag, i) => <Tag key={i}>{tag}</Tag>)}</div>
86+
</Card>
6287
</Col>
6388

6489
<Sidebar />

src/components/Home.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@
6565
}
6666

6767
.pagination {
68-
margin: 24px 0 12px;
68+
margin: 24px auto 12px;
6969
}

src/components/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class Home extends React.Component {
2929

3030
render() {
3131
return (
32-
<div>
32+
<div className="flex-spacer">
3333
<Layout.Content className="banner">
3434
<div className="container">
3535
<div className="banner-head">

src/components/Layout.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
}
6969
}
7070

71+
.main {
72+
margin-top: 24px;
73+
}
74+
7175
.main-footer {
7276
text-align: center;
7377
background: #f5f5f5;

src/index.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ p {
2626
align-self: center;
2727
}
2828

29-
.main {
30-
margin-top: 32px;
31-
}
32-
3329
.ant-card {
3430
font-size: 14px;
3531
}

0 commit comments

Comments
 (0)