import { useSyncExternalStore } from "react"; /** * Whether dashboard cards that show a problem float to the top of their row (on by default). A preference of this browser only: the * arrangement the person made with the arrows is untouched underneath and is what they edit. */ const KEY = "dashboard.problemsFirst"; const listeners = new Set<() => void>(); function read(): boolean { try { return localStorage.getItem(KEY) !== "0"; } catch { return true; } } let value = read(); export function setProblemsFirst(on: boolean): void { value = on; try { localStorage.setItem(KEY, on ? "1" : "0"); } catch { // a remembered choice is only a convenience } for (const l of listeners) l(); } export function useProblemsFirst(): boolean { return useSyncExternalStore( (l) => { listeners.add(l); return () => listeners.delete(l); }, () => value, ); }