Files
yaak-mountain-loop/src-web/hooks/useGrpcEvents.ts
Gregory Schier f967820f12 Model and DB refactor (#61)
- [x] Move from `sqlx` to `rusqlite`
- [x] Generate TS types from Rust models
2024-08-05 07:58:20 -07:00

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 ?? []
);
}