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:
@@ -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"> | </span>
|
||||
|
||||
9
app/views/comments/_responses_count.html.erb
Normal file
9
app/views/comments/_responses_count.html.erb
Normal 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 %>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user