- <% if user_voted_for %>
+ <% if user_voted_for? %>
<%= t("budgets.investments.investment.already_supported") %>
@@ -21,13 +17,13 @@
remote: !display_support_alert?,
data: (display_support_alert? ? {
confirm: t("budgets.investments.investment.confirm_group", count: investment.group.max_votable_headings) } : nil),
- "aria-hidden" => css_for_aria_hidden(reason) do %>
+ "aria-hidden" => css_for_aria_hidden do %>
<%= t("budgets.investments.investment.give_support") %>
<% end %>
<% end %>
- <% if reason.present? && !user_voted_for %>
+ <% if reason.present? && !user_voted_for? %>
<%= render "shared/social_share",
title: investment.title,
diff --git a/app/components/budgets/investments/votes_component.rb b/app/components/budgets/investments/votes_component.rb
index c8c9a12d3..442ecfa13 100644
--- a/app/components/budgets/investments/votes_component.rb
+++ b/app/components/budgets/investments/votes_component.rb
@@ -11,13 +11,25 @@ class Budgets::Investments::VotesComponent < ApplicationComponent
private
+ def reason
+ @reason ||= investment.reason_for_not_being_selectable_by(current_user)
+ end
+
+ def voting_allowed?
+ reason != :not_voting_allowed
+ end
+
+ def user_voted_for?
+ @user_voted_for ||= voted_for?(investment_votes, investment)
+ end
+
def display_support_alert?
current_user &&
!current_user.voted_in_group?(investment.group) &&
investment.group.headings.count > 1
end
- def css_for_aria_hidden(reason)
+ def css_for_aria_hidden
reason.present? ? "true" : ""
end
end