Repository navigation
Description
Context
AppLayout is the top-level layout shell. It owns the menu dispatcher, 5 dialog states, and the centralised ConfirmDialog wiring.
Problem
src/components/layout/AppLayout.tsx (306 LOC) has 13 useState calls (lines 34-46), 6 useEffect calls, and reads 6 stores (lines 11-13, 38-49). Three concerns mashed together:
- Layout shell — sidebar collapse, panels (lines 248-274).
- Menu dispatcher — the 77-line
handleActionswitch (lines 90-167) is the only place that routes menu actions to store calls. 23 menu items, all defined inMenuBar.tsx. Any new feature wanting menu-bar reachability must edit AppLayout. - Dialog hub — 5 dialog states (
showShortcuts,helpTab,showImport,showBackup,showRestore) plus 2 pre-select states (backupPreselect,restorePreselect) — copy-pasted between backup and restore (lines 39-46, 100-104, 170-185). TheConfirmDialog(lines 294-306) is hardcoded to destructive-query production-warning copy and tied touseResultStore— no way to surface a different confirm (designer.save, sync.execute, backup.restore) without forking.
The cross-cutting audit (docs/audits/cross-cutting.md F5) flagged this as P1.
Files
- src/components/layout/AppLayout.tsx:1-306
- src/components/layout/MenuBar.tsx:1-146 (menu items)
- src/components/common/ConfirmDialog.tsx:1-65 (consumed at line 294)
Repro
wc -l src/components/layout/AppLayout.tsx # 306
grep -c "useState" src/components/layout/AppLayout.tsx # 13
grep -c "useEffect" src/components/layout/AppLayout.tsx # 6Expected
AppLayout is < 180 LOC with ≤ 3 useState calls. Menu actions route through a useMenuActions() hook that takes the action map as a parameter. Dialog states collapse to one registry. ConfirmDialog is generic and consumed by a useConfirm() hook.
Proposed fix
Scope M. Extract three things:
useMenuActions()hook taking{ [id]: () => void }map; AppLayout calls it once and binds the result tolisten("menu-action")+addEventListener("menu-action").useDialogRegistry()returning{ open(name, preselect?), close(name), state }; the 5 dialog states collapse to one record.useConfirm()hook backed by aconfirmStore; ConfirmDialog becomes generic.
AppLayout keeps only the layout shell + the wiring of these three hooks.
Acceptance
AppLayout.tsx is < 180 LOC, has ≤ 3 useState calls, and no longer references useEditorStore.getState() (menu actions move to the hook). The 5 dialog pre-select states collapse to one. A new feature can register a menu action and a dialog by adding one entry to the respective registries.
Needs human verify
No (refactor only).
Labels: audit, area/cross-cutting, severity/p1, kind/arch
Activity