diff --git a/app/components/shared/comments_component.html.erb b/app/components/shared/comments_component.html.erb new file mode 100644 index 000000000..9dd3ab9c3 --- /dev/null +++ b/app/components/shared/comments_component.html.erb @@ -0,0 +1,19 @@ +<% cache [locale_and_user_status, current_order, commentable_cache_key(record), comment_tree.comments, comment_tree.comment_authors, record.comments_count] do %> +
+
+ <%= content %> + + <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> + + <% if current_user %> + <%= render "comments/form", { commentable: record, parent_id: nil } %> + <% else %> +
+ <%= render "shared/login_to_comment" %> + <% end %> + + <%= render "comments/comment_list", comments: comment_tree.root_comments %> + <%= paginate comment_tree.root_comments %> +
+
+<% end %> diff --git a/app/components/shared/comments_component.rb b/app/components/shared/comments_component.rb new file mode 100644 index 000000000..01a1eff86 --- /dev/null +++ b/app/components/shared/comments_component.rb @@ -0,0 +1,9 @@ +class Shared::CommentsComponent < ApplicationComponent + attr_reader :record, :comment_tree + delegate :current_user, :current_order, :locale_and_user_status, :commentable_cache_key, to: :helpers + + def initialize(record, comment_tree) + @record = record + @comment_tree = comment_tree + end +end diff --git a/app/controllers/concerns/has_orders.rb b/app/controllers/concerns/has_orders.rb index 40dcac20f..cabd5ad79 100644 --- a/app/controllers/concerns/has_orders.rb +++ b/app/controllers/concerns/has_orders.rb @@ -1,5 +1,10 @@ module HasOrders extend ActiveSupport::Concern + attr_reader :valid_orders, :current_order + + included do + helper_method :valid_orders, :current_order + end class_methods do def has_orders(valid_orders, *args) diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index 9b0348930..adaec8a3e 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -1,22 +1,6 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@debate), @comment_tree.comments, @comment_tree.comment_authors, @debate.comments_count] do %> -
-
-

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

- - <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render "comments/form", { commentable: @debate, parent_id: nil } %> - <% else %> -
- <%= render "shared/login_to_comment" %> - <% end %> - - <%= render "comments/comment_list", comments: @comment_tree.root_comments %> - <%= paginate @comment_tree.root_comments %> -
-
+<%= render Shared::CommentsComponent.new(@debate, @comment_tree) do %> +

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

<% end %> diff --git a/app/views/legislation/proposals/_comments.html.erb b/app/views/legislation/proposals/_comments.html.erb index a8e657835..43d690b35 100644 --- a/app/views/legislation/proposals/_comments.html.erb +++ b/app/views/legislation/proposals/_comments.html.erb @@ -1,17 +1 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count] do %> -
-
- <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render "comments/form", { commentable: @proposal, parent_id: nil } %> - <% else %> -
- <%= render "shared/login_to_comment" %> - <% end %> - - <%= render "comments/comment_list", comments: @comment_tree.root_comments %> - <%= paginate @comment_tree.root_comments %> -
-
-<% end %> +<%= render Shared::CommentsComponent.new(@proposal, @comment_tree) %> diff --git a/app/views/polls/_comments.html.erb b/app/views/polls/_comments.html.erb index b99b9f351..b937ca015 100644 --- a/app/views/polls/_comments.html.erb +++ b/app/views/polls/_comments.html.erb @@ -1,17 +1 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@poll), @comment_tree.comments, @comment_tree.comment_authors, @poll.comments_count] do %> -
-
- <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render "comments/form", { commentable: @poll, parent_id: nil } %> - <% else %> -
- <%= render "shared/login_to_comment" %> - <% end %> - - <%= render "comments/comment_list", comments: @comment_tree.root_comments %> - <%= paginate @comment_tree.root_comments %> -
-
-<% end %> +<%= render Shared::CommentsComponent.new(@poll, @comment_tree) %> diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index a8e657835..43d690b35 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -1,17 +1 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count] do %> -
-
- <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render "comments/form", { commentable: @proposal, parent_id: nil } %> - <% else %> -
- <%= render "shared/login_to_comment" %> - <% end %> - - <%= render "comments/comment_list", comments: @comment_tree.root_comments %> - <%= paginate @comment_tree.root_comments %> -
-
-<% end %> +<%= render Shared::CommentsComponent.new(@proposal, @comment_tree) %> diff --git a/app/views/topics/_comments.html.erb b/app/views/topics/_comments.html.erb index 46c31c727..1a089ce26 100644 --- a/app/views/topics/_comments.html.erb +++ b/app/views/topics/_comments.html.erb @@ -1,18 +1 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@topic), @comment_tree.comments, @comment_tree.comment_authors, @topic.comments_count] do %> -
- -
- <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render "comments/form", { commentable: @topic, parent_id: nil } %> - <% else %> -
- <%= render "shared/login_to_comment" %> - <% end %> - - <%= render "comments/comment_list", comments: @comment_tree.root_comments %> - <%= paginate @comment_tree.root_comments %> -
-
-<% end %> +<%= render Shared::CommentsComponent.new(@topic, @comment_tree) %>