- Fix liked hearts not showing after page reload (sync useEffect in CatCard) - Replace pagination with infinite scroll (useInfiniteQuery + IntersectionObserver) - Add HEIC/HEIF/AVIF image support with sharp conversion to JPEG on upload - Validate MIME type alongside file extension to prevent spoofing - Limit caption to 500 chars; increase upload size limit to 20MB - Delete physical file from uploads/ when post is removed (cats + admin routes) - Add WAL journal mode and graceful shutdown (SIGTERM/SIGINT) to db - Add rate limiter for upload endpoint (10 req / 15 min) - Add pre-deploy backup of data.db and uploads/ to deploy.sh (keeps last 10) - Add plan_modernization.md with ideas for future improvements Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { useInfiniteQuery, useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { getCats, getUserCats, getCat, uploadCat, deleteCat } from '@/api/endpoints';
|
|
|
|
export function useCats() {
|
|
return useInfiniteQuery({
|
|
queryKey: ['cats'],
|
|
queryFn: ({ pageParam }) => getCats(pageParam as number).then((r) => r.data),
|
|
initialPageParam: 1,
|
|
getNextPageParam: (lastPage) =>
|
|
lastPage.page < lastPage.totalPages ? lastPage.page + 1 : undefined,
|
|
});
|
|
}
|
|
|
|
export function useUserCats(userId: number) {
|
|
return useQuery({
|
|
queryKey: ['cats', 'user', userId],
|
|
queryFn: () => getUserCats(userId).then((r) => r.data),
|
|
enabled: !!userId,
|
|
});
|
|
}
|
|
|
|
export function useCat(id: number) {
|
|
return useQuery({
|
|
queryKey: ['cat', id],
|
|
queryFn: () => getCat(id).then((r) => r.data),
|
|
enabled: !!id,
|
|
});
|
|
}
|
|
|
|
export function useUploadCat() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (formData: FormData) => uploadCat(formData).then((r) => r.data),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ['cats'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteCat() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (id: number) => deleteCat(id),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ['cats'] });
|
|
},
|
|
});
|
|
}
|