File tree Expand file tree Collapse file tree 3 files changed +83
-20
lines changed Expand file tree Collapse file tree 3 files changed +83
-20
lines changed Original file line number Diff line number Diff line change 41
41
"publish" : false ,
42
42
"createdAt" : 1647211425309 ,
43
43
"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
44
79
}
45
80
]
46
81
}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import Card from '../components/Card';
4
4
import { useHistory } from 'react-router' ;
5
5
import LoadingSpinner from '../components/LoadingSpinner' ;
6
6
import { bool } from 'prop-types' ;
7
+ import Pagination from './Pagination' ;
7
8
8
9
const BlogList = ( { isAdmin } ) => {
9
10
const history = useHistory ( ) ;
@@ -38,27 +39,35 @@ const BlogList = ({ isAdmin }) => {
38
39
if ( posts . length === 0 ) {
39
40
return ( < div > No blog posts found</ div > )
40
41
}
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
+ }
41
64
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
+ )
62
71
} ;
63
72
64
73
BlogList . propTypes = {
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments