Move recommended index partial to a component

Thanks to it, we can slightly simplify the debates view rendering it.
This commit is contained in:
Javi Martín
2024-10-23 01:15:53 +02:00
parent d34c9905a4
commit a548c497fc
7 changed files with 81 additions and 70 deletions

View File

@@ -0,0 +1,34 @@
<div class="recommended-index">
<div class="row relative" data-equalizer data-equalizer-on="medium">
<div class="small-12 column">
<h2 class="show-for-sr"><%= t("shared.recommended_index.title") %></h2>
</div>
<div id="recommendations" data-toggler=".hide">
<%= button_to disable_recommendations_path, title: t("shared.recommended_index.hide"),
class: "hide-recommendations",
data: {
toggle: "recommendations",
confirm: t("#{namespace}.index.recommendations.disable")
},
method: :put do %>
<span class="icon-x"></span>
<span class="show-for-sr"><%= t("shared.recommended_index.hide") %></span>
<% end %>
<% recommended.each_with_index do |recommended, index| %>
<div class="small-12 medium-6 large-4 column end">
<div class="recommendation" data-equalizer-watch>
<h3><%= link_to recommended.title, recommended_path(recommended) %></h3>
</div>
</div>
<% end %>
<div class="small-12 column">
<%= link_to t("shared.recommended_index.see_more"),
current_path_with_query_params(order: "recommendations"),
class: "float-right-medium small" %>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,14 @@
class Shared::RecommendedIndexComponent < ApplicationComponent
attr_reader :recommended, :disable_recommendations_path, :namespace
use_helpers :recommended_path, :current_path_with_query_params
def initialize(recommended, disable_recommendations_path:, namespace:)
@recommended = recommended
@disable_recommendations_path = disable_recommendations_path
@namespace = namespace
end
def render?
feature?("user.recommendations") && recommended.present?
end
end