This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

semble / src / webapp / features / cards / lib / mutations / useRemoveCardFromLibrary.tsx
1.8 kB 45 lines
1import { useMutation, useQueryClient } from '@tanstack/react-query'; 2import { removeCardFromLibrary } from '../dal'; 3import { cardKeys } from '../cardKeys'; 4import { collectionKeys } from '@/features/collections/lib/collectionKeys'; 5import { noteKeys } from '@/features/notes/lib/noteKeys'; 6import { feedKeys } from '@/features/feeds/lib/feedKeys'; 7import { sembleKeys } from '@/features/semble/lib/sembleKeys'; 8import { connectionKeys } from '@/features/connections/lib/connectionKeys'; 9import { profileKeys } from '@/features/profile/lib/profileKeys'; 10 11export default function useRemoveCardFromLibrary() { 12 const queryClient = useQueryClient(); 13 14 const mutation = useMutation({ 15 mutationFn: (cardId: string) => { 16 return removeCardFromLibrary(cardId); 17 }, 18 19 onSuccess: () => { 20 queryClient.invalidateQueries({ queryKey: cardKeys.all() }); 21 queryClient.invalidateQueries({ queryKey: noteKeys.all() }); 22 queryClient.invalidateQueries({ queryKey: feedKeys.all() }); 23 queryClient.invalidateQueries({ queryKey: collectionKeys.all() }); 24 queryClient.invalidateQueries({ queryKey: sembleKeys.all() }); 25 queryClient.invalidateQueries({ queryKey: connectionKeys.all() }); 26 queryClient.invalidateQueries({ queryKey: profileKeys.all() }); 27 // Invalidate all URL metadata queries with stats to update tab counts 28 queryClient.invalidateQueries({ 29 predicate: (query): boolean => { 30 const key = query.queryKey as unknown[]; 31 return !!( 32 key[0] === 'cards' && 33 key[1] === 'metadata' && 34 key[3] && 35 typeof key[3] === 'object' && 36 'includeStats' in key[3] && 37 key[3].includeStats === true 38 ); 39 }, 40 }); 41 }, 42 }); 43 44 return mutation; 45}