File size: 1,568 Bytes
e3714c1 7e7bccd e3714c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // Per-SESSION opt-in for the interpretation layer on a dataset whose
// profile does not opt in (Jingyi's PR B: the layer is behind a per-dataset
// opt-in; Zheng's template ruling keeps the annotator usable on day one).
// A module-level store, like the display toggle in tactile-panel.tsx: it
// survives tab switches and episode navigation within the page and resets
// on reload, so base mode is always the state a fresh visit starts in. The
// auto-label panel reads it for the detector, the tactile panels for the
// corrected display's residual gate, so both follow the same switch.
import { useSyncExternalStore } from "react";
import type { RigProfile } from "./rigProfile";
let sessionOptIn = false;
const subs = new Set<() => void>();
export function setSessionInterpretation(v: boolean): void {
if (sessionOptIn === v) return;
sessionOptIn = v;
subs.forEach((cb) => cb());
}
/** Non-hook read for code outside React (the save path). */
export function getSessionInterpretation(): boolean {
return sessionOptIn;
}
export function useSessionInterpretation(): boolean {
return useSyncExternalStore(
(cb) => {
subs.add(cb);
return () => subs.delete(cb);
},
() => sessionOptIn,
() => false,
);
}
/** The profile a run should use: the dataset's own, or a copy opted in
* for this session. */
export function activeProfileFor(
profile: RigProfile | null,
session: boolean,
): RigProfile | null {
return profile && session && !profile.interpretation
? { ...profile, interpretation: true }
: profile;
}
|