File size: 923 Bytes
dbd6aed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import { useEffect, useState } from 'react';
/* Simple mode: the test run page as one guided column (the current step only, the rest folded away), for people new
to the app. Each person switches it in the account menu; the choice stays in this browser. */
const KEY = 'pw.simple';
const EVT = 'pw-simple';
export const simpleModeOn = () => { try { return window.localStorage.getItem(KEY) === 'on'; } catch { return false; } };
export function setSimpleMode(on: boolean) {
try { window.localStorage.setItem(KEY, on ? 'on' : 'off'); } catch { /* storage blocked: the choice lasts this page */ }
window.dispatchEvent(new Event(EVT));
}
export function useSimpleMode() {
const [on, setOn] = useState(simpleModeOn);
useEffect(() => {
const f = () => setOn(simpleModeOn());
window.addEventListener(EVT, f);
return () => window.removeEventListener(EVT, f);
}, []);
return on;
}
|