mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-05 08:47:05 +02:00
Websocket Support (#159)
This commit is contained in:
17
src-web/hooks/useWebsocketConnections.ts
Normal file
17
src-web/hooks/useWebsocketConnections.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { WebsocketConnection } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const websocketConnectionsAtom = atom<WebsocketConnection[]>([]);
|
||||
|
||||
export function useWebsocketConnections() {
|
||||
return useAtomValue(websocketConnectionsAtom);
|
||||
}
|
||||
|
||||
export function useLatestWebsocketConnection(requestId: string | null): WebsocketConnection | null {
|
||||
return useWebsocketConnections().find((r) => r.requestId === requestId) ?? null;
|
||||
}
|
||||
|
||||
export function getWebsocketConnection(id: string) {
|
||||
return jotaiStore.get(websocketConnectionsAtom).find((r) => r.id === id) ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user