@@ -6,11 +6,68 @@ import {getCookie,isAuthenticated} from "../../actions/authentication";
66import { listingTheBlog , removingTheBlog , updatingTheBlog } from "../../actions/blog" ;
77import PublishIcon from '@material-ui/icons/Publish' ;
88import { ReactQuillModules , ReactQuillFormats } from "../../helpers/ReactQuill" ;
9+ import DeleteForeverIcon from '@material-ui/icons/DeleteForever' ;
10+ import moment from "moment" ;
911
1012const ReadNewBlog = ( ) => {
13+ const [ blogs , setBlogs ] = useState ( [ ] )
14+ const [ message , setMessage ] = useState ( '' )
15+ const token = getCookie ( 'token' )
16+
17+ const loadBlogs = ( ) => {
18+ listingTheBlog ( ) . then ( data => {
19+ if ( data . error ) {
20+ console . log ( data . error )
21+ } else {
22+ setBlogs ( data )
23+ }
24+ } )
25+ }
26+ useEffect ( ( ) => {
27+ loadBlogs ( ) ;
28+ } , [ ] )
29+
30+ const deleteTheBlog = ( slug ) => {
31+ removingTheBlog ( slug , token ) . then ( data => {
32+ if ( data . error ) {
33+ console . log ( data . error )
34+ } else {
35+ setMessage ( data . message )
36+ loadBlogs ( ) ;
37+ }
38+ } )
39+ }
40+
41+ const deleteConfirmation = ( ) => {
42+ let answer = window . confirm ( "Are you sure you want to delete this ?" )
43+ if ( answer ) {
44+ deleteTheBlog ( slug )
45+ }
46+ }
47+
48+ const showingAllBlogs = ( ) => {
49+ return blogs . map ( ( blog , index ) => {
50+ return (
51+ < div key = { index } className = "mt-4 pb-5" >
52+ < h3 > { blog . title } </ h3 >
53+ < div style = { { backgroundColor :"inset 0 0 2000px rgba(255, 255, 255, .5)" , filter :"blur(0.7px)" , fontSize :"15px" } } > Author : { blog . postedBy . name } | Published { moment ( blog . updatedAt ) . fromNow ( ) } </ div >
54+ < button className = "btn btn-sm btn-danger" onClick = { ( ) => deleteConfirmation ( blog . slug ) } > < DeleteForeverIcon /> Delete</ button >
55+
56+ </ div >
57+ )
58+ } )
59+ }
60+
1161 return (
1262 < >
13- < p > Update Blogs</ p >
63+ < div className = "container" >
64+ < div className = "row" >
65+ < div className = "col-md-12" >
66+ { message && < div className = "alert alert-warning" > { message } </ div > }
67+ { showingAllBlogs ( ) }
68+ </ div >
69+ </ div >
70+ </ div >
1471 </ >
1572 )
1673}
0 commit comments