mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 16:46:38 +01:00
22 lines
742 B
TypeScript
22 lines
742 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import type { WebsocketEvent } from '@yaakapp-internal/models';
|
|
import { listWebsocketEvents } from '@yaakapp-internal/ws';
|
|
|
|
export function websocketEventsQueryKey({ connectionId }: { connectionId: string }) {
|
|
return ['websocket_events', { connectionId }];
|
|
}
|
|
|
|
export function useWebsocketEvents(connectionId: string | null) {
|
|
return (
|
|
useQuery<WebsocketEvent[]>({
|
|
enabled: connectionId !== null,
|
|
initialData: [],
|
|
queryKey: websocketEventsQueryKey({ connectionId: connectionId ?? 'n/a' }),
|
|
queryFn: () => {
|
|
if (connectionId == null) return [] as WebsocketEvent[];
|
|
return listWebsocketEvents({ connectionId });
|
|
},
|
|
}).data ?? []
|
|
);
|
|
}
|