Class: VoteFu::ReactionBarComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/vote_fu/reaction_bar_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(voteable:, voter: nil, reactions: default_reactions, show_counts: true, show_users: false, max_users: 3, allow_multiple: true) ⇒ ReactionBarComponent

Reaction bar component for emoji reactions (like Slack, GitHub, etc.)

Uses scoped voting where each reaction type is a scope. Vote values indicate the reaction emoji index.

Parameters:

  • voteable (ActiveRecord::Base)

    The voteable record

  • voter (ActiveRecord::Base, nil) (defaults to: nil)

    The current voter

  • reactions (Array<Hash>) (defaults to: default_reactions)

    Array of reaction configs: { emoji:, label:, scope: }

  • show_counts (Boolean) (defaults to: true)

    Show reaction counts

  • show_users (Boolean) (defaults to: false)

    Show who reacted (requires extra query)

  • max_users (Integer) (defaults to: 3)

    Max user names to show per reaction

  • allow_multiple (Boolean) (defaults to: true)

    Allow user to add multiple reactions



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/vote_fu/reaction_bar_component.rb', line 17

def initialize(
  voteable:,
  voter: nil,
  reactions: default_reactions,
  show_counts: true,
  show_users: false,
  max_users: 3,
  allow_multiple: true
)
  @voteable = voteable
  @voter = voter
  @reactions = reactions
  @show_counts = show_counts
  @show_users = show_users
  @max_users = max_users
  @allow_multiple = allow_multiple
end

Instance Method Details

#callObject



35
36
37
38
39
40
41
42
# File 'app/components/vote_fu/reaction_bar_component.rb', line 35

def call
  tag.div(**wrapper_attributes) do
    safe_join([
      reactions_container,
      (add_reaction_button if @voter && @allow_multiple)
    ].compact)
  end
end