mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-18 23:16:59 +01:00
24 lines
715 B
TypeScript
24 lines
715 B
TypeScript
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 ?? []
|
|
);
|
|
}
|