mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 16:43:53 +01:00
Refactor model emit, and recent conn dropdown
This commit is contained in:
21
src-web/hooks/useDeleteGrpcConnection.ts
Normal file
21
src-web/hooks/useDeleteGrpcConnection.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import type { GrpcConnection } from '../lib/models';
|
||||
import { grpcConnectionsQueryKey } from './useGrpcConnections';
|
||||
|
||||
export function useDeleteGrpcConnection(id: string | null) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<GrpcConnection>({
|
||||
mutationFn: async () => {
|
||||
return await invoke('cmd_delete_grpc_connection', { id: id });
|
||||
},
|
||||
onSettled: () => trackEvent('GrpcConnection', 'Delete'),
|
||||
onSuccess: ({ requestId, id: connectionId }) => {
|
||||
queryClient.setQueryData<GrpcConnection[]>(
|
||||
grpcConnectionsQueryKey({ requestId }),
|
||||
(connections) => (connections ?? []).filter((c) => c.id !== connectionId),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user