Files
DeepTutor/web/hooks/useUiLayout.ts
Bingxi Zhao (Frank) 6ab4f9a766 feat(web): add classic/modern layout switch with Notion-style modern chrome
- Settings → General gains a classic/modern layout choice; classic is a frozen
  snapshot of dev's sidebar and learning dashboard, modern keeps iterating.
  Variants differ only through slots, tokens and per-variant CSS on
  <html data-ui-layout>; the preference lives in localStorage.
- Modern chrome: warm neutral tokens, WorkspaceMenu header, ⌘K command palette
  and keyboard shortcuts, PageBar location strip, swipeable PartnerRoster.
- Remove dead HomeShortcuts, WorkspaceSwitcher and the inline sidebar search
  query chain.
2026-10-15 23:00:23 +08:00

32 lines
974 B
TypeScript

"use client";
import { useSyncExternalStore } from "react";
import {
DEFAULT_UI_LAYOUT,
UI_LAYOUT_EVENT,
UI_LAYOUT_STORAGE_KEY,
applyUiLayoutToDocument,
readStoredUiLayout,
type UiLayout,
} from "@/lib/ui-layout";
function subscribe(onChange: () => void): () => void {
const onStorage = (event: StorageEvent) => {
if (event.key !== UI_LAYOUT_STORAGE_KEY) return;
// Another tab switched; keep this tab's <html> tokens in step.
applyUiLayoutToDocument(readStoredUiLayout());
onChange();
};
window.addEventListener(UI_LAYOUT_EVENT, onChange);
window.addEventListener("storage", onStorage);
return () => {
window.removeEventListener(UI_LAYOUT_EVENT, onChange);
window.removeEventListener("storage", onStorage);
};
}
/** The active UI layout. SSR and hydration render the default, then adopt. */
export function useUiLayout(): UiLayout {
return useSyncExternalStore(subscribe, readStoredUiLayout, () => DEFAULT_UI_LAYOUT);
}