* Remove extraneous comment (see 9361d2 and 5c18f8) * Flexible, multiple reaction types * Fix reaction counts * Re-use svg for active state for now * Update yml, update spec * Possible temp fix for failing tests * Colorize reaction icon svgs * Reaction engagement above post title * Index reactions engagements (for logged-out) * Maybe readinglist is special * Try using crayons' dropdown as a drawer? * readinglist isn't really public now * feat: update the styles for the reaction drawer * Grey background highlight, turn off border/shadow * Read our feature flag docs, saw this was recommended * Missed fifth emoji: party/tada * Fix JS test errors * Update test with tada * Suppress flashing engagements when no public reactions * Liberate jump-to-comments from unicorn replacement * 'Add reaction' on tooltip * Don't show reaction emoji on index unless it's been used * rubocop * Update heart+ total count when toggling * Do not include 'readinglist' in drawer/public counts * Fix semi-public readinglist so that icon is badged for current user * Tweak heart-plus svg * Style tweak: border on active reaction * Show reacted icon on drawer trigger for 1.5 sec * Tweak styles for engagements bar * Style tweaks for multiple engagements (#index) * Trying to get size working through crayons/inline_svg * Sparkle hearts * Restore unicorn * Make heart-plus-active work when user has an active reaction * Try 'hoverdown' a dropdown that activates with hover * Long touch? * Tap *outside* the drawer to close * Mobile reaction drawer is also supposed to be columns * More reaction count cleanup * Final emoticons maybe? * Fix reaction bug when feature disabled * Remove readinglist from public reaction counts * Update specs for new reaction categories * Shuffle makes specs flaky * Order does not matter * rubocop * Update to preserve readinglist analytics * Shuffle makes specs flaky * Fix flickering images, remove icon highlight for now * Don't update total for readinglist * reactions_by_user_id * Try renaming this observer function * Try unid ids for SVGs * Remove local test file * Simplistic test for the unique svg transform * Fix javascript for current SVG * Signifcant string literals in this case, rubocop * Use the right expected output Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
71 lines
1.9 KiB
Ruby
71 lines
1.9 KiB
Ruby
# See also reactions.yml and initializers/load_reaction_category_list.rb
|
|
class ReactionCategory
|
|
class << self
|
|
def [](slug)
|
|
hash[slug.to_sym]
|
|
end
|
|
|
|
def all_slugs
|
|
list.map(&:slug)
|
|
end
|
|
|
|
def negative_privileged
|
|
list.filter_map { |category| category.slug if category.privileged? && category.negative? }
|
|
end
|
|
|
|
def for_view
|
|
list.sort_by(&:position).filter_map { |category| category if category.visible_to_public? }
|
|
end
|
|
|
|
def public
|
|
list.sort_by(&:position).filter_map { |category| category.slug if category.visible_to_public? }
|
|
end
|
|
|
|
def privileged
|
|
list.filter_map { |category| category.slug if category.privileged? }
|
|
end
|
|
|
|
def list
|
|
@list ||= hash.values
|
|
end
|
|
|
|
def hash
|
|
@hash ||= REACTION_CATEGORY_LIST.each_pair.to_h do |slug, category_or_attributes|
|
|
as_category = if category_or_attributes.is_a?(ReactionCategory)
|
|
category_or_attributes
|
|
else
|
|
new(**category_or_attributes.merge(slug: slug))
|
|
end
|
|
[slug.to_sym, as_category]
|
|
end
|
|
end
|
|
end
|
|
|
|
attr_reader :color, :icon, :name, :position, :privileged, :published, :score, :slug
|
|
alias privileged? privileged
|
|
alias published? published
|
|
|
|
def initialize(attributes = {})
|
|
attributes.symbolize_keys!
|
|
@slug = attributes[:slug]&.to_sym
|
|
@name = attributes[:name] || slug.to_s.titleize
|
|
@icon = attributes[:icon]
|
|
@position = attributes[:position] || 99
|
|
@score = attributes[:score] || 1.0
|
|
@privileged = attributes[:privileged] || false
|
|
@published = attributes.fetch(:published, true)
|
|
@color = attributes[:color] || "000000"
|
|
end
|
|
|
|
def positive?
|
|
score > 0.0
|
|
end
|
|
|
|
def negative?
|
|
score < 0.0
|
|
end
|
|
|
|
def visible_to_public?
|
|
!privileged? && published?
|
|
end
|
|
end
|