From f8faabf7d1bedffbd32ba81cb4a0bf2eb483823f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 11 Oct 2024 17:43:16 +0200 Subject: [PATCH] Extract component to mark a debate as featured We're also moving the path argument in the `link_to` calls to a different line, since it's what we usually do. --- .../mark_featured_action_component.html.erb | 16 ++++++++++++++++ .../debates/mark_featured_action_component.rb | 12 ++++++++++++ app/views/debates/_actions.html.erb | 18 +----------------- 3 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 app/components/debates/mark_featured_action_component.html.erb create mode 100644 app/components/debates/mark_featured_action_component.rb diff --git a/app/components/debates/mark_featured_action_component.html.erb b/app/components/debates/mark_featured_action_component.html.erb new file mode 100644 index 000000000..3eb392fcf --- /dev/null +++ b/app/components/debates/mark_featured_action_component.html.erb @@ -0,0 +1,16 @@ + |  +<% if debate.featured? %> + <%= link_to t("admin.actions.unmark_featured").capitalize, + unmark_featured_debate_path(debate), + method: :put, + data: { confirm: t("admin.actions.confirm_action", + action: t("admin.actions.unmark_featured"), + name: debate.title) } %> +<% else %> + <%= link_to t("admin.actions.mark_featured").capitalize, + mark_featured_debate_path(debate), + method: :put, + data: { confirm: t("admin.actions.confirm_action", + action: t("admin.actions.mark_featured"), + name: debate.title) } %> +<% end %> diff --git a/app/components/debates/mark_featured_action_component.rb b/app/components/debates/mark_featured_action_component.rb new file mode 100644 index 000000000..38e5e59da --- /dev/null +++ b/app/components/debates/mark_featured_action_component.rb @@ -0,0 +1,12 @@ +class Debates::MarkFeaturedActionComponent < ApplicationComponent + attr_reader :debate + use_helpers :can? + + def initialize(debate) + @debate = debate + end + + def render + can? :mark_featured, debate + end +end diff --git a/app/views/debates/_actions.html.erb b/app/views/debates/_actions.html.erb index d3e64148b..99a4f7931 100644 --- a/app/views/debates/_actions.html.erb +++ b/app/views/debates/_actions.html.erb @@ -1,18 +1,2 @@ <%= render Shared::ModerationActionsComponent.new(debate) %> - -<% if can? :mark_featured, debate %> -  |  - <% if debate.featured? %> - <%= link_to t("admin.actions.unmark_featured").capitalize, unmark_featured_debate_path(debate), - method: :put, - data: { confirm: t("admin.actions.confirm_action", - action: t("admin.actions.unmark_featured"), - name: debate.title) } %> - <% else %> - <%= link_to t("admin.actions.mark_featured").capitalize, mark_featured_debate_path(debate), - method: :put, - data: { confirm: t("admin.actions.confirm_action", - action: t("admin.actions.mark_featured"), - name: debate.title) } %> - <% end %> -<% end %> +<%= render Debates::MarkFeaturedActionComponent.new(debate) %>