docbrown/app/helpers/notifications_helper.rb
Joshua Wehner ea2154d506
Fixing design issues with multiple reactions (#19020)
* Try disabling text-select (mobile long-tap)

* Try to force button color on mobile safari

* Try making notification decorator more helpful

* More using notification decorator

* Helper so I can see exceptions

* As we toggle feature flag, temporary show 'heart' for unsupported reactions

* Reaction on Comment is a 'reaction'-type notification

* Temporarily add new emojis to i18n

* Render full-color, unique SVGs for multiple_reactions

* Restore card layout

* Aggregate reaction icons also need unique SVGs

* This seems unnecessary?

* Multiple is -more-than-one-

* Display *unique* reaction categories on /notifications

* Comment notification no longer needs to re-render as reaction

* Decorator needs to handle some data gaps

* Fix NotificationHelper

* Try a better name for this

* Tests for the notification decorator

* These partials wound up without an outer layer

* Add a descriptive comment

* index needs force_unique

* Try multiple reactions external img (#19076)

* Try external img SVGs

* Unique SVG might not be necessary if this works

* Can also remove this spec if successful

* Restore flash icon behavior

* Plus external img for #index as well
2023-02-08 11:39:47 +01:00

55 lines
1.8 KiB
Ruby

module NotificationsHelper
REACTION_IMAGES = {
"like" => "heart-filled.svg",
"unicorn" => "unicorn-filled.svg",
"hands" => "twemoji/hands.svg",
"thinking" => "twemoji/thinking.svg",
"readinglist" => "save-filled.svg",
"thumbsdown" => "twemoji/thumb-down.svg",
"vomit" => "twemoji/suspicious.svg"
}.freeze
def reaction_image(slug)
if FeatureFlag.enabled?(:multiple_reactions)
if (category = ReactionCategory[slug] || ReactionCategory["like"])
"#{category.icon}.svg"
end
else
# This is mostly original behavior, pre-multiple_reactions, modified to return
# a "like" image if the actual reaction is one of the new ones
REACTION_IMAGES[slug] || REACTION_IMAGES["like"]
end
end
def reaction_category_name(slug)
ReactionCategory[slug]&.name.presence || "unknown"
end
def render_each_notification_or_error(notifications, error:, &block)
notifications.each do |notification|
concat render_notification_or_error(notification, error: error, &block)
end
end
def render_notification_or_error(notification, error:)
capture { yield(notification) }
rescue StandardError => e
raise if Rails.env.development?
Honeybadger.notify(e, context: { notification_id: notification.id })
capture { render error }
end
def message_user_acted_maybe_org(data, action, if_org: "")
key_to_link = ->(key) { link_to(data[key]["name"], data[key]["path"], class: "crayons-link fw-bold") }
if if_org.present?
I18n.t(
action,
user: key_to_link.call("user"),
if_org: data["organization"] ? I18n.t(if_org, org: key_to_link.call("organization")) : "",
)
else
I18n.t(action, user: key_to_link.call("user"))
end.html_safe # rubocop:disable Rails/OutputSafety
end
end