mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
24 lines
701 B
TypeScript
24 lines
701 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import type { GrpcEvent } from '@yaakapp/api';
|
|
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 ?? []
|
|
);
|
|
}
|