Skip to content

[P1][arch] AppLayout.tsx is layout shell + menu dispatcher + dialog hub — 306 LOC, 13 useState pairs #450

Closed

Description

@EVWorth

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:

  1. Layout shell — sidebar collapse, panels (lines 248-274).
  2. Menu dispatcher — the 77-line handleAction switch (lines 90-167) is the only place that routes menu actions to store calls. 23 menu items, all defined in MenuBar.tsx. Any new feature wanting menu-bar reachability must edit AppLayout.
  3. 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). The ConfirmDialog (lines 294-306) is hardcoded to destructive-query production-warning copy and tied to useResultStore — 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  # 6

Expected

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 to listen("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 a confirmStore; 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

  1. added
    audit
    severity/p1
    kind/arch
    on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cross-cuttingauditkind/archseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions