File tree Expand file tree Collapse file tree 3 files changed +30
-6
lines changed Expand file tree Collapse file tree 3 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ import Card from '../components/Card';
4
4
import { Link } from 'react-router-dom' ;
5
5
import { useHistory } from 'react-router' ;
6
6
import LoadingSpinner from '../components/LoadingSpinner' ;
7
+ import { bool } from 'prop-types' ;
7
8
8
- const BlogList = ( ) => {
9
+ const BlogList = ( { isAdmin } ) => {
9
10
const history = useHistory ( ) ;
10
11
const [ posts , setPosts ] = useState ( [ ] ) ;
11
12
const [ loading , setLoading ] = useState ( true ) ;
@@ -40,25 +41,33 @@ const BlogList = () => {
40
41
}
41
42
42
43
return posts . filter ( post => {
43
- return post . publish
44
+ return isAdmin || post . publish
44
45
} ) . map ( post => {
45
46
return (
46
47
< Card
47
48
key = { post . id }
48
49
title = { post . title }
49
50
onClick = { ( ) => history . push ( `/blogs/${ post . id } ` ) }
50
51
>
51
- < div >
52
+ { isAdmin ? ( < div >
52
53
< button
53
54
className = "btn btn-danger btn-sm"
54
55
onClick = { ( e ) => deleteBlog ( e , post . id ) }
55
56
>
56
57
Delete
57
58
</ button >
58
- </ div >
59
+ </ div > ) : null }
59
60
</ Card >
60
61
) ;
61
62
} )
62
63
} ;
63
64
65
+ BlogList . propTypes = {
66
+ isAdmin : bool
67
+ } ;
68
+
69
+ BlogList . defaultProps = {
70
+ isAdmin : false
71
+ }
72
+
64
73
export default BlogList ;
Original file line number Diff line number Diff line change @@ -5,7 +5,22 @@ const NavBar = () => {
5
5
< nav className = "navbar navbar-dark bg-dark" >
6
6
< div className = "container" >
7
7
< Link className = "navbar-brand" to = "/" > Home</ Link >
8
- < ul className = "navbar-nav" >
8
+ < ul
9
+ style = { {
10
+ flexDirection : 'row'
11
+ } }
12
+ className = "navbar-nav"
13
+ >
14
+ < li className = "nav-item me-2" >
15
+ < NavLink
16
+ activeClassName = "active"
17
+ className = "nav-link"
18
+ aria-current = "page"
19
+ to = "/admin"
20
+ >
21
+ Admin
22
+ </ NavLink >
23
+ </ li >
9
24
< li className = "nav-item" >
10
25
< NavLink
11
26
activeClassName = "active"
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const AdminPage = () => {
12
12
</ Link >
13
13
</ div >
14
14
</ div >
15
- < BlogList />
15
+ < BlogList isAdmin = { true } />
16
16
</ div >
17
17
) ;
18
18
} ;
You can’t perform that action at this time.
0 commit comments