From f11fd2b13e7edbc1190f60b6749f10a17c68a3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 30 Sep 2021 22:44:16 +0200 Subject: [PATCH] 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. --- app/assets/javascripts/votes.js | 2 - .../comments/votes_component.html.erb | 87 ++++++------------- spec/support/common_actions/votes.rb | 2 - 3 files changed, 25 insertions(+), 66 deletions(-) diff --git a/app/assets/javascripts/votes.js b/app/assets/javascripts/votes.js index 2e8583156..c782d428b 100644 --- a/app/assets/javascripts/votes.js +++ b/app/assets/javascripts/votes.js @@ -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); }, diff --git a/app/components/comments/votes_component.html.erb b/app/components/comments/votes_component.html.erb index cb428eb80..a3714a63f 100644 --- a/app/components/comments/votes_component.html.erb +++ b/app/components/comments/votes_component.html.erb @@ -1,77 +1,40 @@
- <% if current_user %> - <%= t("comments.comment.votes", count: comment.total_votes) %> -  |  + <%= t("comments.comment.votes", count: comment.total_votes) %> +  |  - - <% if can?(:vote, comment) %> - <%= link_to vote_comment_path(comment, value: "yes"), - method: "post", remote: true, title: t("votes.agree") do %> - - <%= t("votes.agree") %> - - <% end %> - <% else %> - - <%= t("votes.agree") %> - - <% end %> - <%= comment.total_likes %> - - - - <% if can?(:vote, comment) %> - <%= link_to vote_comment_path(comment, value: "no"), - method: "post", remote: true, title: t("votes.disagree") do %> - - <%= t("votes.disagree") %> - - <% end %> - <% else %> - - <%= t("votes.disagree") %> - - <% end %> - <%= comment.total_dislikes %> - - <% else %> -
- <%= t("comments.comment.votes", count: comment.total_votes) %> -  |  - - - <% if can?(:vote, comment) %> - <%= link_to vote_comment_path(comment, value: "yes"), - method: "post", remote: true, title: t("votes.agree") do %> - - <%= t("votes.agree") %> - - <% end %> - <% else %> + + <% if can?(:vote, comment) %> + <%= link_to vote_comment_path(comment, value: "yes"), + method: "post", remote: true, title: t("votes.agree") do %> <%= t("votes.agree") %> - <% end %> - <%= comment.total_likes %> + <% end %> + <% else %> + + <%= t("votes.agree") %> + <% end %> + <%= comment.total_likes %> + - - <% if can?(:vote, comment) %> - <%= link_to vote_comment_path(comment, value: "no"), - method: "post", remote: true, title: t("votes.disagree") do %> - - <%= t("votes.disagree") %> - - <% end %> - <% else %> + + <% if can?(:vote, comment) %> + <%= link_to vote_comment_path(comment, value: "no"), + method: "post", remote: true, title: t("votes.disagree") do %> <%= t("votes.disagree") %> - <% end %> - <%= comment.total_dislikes %> + <% end %> + <% else %> + + <%= t("votes.disagree") %> -
+ <% end %> + <%= comment.total_dislikes %> + + <% unless current_user %>