Fix #4755: No navigation bar (prev/next button) when favgroup in query.

Fix the favgroup navbar not being shown when doing a `favgroup:<id>`
search for a public favgroup belonging to another user.
This commit is contained in:
evazion
2021-03-07 22:19:11 -06:00
parent 28d101eaa7
commit 53fdf66922
2 changed files with 21 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
class PostNavbarComponent < ApplicationComponent
extend Memoist
attr_reader :post, :current_user, :search
def initialize(post:, current_user:, search: nil)
@@ -18,7 +20,9 @@ class PostNavbarComponent < ApplicationComponent
end
def favgroups
@favgroups ||= current_user.favorite_groups.for_post(post.id).sort_by do |favgroup|
favgroups = FavoriteGroup.visible(current_user).for_post(post.id)
favgroups = favgroups.where(creator: current_user).or(favgroups.where(id: favgroup_id))
favgroups.sort_by do |favgroup|
[favgroup.id == favgroup_id ? 0 : 1, favgroup.name]
end
end
@@ -38,4 +42,6 @@ class PostNavbarComponent < ApplicationComponent
def query
@query ||= PostQueryBuilder.new(search)
end
memoize :favgroups
end