Files
nairobi/app/components/shared/moderation_actions_component.rb
Javi Martín cac24b0159 Extract component to show moderation actions
Note that in proposal notifications we're writing the call to
render the component in the same line as the <div class="reply">
definition in order to be able to use the `:empty` selector when the
component renders nothing. No browser matches whitespace with the
`:empty` selector, so we can't add newline characters inside the tag. A
more elegant solution would be extracting the proposal notification
actions to a component and only rendering it if the moderation actions
component is rendered.
2021-12-30 15:50:03 +01:00

35 lines
761 B
Ruby

class Shared::ModerationActionsComponent < ApplicationComponent
attr_reader :record
delegate :can?, to: :helpers
def initialize(record)
@record = record
end
def render?
can?(:hide, record) || can?(:hide, record.author)
end
private
def hide_path
polymorphic_path([:moderation, record], action: :hide)
end
def confirm_hide_text
t("admin.actions.confirm_action", action: t("admin.actions.hide"), name: record.human_name)
end
def confirm_hide_author_text
t("admin.actions.confirm_action", action: t("admin.actions.hide_author"), name: record.author.name)
end
def separator
if record.is_a?(Comment)
"&nbsp;&bull;&nbsp;"
else
"&nbsp;|&nbsp;"
end
end
end