From eb564a4ef273552ab9dfad6b7a0bab7e04efccf9 Mon Sep 17 00:00:00 2001 From: lllusion3469 <31420484+lllusion3469@users.noreply.github.com> Date: Tue, 7 Apr 2020 02:08:56 +0200 Subject: [PATCH] Show or hide post vote buttons when (un)favoriting When favoriting/unfavoriting a post, it would also be upvoted/"un"voted but the upvote/downvote/undo vote buttons would stay shown/hidden as they were before unlike when pressing those buttons. For example when you want change from favorite to merely upvoted you would have to reload the page in between. --- app/views/favorites/_update.js.erb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/views/favorites/_update.js.erb b/app/views/favorites/_update.js.erb index ebea2bcb9..73b71ec61 100644 --- a/app/views/favorites/_update.js.erb +++ b/app/views/favorites/_update.js.erb @@ -4,6 +4,14 @@ $("#score-for-post-<%= @post.id %>").text(<%= @post.score %>); $("#favcount-for-post-<%= @post.id %>").text(<%= @post.fav_count %>); $(".fav-buttons").toggleClass("fav-buttons-false").toggleClass("fav-buttons-true"); +<% if @post.can_be_voted_by?(CurrentUser.user) %> + $("#vote-links-for-post-<%= @post.id %>").show(); + $("#unvote-link-for-post-<%= @post.id %>").hide(); +<% else %> + $("#vote-links-for-post-<%= @post.id %>").hide(); + $("#unvote-link-for-post-<%= @post.id %>").show(); +<% end %> + <% if policy(@post).can_view_favlist? %> var fav_count = <%= @post.fav_count %>; $("#favlist").html("<%= j post_favlist(@post) %>");