From 054fbf585e62642f237138f6a89df8e591ba213a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 2 Jul 2025 15:11:46 +0200 Subject: [PATCH] Simplify recommended index component parameters We can get the path if we know the namespace, so we don't need to pass both of them. --- .../shared/recommended_index_component.rb | 15 ++++++++++++--- app/views/debates/index.html.erb | 4 +--- app/views/proposals/index.html.erb | 4 +--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/components/shared/recommended_index_component.rb b/app/components/shared/recommended_index_component.rb index 439f69989..f22a87de3 100644 --- a/app/components/shared/recommended_index_component.rb +++ b/app/components/shared/recommended_index_component.rb @@ -1,14 +1,23 @@ class Shared::RecommendedIndexComponent < ApplicationComponent - attr_reader :recommendations, :disable_recommendations_path, :namespace + attr_reader :recommendations, :namespace use_helpers :current_path_with_query_params - def initialize(recommendations, disable_recommendations_path:, namespace:) + def initialize(recommendations, namespace:) @recommendations = recommendations - @disable_recommendations_path = disable_recommendations_path @namespace = namespace end def render? feature?("user.recommendations") && recommendations.present? end + + private + + def disable_recommendations_path + if namespace == "debates" + recommendations_disable_debates_path + else + recommendations_disable_proposals_path + end + end end diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index fe16bde5e..ed1b688c4 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -18,9 +18,7 @@ <%= render "shared/section_header", i18n_namespace: "debates.index.section_header", image: "debates" %> <% end %> -<%= render Shared::RecommendedIndexComponent.new(@recommended_debates, - disable_recommendations_path: recommendations_disable_debates_path, - namespace: "debates") %> +<%= render Shared::RecommendedIndexComponent.new(@recommended_debates, namespace: "debates") %>
diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index 2c5606329..3cdd444e3 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -25,9 +25,7 @@ <% end %> <% if show_recommended_proposals? %> - <%= render Shared::RecommendedIndexComponent.new(@recommended_proposals, - disable_recommendations_path: recommendations_disable_proposals_path, - namespace: "proposals") %> + <%= render Shared::RecommendedIndexComponent.new(@recommended_proposals, namespace: "proposals") %> <% end %>