Remove duplication in comments votes component

We're also simplifying the code a bit by removing the
`participation-allowed` HTML class, which wasn't used in any other votes
component.
This commit is contained in:
Javi Martín
2021-09-30 22:44:16 +02:00
parent 053ec31df6
commit f11fd2b13e
3 changed files with 25 additions and 66 deletions

View File

@@ -5,11 +5,9 @@
$(document).on({
"mouseenter focus": function() {
$("div.participation-not-allowed", this).show();
$("div.participation-allowed", this).hide();
},
mouseleave: function() {
$("div.participation-not-allowed", this).hide();
$("div.participation-allowed", this).show();
}
}, votes);
},

View File

@@ -1,5 +1,4 @@
<div class="votes">
<% if current_user %>
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;
@@ -34,44 +33,8 @@
<% end %>
<%= comment.total_dislikes %>
</span>
<% else %>
<div class="participation-allowed">
<%= t("comments.comment.votes", count: comment.total_votes) %>
&nbsp;|&nbsp;
<span class="in_favor">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "yes"),
method: "post", remote: true, title: t("votes.agree") do %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<% else %>
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<% end %>
<%= comment.total_likes %>
</span>
<span class="against">
<% if can?(:vote, comment) %>
<%= link_to vote_comment_path(comment, value: "no"),
method: "post", remote: true, title: t("votes.disagree") do %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<% else %>
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<% end %>
<%= comment.total_dislikes %>
</span>
</div>
<% unless current_user %>
<div tabindex="0">
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<%= sanitize(t("votes.comment_unauthenticated", signin: link_to_signin, signup: link_to_signup)) %>

View File

@@ -8,8 +8,6 @@ module Votes
within(".participation-not-allowed") do
expect(page).to have_content "You must sign in or sign up to vote"
end
expect(page).not_to have_selector(".participation-allowed")
end
def expect_message_to_many_anonymous_votes