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:
2025-09-16 09:28:12 +02:00
parent 3a6d06192a
commit 5b2561b6f1
2 changed files with 14 additions and 2 deletions
+11
View File
@@ -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
+2 -1
View File
@@ -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