mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 07:24:07 +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),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
19
src-web/hooks/useDeleteGrpcConnections.ts
Normal file
19
src-web/hooks/useDeleteGrpcConnections.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { grpcConnectionsQueryKey } from './useGrpcConnections';
|
||||
|
||||
export function useDeleteGrpcConnections(requestId?: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
if (requestId === undefined) return;
|
||||
await invoke('cmd_delete_all_grpc_connections', { requestId });
|
||||
},
|
||||
onSettled: () => trackEvent('GrpcConnection', 'DeleteMany'),
|
||||
onSuccess: async () => {
|
||||
if (requestId === undefined) return;
|
||||
queryClient.setQueryData(grpcConnectionsQueryKey({ requestId }), []);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import { trackEvent } from '../lib/analytics';
|
||||
import type { HttpResponse } from '../lib/models';
|
||||
import { httpResponsesQueryKey } from './useHttpResponses';
|
||||
|
||||
export function useDeleteResponse(id: string | null) {
|
||||
export function useDeleteHttpResponse(id: string | null) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<HttpResponse>({
|
||||
mutationFn: async () => {
|
||||
return await invoke('cmd_delete_response', { id: id });
|
||||
return await invoke('cmd_delete_http_response', { id: id });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpResponse', 'Delete'),
|
||||
onSuccess: ({ requestId, id: responseId }) => {
|
||||
@@ -3,12 +3,12 @@ import { invoke } from '@tauri-apps/api';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { httpResponsesQueryKey } from './useHttpResponses';
|
||||
|
||||
export function useDeleteResponses(requestId?: string) {
|
||||
export function useDeleteHttpResponses(requestId?: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
if (requestId === undefined) return;
|
||||
await invoke('cmd_delete_all_responses', { requestId });
|
||||
await invoke('cmd_delete_all_http_responses', { requestId });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpResponse', 'DeleteMany'),
|
||||
onSuccess: async () => {
|
||||
@@ -1,8 +1,8 @@
|
||||
import { isResponseLoading } from '../lib/models';
|
||||
import { useLatestResponse } from './useLatestResponse';
|
||||
import { useLatestHttpResponse } from './useLatestHttpResponse';
|
||||
|
||||
export function useIsResponseLoading(requestId: string | null): boolean {
|
||||
const response = useLatestResponse(requestId);
|
||||
const response = useLatestHttpResponse(requestId);
|
||||
if (response === null) return false;
|
||||
return isResponseLoading(response);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { HttpResponse } from '../lib/models';
|
||||
import { useHttpResponses } from './useHttpResponses';
|
||||
|
||||
export function useLatestResponse(requestId: string | null): HttpResponse | null {
|
||||
export function useLatestHttpResponse(requestId: string | null): HttpResponse | null {
|
||||
const responses = useHttpResponses(requestId);
|
||||
return responses[0] ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user