Pre-zip downloads: - Generate ZIP in background after photo mutations (upload/delete/watermark change) - Serve cached zip with Content-Length for instant downloads and native progress bar - Falls back to on-the-fly streaming when no cache exists yet - Frontend uses browser-native download when zip is ready (no blob buffering) - New downloadZipService with debounced regeneration and in-memory locking Photo replacement: - Admin upload form gets "Replace existing photos with same name" checkbox - Matches by original_filename (case-insensitive) within the same event - Preserves photo ID, position, feedback, category, and visibility - Updates file, thumbnail, dimensions, EXIF capture date on replacement - Ambiguous matches (multiple photos with same name) skip replacement with warning - New photoReplacementService with findReplacementCandidate and replacePhoto
80 lines
2.1 KiB
TypeScript
80 lines
2.1 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, enabled: boolean = true) => {
|
|
return useQuery({
|
|
queryKey: ['gallery-info', slug, token],
|
|
queryFn: () => {
|
|
if (!slug) {
|
|
throw new Error('Gallery slug is required');
|
|
}
|
|
return galleryService.getGalleryInfo(slug, token);
|
|
},
|
|
retry: 1,
|
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
enabled: Boolean(slug) && enabled,
|
|
});
|
|
};
|
|
|
|
export const useGalleryPhotos = (
|
|
slug: string,
|
|
filter?: 'liked' | 'favorited' | 'commented' | 'rated' | 'all',
|
|
guestId?: string,
|
|
enabled: boolean = true
|
|
) => {
|
|
return useQuery({
|
|
queryKey: ['gallery-photos', slug, filter, guestId],
|
|
// Pass guestId so backend can filter per-guest views when needed
|
|
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, zipReady }: { slug: string; zipReady?: boolean }) =>
|
|
galleryService.downloadAllPhotos(slug, zipReady),
|
|
onSuccess: () => {
|
|
toast.success('Download started');
|
|
},
|
|
onError: () => {
|
|
toast.error('Failed to download photos');
|
|
},
|
|
});
|
|
};
|