Skip to main content

State Management

CommitT uses Zustand for all client-side state management. There are 10 specialized stores, each owning a specific domain of the application state.

Store Inventory

useTaskDraftStore

The largest store (800+ lines). Manages the entire commitment creation/editing wizard state — title, conditions, time windows, penalties, waivers, blocklists, and per-slot attachments.

useCalendarStore

Calendar grid state including selected date, view mode (day/week/month), event layout calculations, and drag-drop position tracking.

usePresetStore

Holds all hydrated presets (location, blocklist, rule) fetched from the Convex backend. Populated once at wizard layout mount via usePresetHydration().

useCommitStore

Tracks the active commitment list on the Dashboard. Manages selection state, menu visibility, and deletion modal flow.

useVerificationStore

Real-time verification session state. Holds current GPS coordinates, geofence status, camera capture state, and CAPTCHA progress.

useHealStore

Controls the HealOverlay — the recovery UI that appears during database reconstruction. Tracks progress percentage and status message.

usePresetEditStore

State for the preset editing screens (location, blocklist, rule). Separate from the main PresetStore to allow independent editing without affecting the wizard.

useAppStore

Minimal global app state. Tracks whether the app is in the foreground or background, used by the HydrationSync engine to trigger syncs on app resume.

useTaskStore

Read-only cache of tasks fetched from the local SQLite database. Populated by the useTasks hook on the Dashboard screen.

useChaosStore

Development-only store for the Chaos Engineering FAB. Allows injecting failures, simulating network drops, and corrupting the database for resilience testing.

TaskDraftStore Deep Dive

The useTaskDraftStore is the state machine behind the entire commitment wizard. It manages the full TaskDraft type — a frontend representation of a commitment being created or edited:

Slot-Level Condition Management

The most complex part of the store is the per-slot condition system. Each time window can have its own independent location, blocklist, and rule:

Intelligent Recurrence Logic

The setRecurrence action contains business logic that automatically adjusts the recurrence type and instance count based on the user’s day selection:

Logger Middleware

Every state mutation is logged with a pretty-printed JSON dump of the full draft. This provides complete visibility during development: