Remove duplication rendering comments
We were using the same code 5 times, with the only slight variation being the extra heading in the debates section.
This commit is contained in:
19
app/components/shared/comments_component.html.erb
Normal file
19
app/components/shared/comments_component.html.erb
Normal file
@@ -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 %>
|
||||||
|
<div class="row comments">
|
||||||
|
<div id="comments" class="small-12 column">
|
||||||
|
<%= content %>
|
||||||
|
|
||||||
|
<%= render "shared/wide_order_selector", i18n_namespace: "comments" %>
|
||||||
|
|
||||||
|
<% if current_user %>
|
||||||
|
<%= render "comments/form", { commentable: record, parent_id: nil } %>
|
||||||
|
<% else %>
|
||||||
|
<br>
|
||||||
|
<%= render "shared/login_to_comment" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render "comments/comment_list", comments: comment_tree.root_comments %>
|
||||||
|
<%= paginate comment_tree.root_comments %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
9
app/components/shared/comments_component.rb
Normal file
9
app/components/shared/comments_component.rb
Normal file
@@ -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
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
module HasOrders
|
module HasOrders
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
attr_reader :valid_orders, :current_order
|
||||||
|
|
||||||
|
included do
|
||||||
|
helper_method :valid_orders, :current_order
|
||||||
|
end
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
def has_orders(valid_orders, *args)
|
def has_orders(valid_orders, *args)
|
||||||
|
|||||||
@@ -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 %>
|
<%= render Shared::CommentsComponent.new(@debate, @comment_tree) do %>
|
||||||
<div class="row comments">
|
|
||||||
<div id="comments" class="small-12 column">
|
|
||||||
<h3>
|
<h3>
|
||||||
<%= t("debates.show.comments_title") %>
|
<%= t("debates.show.comments_title") %>
|
||||||
<span class="js-comments-count">(<%= @debate.comments_count %>)</span>
|
<span class="js-comments-count">(<%= @debate.comments_count %>)</span>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<%= render "shared/wide_order_selector", i18n_namespace: "comments" %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
|
||||||
<%= render "comments/form", { commentable: @debate, parent_id: nil } %>
|
|
||||||
<% else %>
|
|
||||||
<br>
|
|
||||||
<%= render "shared/login_to_comment" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render "comments/comment_list", comments: @comment_tree.root_comments %>
|
|
||||||
<%= paginate @comment_tree.root_comments %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -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::CommentsComponent.new(@proposal, @comment_tree) %>
|
||||||
<div class="row comments">
|
|
||||||
<div id="comments" class="small-12 column">
|
|
||||||
<%= render "shared/wide_order_selector", i18n_namespace: "comments" %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
|
||||||
<%= render "comments/form", { commentable: @proposal, parent_id: nil } %>
|
|
||||||
<% else %>
|
|
||||||
<br>
|
|
||||||
<%= render "shared/login_to_comment" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render "comments/comment_list", comments: @comment_tree.root_comments %>
|
|
||||||
<%= paginate @comment_tree.root_comments %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -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::CommentsComponent.new(@poll, @comment_tree) %>
|
||||||
<div class="row comments">
|
|
||||||
<div id="comments" class="small-12 column">
|
|
||||||
<%= render "shared/wide_order_selector", i18n_namespace: "comments" %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
|
||||||
<%= render "comments/form", { commentable: @poll, parent_id: nil } %>
|
|
||||||
<% else %>
|
|
||||||
<br>
|
|
||||||
<%= render "shared/login_to_comment" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render "comments/comment_list", comments: @comment_tree.root_comments %>
|
|
||||||
<%= paginate @comment_tree.root_comments %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -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::CommentsComponent.new(@proposal, @comment_tree) %>
|
||||||
<div class="row comments">
|
|
||||||
<div id="comments" class="small-12 column">
|
|
||||||
<%= render "shared/wide_order_selector", i18n_namespace: "comments" %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
|
||||||
<%= render "comments/form", { commentable: @proposal, parent_id: nil } %>
|
|
||||||
<% else %>
|
|
||||||
<br>
|
|
||||||
<%= render "shared/login_to_comment" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render "comments/comment_list", comments: @comment_tree.root_comments %>
|
|
||||||
<%= paginate @comment_tree.root_comments %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -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::CommentsComponent.new(@topic, @comment_tree) %>
|
||||||
<div class="row comments">
|
|
||||||
|
|
||||||
<div id="comments" class="small-12 column">
|
|
||||||
<%= render "shared/wide_order_selector", i18n_namespace: "comments" %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
|
||||||
<%= render "comments/form", { commentable: @topic, parent_id: nil } %>
|
|
||||||
<% else %>
|
|
||||||
<br>
|
|
||||||
<%= render "shared/login_to_comment" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render "comments/comment_list", comments: @comment_tree.root_comments %>
|
|
||||||
<%= paginate @comment_tree.root_comments %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user