Sha256: d24017690dd66d5ea50257d900f03711518398d1f5415e3fffc7da04b0f9ff61

Contents?: true

Size: 1.3 KB

Versions: 13

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders the button to follow the given resource.
  class FollowButtonCell < Decidim::ButtonCell
    def show
      return if model == current_user

      render
    end

    def followers_count
      if model.respond_to?(:followers_count)
        model.followers_count
      else
        model.followers.size
      end
    end

    def id_option
      @id_option ||= options[:mobile] ? "follow-mobile" : "follow"
    end

    private

    def button_classes
      options[:button_classes] || "button button__sm button__text-secondary only:m-auto"
    end

    def text
      current_user_follows? ? t("decidim.follows.destroy.button") : t("decidim.follows.create.button")
    end

    def path
      decidim.follow_path(req_params)
    end

    def req_params
      { follow: { followable_gid: model.to_sgid.to_s, button_classes: } }
    end

    def method
      current_user_follows? ? :delete : :post
    end

    def icon_name
      current_user_follows? ? resource_type_icon_key("unfollow") : resource_type_icon_key("follow")
    end

    def remote
      true
    end

    def current_user_follows?
      return false unless current_user

      current_user.follows?(model)
    end

    def decidim
      Decidim::Core::Engine.routes.url_helpers
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.4 app/cells/decidim/follow_button_cell.rb
decidim-core-0.29.0 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.3 app/cells/decidim/follow_button_cell.rb
decidim-core-0.29.0.rc4 app/cells/decidim/follow_button_cell.rb
decidim-core-0.29.0.rc3 app/cells/decidim/follow_button_cell.rb
decidim-core-0.29.0.rc2 app/cells/decidim/follow_button_cell.rb
decidim-core-0.29.0.rc1 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.2 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.1 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.0 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.0.rc5 app/cells/decidim/follow_button_cell.rb
decidim-core-0.28.0.rc4 app/cells/decidim/follow_button_cell.rb