Update comments count when commenting on a debate or proposal
This commit is contained in:
@@ -2,9 +2,16 @@ App.Comments =
|
||||
|
||||
add_comment: (parent_id, response_html) ->
|
||||
$(response_html).insertAfter($("#js-comment-form-#{parent_id}"))
|
||||
this.update_comments_count()
|
||||
|
||||
add_reply: (parent_id, response_html) ->
|
||||
$("##{parent_id} .comment-children:first").prepend($(response_html))
|
||||
this.update_comments_count()
|
||||
|
||||
update_comments_count: (parent_id) ->
|
||||
$(".js-comments-count").each ->
|
||||
new_val = $(this).text().trim().replace /\d+/, (match) -> parseInt(match, 10) + 1
|
||||
$(this).text(new_val)
|
||||
|
||||
display_error: (field_with_errors, error_html) ->
|
||||
$(error_html).insertAfter($("#{field_with_errors}"))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div id="comments" class="small-12 column">
|
||||
<h2>
|
||||
<%= t("debates.show.comments_title") %>
|
||||
<span>(<%= @debate.comments_count %>)</span>
|
||||
<span class="js-comments-count">(<%= @debate.comments_count %>)</span>
|
||||
</h2>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div id="comments" class="small-12 column">
|
||||
<h2>
|
||||
<%= t("proposals.show.comments_title") %>
|
||||
<span>(<%= @proposal.comments_count %>)</span>
|
||||
<span class="js-comments-count">(<%= @proposal.comments_count %>)</span>
|
||||
</h2>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
|
||||
@@ -85,6 +85,7 @@ feature 'Commenting debates' do
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content 'Have you thought about...?'
|
||||
expect(page).to have_content '(1)'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@ feature 'Commenting proposals' do
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content 'Have you thought about...?'
|
||||
expect(page).to have_content '(1)'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user