workbench-store

PURPOSE

Zustand store for transient UI state of the Weapon Workbench screen: which component is currently selected and the library search query string.

OWNS

  • selectedComponentId: string | null — id of the component currently focused in the workbench (null = nothing selected).
  • librarySearch: string — current search filter applied to the component library panel.
  • selectComponent(id) — setter for selectedComponentId.
  • setLibrarySearch(q) — setter for librarySearch.

READS FROM

  • Nothing. Store is self-contained; initial values are hardcoded (null, '').

PUSHES TO

  • Any React component in the weapon-workbench screen tree that subscribes via useWorkbenchStore.

DOES NOT

  • Persist to localStorage or any backend.
  • Validate that id corresponds to a real component.
  • Cross-reference component data, inventory, or game state.
  • Reset on screen unmount (state survives navigation within the React tree’s lifetime).

Signals

  • selectedComponentId change → consumer panels re-render to show component detail.
  • librarySearch change → library list filters on each keystroke (debouncing, if any, lives in the consumer).

Entry points

  • useWorkbenchStore — sole export; hook used by every consumer in screens/weapon-workbench/.

Pattern notes

  • Plain create<State>() factory with no middleware (no persist, no devtools, no subscribeWithSelector).
  • State + setter colocated in one slice — typical for screen-local UI state.
  • ~15 lines total; intentionally minimal. Any persistence, derived state, or cross-screen sharing belongs elsewhere.

EXTRACT-CANDIDATE

  • Screen-local zustand stores with selectedX: string | null + setter is a recurring shape across workbench-style screens. If a third instance appears, consider a createSelectionStore<T>() factory in a shared state helper.