app/views/decidim/comments/comments/update.js.erb in decidim-comments-0.25.0 vs app/views/decidim/comments/comments/update.js.erb in decidim-comments-0.25.1

- old
+ new

@@ -1,8 +1,22 @@ $(() => { - const commentHtml = '<%== j(render partial: "edited_comment", locals: { comment: @comment }).strip %>'; - const commentId = <%= @comment.id.to_json %>; - const $comment = $("#comment_<%= @comment.id %>"); - const $editCommentModal = $("#editCommentModal<%= @comment.id %>"); + var rootCommentableId = <%== "comments-for-#{@comment.commentable.commentable_type.demodulize}-#{@comment.commentable.id}".to_json %>; + var $comments = $("#" + rootCommentableId); + var config = $comments.data("decidim-comments"); + component = new Decidim.CommentsComponent($comments, config); + component.unmountComponent(); + + var commentHtml = '<%== j(render partial: "edited_comment", locals: { comment: @comment }).strip %>'; + var commentId = <%= @comment.id.to_json %>; + var $comment = $("#comment_<%= @comment.id %>"); + $comment.replaceWith(commentHtml); + + $comments = $("#" + rootCommentableId); + $comments.foundation(); + + // Re-create the component + component = new Decidim.CommentsComponent($comments, $comments.data("decidim-comments")); + component.mountComponent(); + $comments.data("comments", component); });