Skip to content

Commit 8503107

Browse files
committed
51
1 parent 1d5d346 commit 8503107

File tree

3 files changed

+83
-20
lines changed

3 files changed

+83
-20
lines changed

db.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@
4141
"publish": false,
4242
"createdAt": 1647211425309,
4343
"id": 10
44+
},
45+
{
46+
"title": "test1",
47+
"body": "test1",
48+
"publish": false,
49+
"createdAt": 1647211538719,
50+
"id": 11
51+
},
52+
{
53+
"title": "test2",
54+
"body": "test2",
55+
"publish": false,
56+
"createdAt": 1647211545153,
57+
"id": 12
58+
},
59+
{
60+
"title": "test3",
61+
"body": "test3",
62+
"publish": false,
63+
"createdAt": 1647211550036,
64+
"id": 13
65+
},
66+
{
67+
"title": "test4",
68+
"body": "test4",
69+
"publish": false,
70+
"createdAt": 1647211557225,
71+
"id": 14
72+
},
73+
{
74+
"title": "test5",
75+
"body": "test5",
76+
"publish": false,
77+
"createdAt": 1647211568779,
78+
"id": 15
4479
}
4580
]
4681
}

src/components/BlogList.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Card from '../components/Card';
44
import { useHistory } from 'react-router';
55
import LoadingSpinner from '../components/LoadingSpinner';
66
import { bool } from 'prop-types';
7+
import Pagination from './Pagination';
78

89
const BlogList = ({ isAdmin }) => {
910
const history = useHistory();
@@ -38,27 +39,35 @@ const BlogList = ({ isAdmin }) => {
3839
if (posts.length === 0) {
3940
return (<div>No blog posts found</div>)
4041
}
42+
const renderBlogList = () => {
43+
return posts.filter(post => {
44+
return isAdmin || post.publish
45+
}).map(post => {
46+
return (
47+
<Card
48+
key={post.id}
49+
title={post.title}
50+
onClick={() => history.push(`/blogs/${post.id}`)}
51+
>
52+
{isAdmin ? (<div>
53+
<button
54+
className="btn btn-danger btn-sm"
55+
onClick={(e) => deleteBlog(e, post.id)}
56+
>
57+
Delete
58+
</button>
59+
</div>) : null}
60+
</Card>
61+
);
62+
})
63+
}
4164

42-
return posts.filter(post => {
43-
return isAdmin || post.publish
44-
}).map(post => {
45-
return (
46-
<Card
47-
key={post.id}
48-
title={post.title}
49-
onClick={() => history.push(`/blogs/${post.id}`)}
50-
>
51-
{isAdmin ? (<div>
52-
<button
53-
className="btn btn-danger btn-sm"
54-
onClick={(e) => deleteBlog(e, post.id)}
55-
>
56-
Delete
57-
</button>
58-
</div>) : null}
59-
</Card>
60-
);
61-
})
65+
return (
66+
<div>
67+
{renderBlogList()}
68+
<Pagination />
69+
</div>
70+
)
6271
};
6372

6473
BlogList.propTypes = {

src/components/Pagination.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Pagination = () => {
2+
return (
3+
<nav aria-label="Page navigation example">
4+
<ul className="pagination justify-content-center">
5+
<li className="page-item disabled">
6+
<a className="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
7+
</li>
8+
<li className="page-item"><a className="page-link" href="#">1</a></li>
9+
<li className="page-item"><a className="page-link" href="#">2</a></li>
10+
<li className="page-item"><a className="page-link" href="#">3</a></li>
11+
<li className="page-item">
12+
<a className="page-link" href="#">Next</a>
13+
</li>
14+
</ul>
15+
</nav>
16+
)
17+
}
18+
19+
export default Pagination;

0 commit comments

Comments
 (0)