favorites: show favlist when hovering over favcount.

Changes:

* Make it so you can click or hover over a post's favorite count to see
  the list of public favorites.
* Remove the "Show »" button next to the favorite count.
* Make the favorites list visible to all users. Before favorites were
  only visible to Gold users.
* Make the /favorites page show the list of all public favorites,
  instead of redirecting to the current user's favorites.
* Add /posts/:id/favorites endpoint.
* Add /users/:id/favorites endpoint.

This is for several reasons:

* To make viewing favorites work the same way as viewing upvotes.
* To make posts load faster for Gold users. Before, we loaded all the
  favorites when viewing a post, even when the user didn't look at them.
  This made pageloads slower for posts that had hundreds or thousands of
  favorites. Now we only load the favlist if the user hovers over the favcount.
* To make the favorite list visible to all users. Before, it wasn't
  visible to non-Gold users, because of the performance issue listed above.
* To make it more obvious that favorites are public by default. Before,
  since regular users could only see the favcount, they may have
  mistakenly believed other users couldn't see their favorites.
This commit is contained in:
evazion
2021-11-19 20:54:02 -06:00
parent c4ad50bbba
commit 3ae62d08eb
23 changed files with 229 additions and 78 deletions

View File

@@ -10,25 +10,35 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
end
context "index action" do
should "redirect the user_id param to an ordfav: search" do
get favorites_path(user_id: @user.id)
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}", format: "html")
end
should "redirect members to an ordfav: search" do
get_auth favorites_path, @user
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}", format: "html")
end
should "redirect anonymous users to the posts index" do
get favorites_path
assert_redirected_to posts_path(format: "html")
end
should "render for json" do
get favorites_path, as: :json
assert_response :success
end
should "render for html" do
get favorites_path
assert_response :success
end
should "render for /favorites?variant=tooltip" do
get post_favorites_path(@post, variant: "tooltip")
assert_response :success
end
should "render for /users/:id/favorites" do
get user_favorites_path(@user)
assert_response :success
end
should "render for /posts/:id/favorites" do
get post_favorites_path(@faved_post)
assert_response :success
end
should "render for /favorites?search[user_name]=<name>" do
get favorites_path(search: { user_name: @user.name })
assert_response :success
end
end
context "create action" do

View File

@@ -43,8 +43,8 @@ module Moderator
@parent.reload
@child.reload
as(@admin) do
assert_equal(users.map(&:id).sort, @parent.favorited_users.map(&:id).sort)
assert_equal([], @child.favorited_users.map(&:id))
assert_equal(users.map(&:id).sort, @parent.favorites.map(&:user_id).sort)
assert_equal([], @child.favorites.map(&:user_id))
end
end
end