mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 19:52:18 -05:00
24 lines
577 B
Ruby
24 lines
577 B
Ruby
# frozen_string_literal: true
|
|
|
|
class FollowButtonComponent < ViewComponent::Base
|
|
def initialize(follower:, target:, name: nil)
|
|
@target = target
|
|
@following = follower.following? target
|
|
@name = name
|
|
end
|
|
|
|
def before_render
|
|
@path = url_for(@target) + "/follows"
|
|
@method = @following ? :delete : :post
|
|
@i18n_key = @following ? ".unfollow" : ".follow"
|
|
end
|
|
|
|
def render?
|
|
SiteSettings.multiuser_enabled?
|
|
end
|
|
|
|
erb_template <<-ERB
|
|
<%= button_to translate(@i18n_key, name: @name), @path, method: @method, class: "btn btn-primary" %>
|
|
ERB
|
|
end
|