Files
nairobi/app/components/shared/in_favor_against_component.rb
Javi Martín 86ad2df46d Unify code in debates/legislation vote links
We were using the same code to render links to agree and disagree, so we
can extract a new component for this code.

We're also adding component tests to make it easier to test whether
we're breaking anything while refactoring, although the code is probably
already covered by system tests.

Since the votes mixin was only used in one place, we're removing it and
moving most of its code to a new CSS file for the shared component.
2022-02-21 18:47:13 +01:00

26 lines
580 B
Ruby

class Shared::InFavorAgainstComponent < ApplicationComponent
attr_reader :votable
delegate :current_user, :votes_percentage, to: :helpers
def initialize(votable)
@votable = votable
end
private
def voted_classes
@voted_classes ||= css_classes_for_vote
end
def css_classes_for_vote
case current_user&.voted_as_when_voted_for(votable)
when true
{ in_favor: "voted", against: "no-voted" }
when false
{ in_favor: "no-voted", against: "voted" }
else
{ in_favor: "", against: "" }
end
end
end