A social knowledge tool for researchers built on ATProto
at development 35 lines 986 B view raw
1import { ApiClient } from '@/api-client/ApiClient'; 2import { createClientTokenManager } from '@/services/auth'; 3import { useMutation, useQueryClient } from '@tanstack/react-query'; 4 5export default function useUpdateCollection() { 6 const apiClient = new ApiClient( 7 process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3000', 8 createClientTokenManager(), 9 ); 10 11 const queryClient = useQueryClient(); 12 13 const mutation = useMutation({ 14 mutationFn: (collection: { 15 collectionId: string; 16 rkey: string; 17 name: string; 18 description?: string; 19 }) => { 20 return apiClient.updateCollection(collection); 21 }, 22 23 onSuccess: (data, variables) => { 24 queryClient.invalidateQueries({ queryKey: ['collections'] }); 25 queryClient.invalidateQueries({ 26 queryKey: ['collection', data.collectionId], 27 }); 28 queryClient.invalidateQueries({ 29 queryKey: ['collection', variables.rkey], 30 }); 31 }, 32 }); 33 34 return mutation; 35}