File tree Expand file tree Collapse file tree 2 files changed +35
-10
lines changed Expand file tree Collapse file tree 2 files changed +35
-10
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"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
+ },
3
24
{
4
25
"title" : " reactjs1111" ,
5
26
"body" : " reactjs" ,
66
87
{
67
88
"title" : " test4" ,
68
89
"body" : " test4" ,
69
- "publish" : false ,
90
+ "publish" : true ,
70
91
"createdAt" : 1647211557225 ,
71
92
"id" : 14
72
93
},
Original file line number Diff line number Diff line change @@ -12,13 +12,19 @@ const BlogList = ({ isAdmin }) => {
12
12
const [ loading , setLoading ] = useState ( true ) ;
13
13
14
14
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
+
15
26
axios . get ( `http://localhost:3001/posts` , {
16
- params : {
17
- _page : page ,
18
- _limit : 5 ,
19
- _sort : 'id' ,
20
- _order : 'desc' ,
21
- }
27
+ params
22
28
} ) . then ( ( res ) => {
23
29
setPosts ( res . data ) ;
24
30
setLoading ( false ) ;
@@ -47,9 +53,7 @@ const BlogList = ({ isAdmin }) => {
47
53
return ( < div > No blog posts found</ div > )
48
54
}
49
55
const renderBlogList = ( ) => {
50
- return posts . filter ( post => {
51
- return isAdmin || post . publish
52
- } ) . map ( post => {
56
+ return posts . map ( post => {
53
57
return (
54
58
< Card
55
59
key = { post . id }
You can’t perform that action at this time.
0 commit comments