mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 19:31:12 +01:00
Websocket Support (#159)
This commit is contained in:
21
src-web/hooks/useWebsocketEvents.ts
Normal file
21
src-web/hooks/useWebsocketEvents.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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 ?? []
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user