mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-21 17:09:09 +01:00
Websocket Support (#159)
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import { createGlobalState } from 'react-use';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { generateId } from '../lib/generateId';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
const useGlobalState = createGlobalState<Record<string, string>>({});
|
||||
const keyAtom = atom<Record<string, string>>({});
|
||||
|
||||
export function useRequestUpdateKey(requestId: string | null) {
|
||||
const [keys, setKeys] = useGlobalState();
|
||||
const keys = useAtomValue(keyAtom);
|
||||
const key = keys[requestId ?? 'n/a'];
|
||||
return {
|
||||
updateKey: `${requestId}::${key ?? 'default'}`,
|
||||
wasUpdatedExternally: (changedRequestId: string) => {
|
||||
setKeys((m) => ({ ...m, [changedRequestId]: generateId() }));
|
||||
jotaiStore.set(keyAtom, (m) => ({ ...m, [changedRequestId]: generateId() }));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user