Files
yaak/src-web/hooks/useGrpcEvents.ts
2024-06-20 08:40:10 -07:00

24 lines
702 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import type { GrpcEvent } from '../lib/models';
import { invokeCmd } from '../lib/tauri';
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 invokeCmd('cmd_list_grpc_events', {
connectionId,
limit: 200,
})) as GrpcEvent[];
},
}).data ?? []
);
}