This repository has no description
1.1 kB
35 lines
1import { useMutation, useQueryClient } from '@tanstack/react-query';
2import { updateConnection } from '../dal';
3import { connectionKeys } from '../connectionKeys';
4import { UpdateConnectionRequest } from '@semble/types';
5
6export default function useUpdateConnection() {
7 const queryClient = useQueryClient();
8
9 const mutation = useMutation({
10 mutationFn: (request: UpdateConnectionRequest) => {
11 return updateConnection(request);
12 },
13
14 onSuccess: () => {
15 // Invalidate all connection queries to ensure updates appear everywhere
16 queryClient.invalidateQueries({ queryKey: connectionKeys.all() });
17 // Invalidate all URL metadata queries with stats to update tab counts
18 queryClient.invalidateQueries({
19 predicate: (query): boolean => {
20 const key = query.queryKey as unknown[];
21 return !!(
22 key[0] === 'cards' &&
23 key[1] === 'metadata' &&
24 key[3] &&
25 typeof key[3] === 'object' &&
26 'includeStats' in key[3] &&
27 key[3].includeStats === true
28 );
29 },
30 });
31 },
32 });
33
34 return mutation;
35}