From 12ec1fe6f6bcc096f97a79e04a9455f55986f377 Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Tue, 27 Oct 2015 01:02:39 +0100 Subject: [PATCH] Update comments count when commenting on a debate or proposal --- app/assets/javascripts/comments.js.coffee | 7 +++++++ app/views/debates/_comments.html.erb | 2 +- app/views/proposals/_comments.html.erb | 2 +- spec/features/comments/debates_spec.rb | 1 + spec/features/comments/proposals_spec.rb | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee index 8a9ebe0b1..cec074574 100644 --- a/app/assets/javascripts/comments.js.coffee +++ b/app/assets/javascripts/comments.js.coffee @@ -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}")) diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index 2a2fb518e..8aa26ed03 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -4,7 +4,7 @@

<%= t("debates.show.comments_title") %> - (<%= @debate.comments_count %>) + (<%= @debate.comments_count %>)

<% if user_signed_in? %> diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index f9047d83b..2442bd230 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -4,7 +4,7 @@

<%= t("proposals.show.comments_title") %> - (<%= @proposal.comments_count %>) + (<%= @proposal.comments_count %>)

<% if user_signed_in? %> diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index cafc5ff40..82d9708ad 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -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 diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 28f4f0d2d..751329989 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -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