Skip to content

Commit ba9599d

Browse files
committed
54
1 parent aad696b commit ba9599d

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

db.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
{
22
"posts": [
3+
{
4+
"title": "reactjs123123",
5+
"body": "reactjs",
6+
"createdAt": 1644556415774,
7+
"id": 1,
8+
"publish": true
9+
},
10+
{
11+
"title": "reactjs345345",
12+
"body": "reactjs",
13+
"createdAt": 1644556415774,
14+
"id": 2,
15+
"publish": true
16+
},
17+
{
18+
"title": "reactjs456456",
19+
"body": "reactjs",
20+
"createdAt": 1644556415774,
21+
"id": 3,
22+
"publish": true
23+
},
324
{
425
"title": "reactjs1111",
526
"body": "reactjs",
@@ -66,7 +87,7 @@
6687
{
6788
"title": "test4",
6889
"body": "test4",
69-
"publish": false,
90+
"publish": true,
7091
"createdAt": 1647211557225,
7192
"id": 14
7293
},

src/components/BlogList.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ const BlogList = ({ isAdmin }) => {
1212
const [loading, setLoading] = useState(true);
1313

1414
const getPosts = (page = 1) => {
15+
let params = {
16+
_page: page,
17+
_limit: 5,
18+
_sort: 'id',
19+
_order: 'desc',
20+
}
21+
22+
if (!isAdmin) {
23+
params = { ...params, publish: true };
24+
}
25+
1526
axios.get(`http://localhost:3001/posts`, {
16-
params: {
17-
_page: page,
18-
_limit: 5,
19-
_sort: 'id',
20-
_order: 'desc',
21-
}
27+
params
2228
}).then((res) => {
2329
setPosts(res.data);
2430
setLoading(false);
@@ -47,9 +53,7 @@ const BlogList = ({ isAdmin }) => {
4753
return (<div>No blog posts found</div>)
4854
}
4955
const renderBlogList = () => {
50-
return posts.filter(post => {
51-
return isAdmin || post.publish
52-
}).map(post => {
56+
return posts.map(post => {
5357
return (
5458
<Card
5559
key={post.id}

0 commit comments

Comments
 (0)