first commit

This commit is contained in:
2026-05-29 10:23:25 +03:00
commit e4b25fe4b7
48 changed files with 9112 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { getCats, getUserCats, getCat, uploadCat, deleteCat } from '@/api/endpoints';
export function useCats(page: number) {
return useQuery({
queryKey: ['cats', page],
queryFn: () => getCats(page).then((r) => r.data),
});
}
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'] });
},
});
}