Skip to content

Commit c73475d

Browse files
committed
add delete option in comments
1 parent a3fe0e0 commit c73475d

File tree

7 files changed

+36
-35
lines changed

7 files changed

+36
-35
lines changed

public/stylesheets/style.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ body{
6767
}
6868

6969
/* icon */
70-
.icon .fa {
70+
.icon {
7171
font-size: 1.5em;
7272
}
7373

@@ -109,6 +109,17 @@ body{
109109
color: hsl(0, 0%, 21%);
110110
}
111111

112+
#remove-icon {
113+
color: rgba(196, 62, 62, 0.726);
114+
background: transparent;
115+
border: 0;
116+
cursor: pointer;
117+
}
118+
119+
#remove-icon:hover {
120+
color: rgb(255, 0, 0);
121+
}
122+
112123
.nav-item {
113124
padding: 10px;
114125
color: white;

routes/blogs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ router.get("/blog/:id", function(req, res) {
3737
console.log(err);
3838
}
3939
else{
40-
console.log(foundBlog)
4140
res.render("blogs/info", {blog: foundBlog})
4241
}
4342
})

routes/comments.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Comment = require("../models/comment");
55
var middleware = require("../middleware")
66

77
//POST
8-
router.post("/blog/:id/comment", function(req, res){
8+
router.post("/blog/:id/comment", middleware.isLoggedIn, function(req, res){
99
console.log(req.params.id)
1010
Blog.findById(req.params.id, function(err, blog){
1111
if(err){
@@ -30,35 +30,16 @@ router.post("/blog/:id/comment", function(req, res){
3030
})
3131
})
3232

33-
// //EDIT
34-
// router.get("/:comment_id/edit", middleware.checkCommentOwnership, function(req, res){
35-
// Blog.findById(req.params.comment_id, function(err, foundComment){
36-
// if(err){
37-
// res.redirect("back")
38-
// } else{
39-
// res.render("comments/edit", {campgroundid: req.params.id, comment: foundComment})
40-
// }
41-
// })
42-
// })
43-
44-
// //UPDATE
45-
// router.put("/:comment_id", middleware.checkCommentOwnership, function(req, res){
46-
// Comment.findByIdAndUpdate(req.params.comment_id, req.body.comment, function(err, updatedComment){
47-
// if(err){
48-
// res.redirect("back")
49-
// } else{
50-
// res.redirect("/campgrounds/"+req.params.id)
51-
// }
52-
// })
53-
// })
54-
5533
//DELETE
56-
router.delete("/:comment_id", middleware.checkCommentOwnership, function(req, res){
57-
Blog.findByIdAndRemove(req.params.comment_id, function(err){
34+
router.delete("/blog/:id/comment/:comment_id", middleware.checkCommentOwnership, function(req, res){
35+
console.log("hey")
36+
Comment.findByIdAndRemove(req.params.comment_id, function(err){
5837
if(err){
38+
console.log("err: ", err)
5939
res.redirect("back")
6040
} else{
6141
// req.flash("success", "Comments Deleted!")
42+
console.log("deleted successfully")
6243
res.redirect("/blog/"+req.params.id)
6344
}
6445
})

views/blogs/info.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<div class="columns is-centered is-multiline">
8787
<div class="column is-6">
8888
<strong><%=comment.author.username%></strong> - <%=comment.text%>
89+
<%if(currentUser && comment.author.id.equals(currentUser._id)) {%>
90+
<form action="/blog/<%=blog._id%>/comment/<%=comment._id%>?_method=DELETE" method="POST" style="display: inline;">
91+
<button id="remove-icon" class="fas fa-minus-circle"></button>
92+
</form>
93+
<%}%>
8994
</div>
9095
</div>
9196
<%})%>

views/blogs/new.ejs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<%- include('../partials/header') %>
2-
<center><h3 class="title is-3" style="padding: 50px;">Creat a New Blog</h3></center>
2+
<center><h3 class="title is-3" style="padding: 50px;">Create a New Blog</h3></center>
33
<form action="/blogs" method="POST" style="margin: auto; width: 40%;">
44
<div class="field">
5-
<input class="input is-info" type="text" name="title" placeholder="Title" required>
5+
<label class="label">Title:</label>
6+
<input class="input is-info" type="text" name="title" placeholder="Title" required>
67
</div>
78
<div class="field">
9+
<label class="label">Image URL:</label>
810
<input class="input is-info" type="text" name="image" placeholder="Image URL">
911
</div>
1012
<div class="field">
11-
<textarea id="content" class="textarea is-info" name="body" rows="10" placeholder="Body (Markdown in Supported!)"></textarea>
13+
<label class="label">Body (Supports Markdown):</label>
14+
<textarea id="content" class="textarea is-info" name="body" rows="10" placeholder="Body"></textarea>
1215
</div>
13-
<button class="button is-info is-outlined">Create</button>
16+
<span style="display: inline-flex;">
17+
<button class="button is-info is-outlined" style="margin-right: 10px;">Create</button>
18+
</span>
1419
</form>
1520
<%- include('../partials/footer') %>

views/partials/footer.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<div class="nav-center">
77
<a class="nav-item">
88
<span class="icon">
9-
<i class="fa fa-twitter"></i>
9+
<i class="fab fa-twitter fa-lg"></i>
1010
</span>
1111
</a>
1212
<a class="nav-item">
1313
<span class="icon">
14-
<i class="fa fa-facebook"></i>
14+
<i class="fab fa-facebook fa-lg"></i>
1515
</span>
1616
</a>
1717
<a class="nav-item">
1818
<span class="icon">
19-
<i class="fa fa-github"></i>
19+
<i class="fab fa-github fa-lg"></i>
2020
</span>
2121
</a>
2222
</div>

views/partials/header.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!-- styles and fonts -->
66
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
77
<link rel="stylesheet" href="/stylesheets/style.css">
8-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
1010
<!-- end of styles and fonts -->
1111
</head>

0 commit comments

Comments
 (0)