Files
picpeak/frontend/src/hooks/useGallery.ts
T
paul 41857ec499 feat: implement feedback filter for liked/favorited photos (Issue #17)
Implemented Feature Request 1 from github.com/the-luap/picpeak/issues/17:
- Added filter functionality to display only liked or favorited photos
- Integrated feedback filter directly into PhotoFilterBar component
- Implemented responsive design with proper mobile/tablet/desktop layouts
- Filter only shows when feedback is enabled for the gallery
- Added proper count display for liked and favorited photos

Improvements:
- Fixed responsive breakpoints (mobile <768px, tablet 768-1023px, desktop ≥1024px)
- Feedback filter shows inline with categories on desktop with vertical divider
- On mobile/tablet, filter appears below categories to prevent layout issues
- Added horizontal scrolling for category buttons to prevent cut-off

Code cleanup:
- Removed all debug console.log statements from production code
- Removed test route from backend gallery.js
- Cleaned up unnecessary logging in frontend components

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-05 14:56:09 +02:00

66 lines
1.8 KiB
TypeScript

import { useQuery, useMutation } from '@tanstack/react-query';
import { galleryService } from '../services';
import { toast } from 'react-toastify';
export const useGalleryInfo = (slug: string, token?: string) => {
return useQuery({
queryKey: ['gallery-info', slug, token],
queryFn: () => galleryService.getGalleryInfo(slug, token),
retry: 1,
staleTime: 5 * 60 * 1000, // 5 minutes
});
};
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),
enabled,
retry: 1,
staleTime: 5 * 60 * 1000, // 5 minutes
// Add a small delay to ensure auth token is properly set
retryDelay: 100,
});
};
export const useGalleryStats = (slug: string, enabled: boolean = true) => {
return useQuery({
queryKey: ['gallery-stats', slug],
queryFn: () => galleryService.getGalleryStats(slug),
enabled,
retry: 1,
staleTime: 60 * 1000, // 1 minute
});
};
export const useDownloadPhoto = () => {
return useMutation({
mutationFn: ({
slug,
photoId,
filename,
}: {
slug: string;
photoId: number;
filename: string;
}) => galleryService.downloadPhoto(slug, photoId, filename),
onSuccess: () => {
toast.success('Photo downloaded successfully');
},
onError: () => {
toast.error('Failed to download photo');
},
});
};
export const useDownloadAllPhotos = () => {
return useMutation({
mutationFn: (slug: string) => galleryService.downloadAllPhotos(slug),
onSuccess: () => {
toast.success('Download started');
},
onError: () => {
toast.error('Failed to download photos');
},
});
};