mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 03:41:11 +01:00
Refactor into grpc events
This commit is contained in:
23
src-web/hooks/useGrpcEvents.ts
Normal file
23
src-web/hooks/useGrpcEvents.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { GrpcEvent } from '../lib/models';
|
||||
|
||||
export function grpcEventsQueryKey({ connectionId }: { connectionId: string }) {
|
||||
return ['grpc_events', { connectionId }];
|
||||
}
|
||||
|
||||
export function useGrpcEvents(connectionId: string | null) {
|
||||
return (
|
||||
useQuery<GrpcEvent[]>({
|
||||
enabled: connectionId !== null,
|
||||
initialData: [],
|
||||
queryKey: grpcEventsQueryKey({ connectionId: connectionId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
return (await invoke('cmd_list_grpc_events', {
|
||||
connectionId,
|
||||
limit: 200,
|
||||
})) as GrpcEvent[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { GrpcMessage } from '../lib/models';
|
||||
|
||||
export function grpcMessagesQueryKey({ connectionId }: { connectionId: string }) {
|
||||
return ['grpc_messages', { connectionId }];
|
||||
}
|
||||
|
||||
export function useGrpcMessages(connectionId: string | null) {
|
||||
return (
|
||||
useQuery<GrpcMessage[]>({
|
||||
enabled: connectionId !== null,
|
||||
initialData: [],
|
||||
queryKey: grpcMessagesQueryKey({ connectionId: connectionId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
return (await invoke('cmd_list_grpc_messages', {
|
||||
connectionId,
|
||||
limit: 200,
|
||||
})) as GrpcMessage[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user