diff --git a/backend/src/routes/gallery.js b/backend/src/routes/gallery.js index 7ed8b36..92e7bba 100644 --- a/backend/src/routes/gallery.js +++ b/backend/src/routes/gallery.js @@ -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 diff --git a/frontend/src/hooks/useGallery.ts b/frontend/src/hooks/useGallery.ts index a80ba49..3bbc108 100644 --- a/frontend/src/hooks/useGallery.ts +++ b/frontend/src/hooks/useGallery.ts @@ -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 @@ -63,4 +64,4 @@ export const useDownloadAllPhotos = () => { toast.error('Failed to download photos'); }, }); -}; \ No newline at end of file +};