Update parent comment responses count when a new reply is created

Extract the needed portion of code to a new partial to be able to update
only the elements needed when a new comment is added keeping UI properly
updated.
This commit is contained in:
Senén Rodero Rodríguez
2020-05-08 07:00:30 +02:00
parent 095abbf9a7
commit 956f002738
12 changed files with 144 additions and 9 deletions

View File

@@ -85,15 +85,9 @@
</div>
<% end %>
<% if comment.children.size > 0 %>
<%= link_to "", class: "js-toggle-children relative" do %>
<span class="far fa-minus-square"></span>
<span class="js-child-toggle" style="display: none;"><%= t("comments.comment.responses_show", count: comment.children.size) %></span>
<span class="js-child-toggle"><%= t("comments.comment.responses_collapse", count: comment.children.size) %></span>
<% end %>
<% else %>
<%= t("comments.comment.responses", count: 0) %>
<% end %>
<span class="responses-count">
<%= render "comments/responses_count", count: comment.children.size %>
</span>
<% if user_signed_in? && !comments_closed_for_commentable?(comment.commentable) && !require_verified_resident_for_commentable?(comment.commentable, current_user) %>
<span class="divider">&nbsp;|&nbsp;</span>

View File

@@ -0,0 +1,9 @@
<% if count > 0 %>
<%= link_to "", class: "js-toggle-children relative" do %>
<span class="far fa-minus-square"></span>
<span class="js-child-toggle" style="display: none;"><%= t("comments.comment.responses_show", count: count) %></span>
<span class="js-child-toggle"><%= t("comments.comment.responses_collapse", count: count) %></span>
<% end %>
<% else %>
<%= t("comments.comment.responses", count: 0) %>
<% end %>

View File

@@ -2,6 +2,8 @@
var parent_id = "";
<% else -%>
var parent_id = "#" + "<%= "comment_#{@comment.parent_id}" %>";
var responses_count_html = "<%= j(render "comments/responses_count", count: @comment.parent.children.size) %>"
App.Comments.update_responses_count(parent_id, responses_count_html);
<% end -%>
App.Comments.reset_form(parent_id);