feat: expand intelligent investigation workspace
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { useCallback, useContext, useSyncExternalStore } from "react";
|
||||
import type { Spec } from "@json-render/core";
|
||||
import type { AnswerViewStateScope } from "./answer-view-state-scope";
|
||||
import { AnswerViewPersistenceContext } from "./answer-view-persistence-context";
|
||||
|
||||
export function useAnswerViewPersistence() { return useContext(AnswerViewPersistenceContext); }
|
||||
export function useAnswerViewState(scope: AnswerViewStateScope, sessionId: string, messageId: string, blockId: string, spec: Spec, enabled = true) {
|
||||
const entry = scope.entry(sessionId, messageId, blockId, spec);
|
||||
const snapshot = useSyncExternalStore(
|
||||
useCallback((listener: () => void) => scope.subscribe(entry, listener, enabled), [scope, entry, enabled]),
|
||||
() => entry.snapshot,
|
||||
() => entry.snapshot,
|
||||
);
|
||||
return { ...snapshot, update: scope.update.bind(scope, entry), retry: () => scope.retry(entry),
|
||||
reload: () => scope.reload(entry), resave: () => scope.resave(entry) };
|
||||
}
|
||||
Reference in New Issue
Block a user