Skip to content

Commit 6cb35b0

Browse files
committed
part 3
1 parent f5843d2 commit 6cb35b0

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed

src/components/App.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.app {
2+
margin: 20px;
3+
}
4+
5+
.interactions, .error {
6+
text-align: center;
7+
}

src/components/Stories.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.stories {
2+
margin: 20px 0;
3+
}
4+
5+
.stories-header {
6+
display: flex;
7+
line-height: 24px;
8+
font-size: 16px;
9+
padding: 0 10px;
10+
justify-content: space-between;
11+
}
12+
13+
.stories-header > span {
14+
overflow: hidden;
15+
text-overflow: ellipsis;
16+
padding: 0 5px;
17+
}

src/components/Stories.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,51 @@ import './Stories.css';
33

44
import Story from './Story';
55

6+
const COLUMNS = {
7+
title: {
8+
label: 'Title',
9+
width: '40%',
10+
},
11+
author: {
12+
label: 'Author',
13+
width: '30%',
14+
},
15+
comments: {
16+
label: 'Comments',
17+
width: '10%',
18+
},
19+
points: {
20+
label: 'Points',
21+
width: '10%',
22+
},
23+
archive: {
24+
width: '10%',
25+
},
26+
};
27+
628
const Stories = ({ stories }) =>
729
<div className="stories">
30+
<StoriesHeader columns={COLUMNS} />
31+
832
{(stories || []).map(story =>
933
<Story
1034
key={story.objectID}
1135
story={story}
36+
columns={COLUMNS}
1237
/>
1338
)}
1439
</div>
1540

41+
const StoriesHeader = ({ columns }) =>
42+
<div className="stories-header">
43+
{Object.keys(columns).map(key =>
44+
<span
45+
key={key}
46+
style={{ width: columns[key].width }}
47+
>
48+
{columns[key].label}
49+
</span>
50+
)}
51+
</div>
52+
1653
export default Stories;

src/components/Story.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.story {
2+
display: flex;
3+
line-height: 24px;
4+
white-space: nowrap;
5+
margin: 10px 0;
6+
padding: 10px;
7+
background: #ffffff;
8+
border: 1px solid #e3e3e3;
9+
}
10+
11+
.story > span {
12+
overflow: hidden;
13+
text-overflow: ellipsis;
14+
padding: 0 5px;
15+
}

src/components/Story.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import './Story.css';
33

4-
const Story = ({ story }) => {
4+
const Story = ({ story, columns }) => {
55
const {
66
title,
77
url,
@@ -12,12 +12,20 @@ const Story = ({ story }) => {
1212

1313
return (
1414
<div className="story">
15-
<span>
15+
<span style={{ width: columns.title.width }}>
1616
<a href={url}>{title}</a>
1717
</span>
18-
<span>{author}</span>
19-
<span>{num_comments}</span>
20-
<span>{points}</span>
18+
<span style={{ width: columns.author.width }}>
19+
{author}
20+
</span>
21+
<span style={{ width: columns.comments.width }}>
22+
{num_comments}
23+
</span>
24+
<span style={{ width: columns.points.width }}>
25+
{points}
26+
</span>
27+
<span style={{ width: columns.archive.width }}>
28+
</span>
2129
</div>
2230
);
2331
}

0 commit comments

Comments
 (0)