diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 82c99ac86..6456a11d1 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -26,6 +26,7 @@ class FavoritesController < ApplicationController def create @post = Post.find(params[:post_id]) @post.add_favorite!(CurrentUser.user) + flash[:notice] = "You have favorited this post" respond_with(@post) end @@ -39,6 +40,7 @@ class FavoritesController < ApplicationController Favorite.remove(post_id: params[:id], user: CurrentUser.user) end + flash[:notice] = "You have unfavorited this post" respond_with(@post) end end diff --git a/app/views/favorites/_update.js.erb b/app/views/favorites/_update.js.erb new file mode 100644 index 000000000..5d608b019 --- /dev/null +++ b/app/views/favorites/_update.js.erb @@ -0,0 +1,16 @@ +$("#add-to-favorites, #add-fav-button, #remove-from-favorites, #remove-fav-button").toggle(); +$("#score-for-post-<%= @post.id %>").text(<%= @post.score %>); +$("#favcount-for-post-<%= @post.id %>").text(<%= @post.fav_count %>); + +<% if CurrentUser.is_gold? %> + var fav_count = <%= @post.fav_count %>; + $("#favlist").html("<%= j post_favlist(@post) %>"); + + if (fav_count === 0) { + $("#show-favlist-link, #hide-favlist-link, #favlist").hide(); + } else if (!$("#favlist").is(":visible")) { + $("#show-favlist-link").show(); + } +<% end %> + +Danbooru.Utility.notice("<%= j flash[:notice] %>"); diff --git a/app/views/favorites/create.js.erb b/app/views/favorites/create.js.erb deleted file mode 100644 index 2b66837a8..000000000 --- a/app/views/favorites/create.js.erb +++ /dev/null @@ -1,13 +0,0 @@ -$("#add-to-favorites").hide(); -$("#add-fav-button").hide(); -$("#remove-from-favorites").show(); -$("#remove-fav-button").show(); -$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>); -$("#favcount-for-post-<%= @post.id %>").html(<%= @post.fav_count %>); -<% if CurrentUser.is_gold? %> - $("#favlist").html("<%= escape_javascript(post_favlist(@post)) %>"); - if (!$("#favlist").is(":visible")) { - $("#show-favlist-link").show(); - } -<% end %> -$(window).trigger("danbooru:notice", "You have favorited this post"); diff --git a/app/views/favorites/create.js.erb b/app/views/favorites/create.js.erb new file mode 120000 index 000000000..348ee6954 --- /dev/null +++ b/app/views/favorites/create.js.erb @@ -0,0 +1 @@ +_update.js.erb \ No newline at end of file diff --git a/app/views/favorites/destroy.js.erb b/app/views/favorites/destroy.js.erb deleted file mode 100644 index bd69dfc52..000000000 --- a/app/views/favorites/destroy.js.erb +++ /dev/null @@ -1,13 +0,0 @@ -$("#add-to-favorites").show(); -$("#add-fav-button").show(); -$("#remove-from-favorites").hide(); -$("#remove-fav-button").hide(); -$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>); -$("#favcount-for-post-<%= @post.id %>").html(<%= @post.fav_count %>); -<% if CurrentUser.is_gold? %> - $("#favlist").html("<%= escape_javascript(post_favlist(@post)) %>"); - <% if @post.fav_count == 0 %> - $("#show-favlist-link, #hide-favlist-link, #favlist").hide(); - <% end %> -<% end %> -$(window).trigger("danbooru:notice", "You have unfavorited this post"); diff --git a/app/views/favorites/destroy.js.erb b/app/views/favorites/destroy.js.erb new file mode 120000 index 000000000..348ee6954 --- /dev/null +++ b/app/views/favorites/destroy.js.erb @@ -0,0 +1 @@ +_update.js.erb \ No newline at end of file