* Revert "(Temporarily) Remove multiple reactions from #index (#19142)" This reverts commita45d300639. * Clean up reaction category count mechanism for #index * Remove, unnecessary * Expose reaction categories in JSON response * Update test with new categories * Fix flaky sample / minimum floor * buildArticle (infinite scroll) with multiple reactions * If we're doing #index front-end, we aren't feature-flag'd * nbsp * react (home feed) has multiple_reactions * Update app/assets/javascripts/utilities/buildArticleHTML.js Co-authored-by: Rajat Talesra <rajat@forem.com> * Clean up Reactable#reaction_categories * Use 'multiple_reactions_icons_container' * Try adding a ReactionCount test * Adapt memory fix from76dd53d* Try adding categories to fixture * Attempt to eager-load distinct public categories * Setting dependent to the default for rubocop * Try making image assets more public? * Revert "Fix flaky sample / minimum floor" --------- Co-authored-by: Rajat Talesra <rajat@forem.com> Co-authored-by: Mac Siri <mac@forem.com>
26 lines
854 B
Ruby
26 lines
854 B
Ruby
module Reactable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :reactions, as: :reactable, inverse_of: :reactable, dependent: :destroy
|
|
has_many :distinct_reaction_categories, -> { order(:category).merge(Reaction.distinct_categories) },
|
|
as: :reactable,
|
|
inverse_of: :reactable,
|
|
dependent: nil,
|
|
class_name: "Reaction"
|
|
end
|
|
|
|
def sync_reactions_count
|
|
update_column(:public_reactions_count, reactions.public_category.size)
|
|
end
|
|
|
|
def public_reaction_categories
|
|
@public_reaction_categories ||= begin
|
|
# .map is intentional below - .pluck would break eager-loaded association!
|
|
reacted = distinct_reaction_categories.map(&:category)
|
|
ReactionCategory.for_view.select do |reaction_type|
|
|
reacted.include?(reaction_type.slug.to_s)
|
|
end
|
|
end
|
|
end
|
|
end
|