diff options
author | HombreLaser <buran@silosneeded.com> | 2024-03-03 20:50:11 -0600 |
---|---|---|
committer | HombreLaser <buran@silosneeded.com> | 2024-03-03 20:50:11 -0600 |
commit | ae390aabc9a19e680531241e028877c7ab9a3631 (patch) | |
tree | 42b0f495bdb2025b11fc30a35f52b2f1143e4ef3 /static | |
parent | b76df14f11491a4086d08ad5ff4bdb8f203e647f (diff) |
Improve replies handling
Diffstat (limited to 'static')
-rw-r--r-- | static/js/controllers/replies_controller.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/static/js/controllers/replies_controller.js b/static/js/controllers/replies_controller.js index e76179d..119062c 100644 --- a/static/js/controllers/replies_controller.js +++ b/static/js/controllers/replies_controller.js @@ -23,10 +23,8 @@ export class RepliesController extends BaseController { listenButtons(class_name, func) { const buttons = document.getElementsByClassName(class_name); - if (buttons) { - for (let button of buttons) - button.addEventListener("click", func); - } + for (let button of buttons) + button.addEventListener("click", func); } showReplyForm(event) { @@ -44,7 +42,7 @@ export class RepliesController extends BaseController { renderReplies(event) { /* The div to contain the comment's replies. From the element id we can get the comment's id. */ - const comment_replies_section = event.target.parentElement.parentElement.parentElement; + const comment_replies_section = event.target.parentElement.parentElement.querySelector(".comment-replies"); const present_replies = comment_replies_section.querySelector(".replies-section"); this.setCommentId(comment_replies_section); @@ -62,6 +60,17 @@ export class RepliesController extends BaseController { }); } + renderSubmitResponse(response_document) { + const comment = document.getElementById(`comment-${this.comment_id}`); + const present_replies = comment.querySelector(".replies-section"); + const new_comment_replies = this.htmlFromResponse(response_document).getElementById(`replies-section-${this.comment_id}`) + + if(present_replies != null) + present_replies.replaceWith(new_comment_replies); + else + comment.appendChild(new_comment_replies); + } + setCommentId(replies_section) { this.comment_id = /\d/.exec(replies_section.id)[0]; } |