Skip to content

Commit 2202c30

Browse files
deleting blogs from the client side
1 parent ad0bffb commit 2202c30

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

client/components/update/ReadNewBlog.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,68 @@ import {getCookie,isAuthenticated} from "../../actions/authentication";
66
import {listingTheBlog,removingTheBlog,updatingTheBlog} from "../../actions/blog";
77
import PublishIcon from '@material-ui/icons/Publish';
88
import {ReactQuillModules,ReactQuillFormats} from "../../helpers/ReactQuill";
9+
import DeleteForeverIcon from '@material-ui/icons/DeleteForever';
10+
import moment from "moment";
911

1012
const 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
}

client/pages/adminDashboard/update/editBlog.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import BookIcon from '@material-ui/icons/Book';
1010
import PostAddIcon from '@material-ui/icons/PostAdd';
1111
// import MenuIcon from "@material-ui/icons/Menu";
1212
// import BigMenu from "@material-ui/icons/MenuIcons";
13+
import CreateIcon from '@material-ui/icons/Create';
1314

1415

1516

@@ -21,9 +22,8 @@ const Editblog =() =>{
2122
<div className="row">
2223
<div className="col-md-12">
2324
<h1 className="text-center">
24-
<PostAddIcon style={{"color":"pink"}}/>
25-
Create a new blog
26-
<BookIcon style={{"color":"teal"}}/>
25+
Edit Blogs
26+
<CreateIcon style={{"color":"teal"}}/>
2727
</h1>
2828
</div>
2929
<div className="col-md-12">

0 commit comments

Comments
 (0)