Class: Components::FollowButton

Inherits:
Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::ButtonTo
Defined in:
app/components/follow_button.rb

Instance Method Summary collapse

Constructor Details

#initialize(follower:, target:, name: nil) ⇒ FollowButton

Returns a new instance of FollowButton.



6
7
8
9
10
11
# File 'app/components/follow_button.rb', line 6

def initialize(follower:, target:, name: nil)
  @signed_out = follower.nil?
  @target = target
  @following = follower&.following? target
  @name = name
end

Instance Method Details

#render? ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'app/components/follow_button.rb', line 26

def render?
  SiteSettings.social_enabled? && (
    Pundit::PolicyFinder.new(Federails::Following).policy.new(current_user, nil).create? ||
    remote_follow_allowed?
  )
end

#view_template ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/follow_button.rb', line 13

def view_template
  DoButton(
    icon: @icon,
    href: @path,
    label: translate(@i18n_key, name: @name),
    method: @method,
    variant: (@following == :pending) ? "outline-primary " : "primary",
    data: {
      turbo: !@signed_out
    }
  )
end