diff --git a/public/utils.js b/public/utils.js index a07028b..13dc394 100644 --- a/public/utils.js +++ b/public/utils.js @@ -55,6 +55,11 @@ function commentClick(e) { targ = form } else { return } e.target.disabled = "disabled" + if (data.get("op") == "delete_comment") { + if (!confirm("Are you sure you want to delete?")) { + return false + } + } request(targ.action || "", data, function(res){ if (data.get("op") == "block_user") { diff --git a/routes.go b/routes.go index 7b2dfc0..f82a499 100644 --- a/routes.go +++ b/routes.go @@ -1297,7 +1297,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { postid, _ := strconv.Atoi(ps.ByName("postid")) state.PostID = postid } - if r.FormValue("parentid") != "" { + if r.FormValue("parentid") != "" && r.FormValue("parentid") != "0" { parentid, _ := strconv.Atoi(r.FormValue("parentid")) state.GetComment(parentid) } @@ -1428,6 +1428,13 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { if err != nil { fmt.Println(err) } else { + if r.FormValue("xhr") != "" { + state.XHR = true + state.Comments = append(state.Comments, Comment{P: resp.CommentView, State: &state}) + state.CommentID = commentid + Render(w, "index.html", state) + return + } commentid := strconv.Itoa(resp.CommentView.Comment.ID) r.URL.Fragment = "c" + commentid r.URL.RawQuery = "" diff --git a/templates/comment.html b/templates/comment.html index befaee6..179a7b0 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -61,13 +61,15 @@ {{ if .State.Session }} {{ if and (eq .P.Comment.CreatorID .State.Session.UserID) (ne .Op "edit") }}