MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / useViewModeState

Function useViewModeState

packages/studio/src/contexts/ViewModeContext.tsx:50–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48 * Storyboard mode is always available; no flag gating.
49 */
50export function useViewModeState(): ViewModeValue {
51 const [viewMode, setMode] = useState<StudioViewMode>(() => readViewModeFromUrl());
52
53 // Reflect genuine browser back/forward between history entries with a different
54 // `?view=`. Note: our own writes use `replaceState` (below), which does NOT fire
55 // `popstate`, so this listener never sees them — `setViewMode` updates state directly.
56 // An agent deep-links by doing a full navigation to `?view=storyboard` (picked up by
57 // the mount-time read); a scripted `pushState`/`replaceState` to `?view=` would not be
58 // reflected here, by design.
59 useEffect(() => {
60 const onPopState = () => setMode(readViewModeFromUrl());
61 window.addEventListener("popstate", onPopState);
62 return () => window.removeEventListener("popstate", onPopState);
63 }, []);
64
65 const setViewMode = useCallback((mode: StudioViewMode) => {
66 setMode(mode);
67 writeViewModeToUrl(mode);
68 }, []);
69
70 return useMemo(() => ({ viewMode, setViewMode }), [viewMode, setViewMode]);
71}
72
73const ViewModeContext = createContext<ViewModeValue | null>(null);
74

Callers 1

StudioAppFunction · 0.90

Calls 2

readViewModeFromUrlFunction · 0.85
writeViewModeToUrlFunction · 0.85

Tested by

no test coverage detected