fix(gallery/filters): make feedback filters work globally when no guest_id is provided; remove guest_id from client photos query\n\n- Backend /api/gallery/:slug/photos: if filter present and guest_id missing, filter by like_count/favorite_count\n- Frontend useGalleryPhotos: stop passing random guestId (does not match server guest_identifier)\n\nThis makes Liked/Favorited filters reflect photos with aggregate feedback counts as expected.
This commit is contained in:
@@ -131,6 +131,17 @@ router.get('/:slug/photos', verifyGalleryAccess, async (req, res) => {
|
||||
|
||||
// Filter photos to only include those with feedback
|
||||
photos = photos.filter(photo => filteredPhotoIds.includes(photo.id));
|
||||
} else if (filter && !guest_id) {
|
||||
// Global filtering (by aggregate counts) when no guest identifier is provided
|
||||
// Normalize filter string
|
||||
const f = String(filter).toLowerCase();
|
||||
if (f === 'liked') {
|
||||
photos = photos.filter(p => (p.like_count || 0) > 0);
|
||||
} else if (f === 'favorited') {
|
||||
photos = photos.filter(p => (p.favorite_count || 0) > 0);
|
||||
} else if (f === 'liked,favorited' || f === 'favorited,liked') {
|
||||
photos = photos.filter(p => (p.like_count || 0) > 0 || (p.favorite_count || 0) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Then get comment counts separately
|
||||
|
||||
@@ -14,7 +14,8 @@ export const useGalleryInfo = (slug: string, token?: string) => {
|
||||
export const useGalleryPhotos = (slug: string, filter?: 'liked' | 'favorited' | 'all', guestId?: string, enabled: boolean = true) => {
|
||||
return useQuery({
|
||||
queryKey: ['gallery-photos', slug, filter, guestId],
|
||||
queryFn: () => galleryService.getGalleryPhotos(slug, filter, guestId),
|
||||
// Do not pass guestId for now; backend will apply global filters when guest_id is absent
|
||||
queryFn: () => galleryService.getGalleryPhotos(slug, filter, undefined),
|
||||
enabled,
|
||||
retry: 1,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
|
||||
Reference in New Issue
Block a user