Guide - Front end state

State consolidation map for the site front end

Use this map before changing shared state in the site source. Each entry names the files that hold the state today, states whether the state moves to a single store, stays on the server as the record, or is eliminated, and gives the build order with a check for each step.

How to read this map

Read the location first, then the decision, then the reason. Server truth means the saved booking, rates, workspace, and role records in the app. Client state is a view of those records and is never a second record. A state that can be derived from inputs on each render is not stored.

Move to a single store

One shared module owns the state, and every page reads and writes through that module. Per page copies are removed.

Keep on the server

The server record stays the only truth. The client keeps no competing value and re-reads the record after a change.

Eliminate

Stored state that duplicates derived state is removed. The value is derived from current inputs at render time.

Shared and local state map

Each card is one state item traced in pack app-chauffeur.site.1.

Quote preview cache - move to a single store

Location today: public/index.html keeps a memory cache with no expiry beside a session cache with a five minute expiry. Public/passenger-book.html and public/app/passenger-book.html each keep a memory cache with no expiry and no session tier, keyed by service and hours only. Decision: one shared quote module for all three pages, with one expiry rule applied to every tier, and the quote endpoint as the source for rates. Eliminate the per page cache copies. Reason: a memory entry that never expires can show a prior rate after settings change, and the three pages can disagree on the same quote.

Quote summary - eliminate stored summary

Location today: public/index.html builds a summary from service, pickup, drop off, pickup date and time, passengers, and vehicle class, but re-renders it only when service or hours change. Decision: derive the summary from current inputs on every input event, using the cached quote payload, with no stored summary state and no extra network call. Reason: a stored summary goes stale when pickup, drop off, date, passengers, or vehicle class change after the quote loads.

Passenger book draft and outbox - move to a single store, then retire the duplicate

Location today: public/passenger-book.html and public/app/passenger-book.html each maintain draft keys, outbox keys, retry timers, busy flags, and a current booking object in inline scripts, with validation that has diverged between copies. Decision: one shared passenger book script for both addresses, one draft key and one outbox key per form, and the public booking link as the one destination, with the app copy validation aligned to the public copy before any link is added. Keep the server booking record as truth. Reason: two writers for one form can create two pending requests for one trip and can disagree on required fields.

Public form outbox - move to a single writer

Location today: public/site.js writes an outbox entry with an idempotency key and retry on each data-request form, while public/request-demo.html adds a second draft binder and a second submit check for the same form, clearing the same outbox key from a different store. Decision: public/site.js is the single writer for submit, retry, and outbox clearing. The page script keeps draft persistence only, or is removed where site.js already restores entries. Eliminate the second validation and submit path. Reason: two writers can save, clear, and restore entries in different orders and can show two different error messages for one submit.

Onboarding progress - move to a single store, drop derived caches

Location today: public/onboarding-checklist.html keeps a preferences key, per workspace and person and role progress keys, an in-memory fallback, and separate caches for role steps, applicable steps, and a step signature. Decision: one store object with derive functions for the visible list and progress, and no cache of derived lists. Keep device storage as a view only. Typed workspace and person names are not signed in identity and never replace the workspace record in the app. Reason: cached derived lists can disagree with checked state after a role or identity change, and a typed name can start a separate list with no warning.

Guide search - keep the address as the single store, eliminate mirrored state

Location today: public/guides/index.html mirrors search state in card scores, card visibility, group order, section visibility, last query, and last count, while also writing words and filter groups to the address. Decision: the address stays the single store. Derive visibility, ranking, and order in one render pass from the address and the filter controls, and remove stored score, visibility, and order mirrors. Reason: mirrored state needs effect driven resync on every input and can show a stale order or count after a filter change.

Navigation, error, and funnel singletons - keep in site.js, eliminate per page copies

Location today: public/site.js holds navigation open state, error banner dismissed state and last focus, analytics session and view state, a prefetch set, and service worker registration. Public/404.html and public/offline.html each repeat skip link handling, return path storage, online state, and retry handling in inline scripts. Decision: keep the site.js singletons as the one copy, cap the in-memory analytics list, and move return path, online, and retry handling for system pages into one shared system page script. Eliminate the per page inline copies. Reason: per page copies diverge on return path rules and on focus handling, and an uncapped list grows for the length of a visit.

App shell - move to one shell store

Location today: public/app/index.html maintains drawer open state, inert state, dialog focus, boot fallback visibility, and table labelling in separate handlers. Decision: one shell store for drawer, dialog, and focus, with a single render path, and the server permission check as truth for every screen. Keep table labelling as a derive step from headers on each render. Reason: separate focus and inert writers can leave background content reachable while a drawer or dialog is open.

MAJIC sign-in, active workspace, and user role: one session store

Trace result for pack app-chauffeur.site.1: no site file stores a MAJIC token, a session value, or a workspace secret. Sign-in truth, workspace scope, and role permissions live in the signed-in app and on the server per APPKIT.md, outside this site pack. Site files hold only the view copies below. Consolidate those view copies into one session store, keep the server as truth for every write, and never let client view state widen a list or grant a screen.

Consumer 1: signed-in app shell, public/app/index.html

State today: drawer open mirrored in body.nav-open and inertOn, dialog opener and seen dialog and last outside focus in separate variables, boot timer in window.__cdBootTimer, table seen set in seenTables with a seenList fallback, and repeated queries for .app-nav-toggle, aside or header nav, and main on each event. No workspace or role text is stored here, the workspace switcher is rendered by app code outside this pack. Update: one shell and session store with a single state object and subscribe, derive drawer, inert, and focus from that state, observe the workspace switcher DOM for a display name only, and keep boot and table work as derive steps. Consumers to update in this file are the nav toggle, skip link, document click and keydown handlers, resize, popstate and hashchange handlers, MutationObserver, boot fallback binder, and table labelling.

Consumer 2: signed-in app screens, app slice outside this pack

State today per APPKIT.md: each screen is render(root, ctx) with ctx.can(perm), the workspace is the MAJIC company from the server session, and roles sit on top of MAJIC roles from src/app.json. App code is not in this site pack, so this map names the update without editing it here. Update in a separate app change: inject one session context at the app root, have every screen read workspace and role from that context instead of re-deriving it per view, and keep the server check as truth for every write. No site file in this pack is changed for this consumer.

Consumer 3: onboarding checklist, public/onboarding-checklist.html

State today: ws-name, person-name, role-select, and join-mode in the DOM, preferences in chauffeurdesk:onboarding:prefs:v1, progress in chauffeurdesk:onboarding:v1:workspace:person:role keys, plus roleStepsCache, applicableCache, and lastStepsSignature mirrors. Typed names are device labels only and are not MAJIC identity, and the app checklist per workspace stays separate. Update: one store object for typed workspace, person, job, checked, dismissed, and completed, derive the visible step list and progress on each render, drop the three caches, keep a pending key until a typed identity is entered, and never use this store as signed-in workspace or role truth. Consumers to update are the progress text, live region and bar, step list builder, landing text, next step link, and dismiss, complete, and reset buttons.

Consumer 4: passenger booking, public/passenger-book.html and public/app/passenger-book.html

State today: currentBooking, tokenFromHash, quoteCache, draft and outbox keys under chauffeurdesk:passenger-book, and busy flags. No workspace and no role are stored, the public token is the only scope, under /api/publicbook/public/. Update: keep this module token-scoped, read the session store only for a sign-in link hint, never store a workspace or role from a token, and keep the server booking record as truth. Consumers to update are quote preview, status render, calendar download, and the update, reschedule, and cancel forms.

Consumer 5: marketing site script, public/site.js

State today: mobile nav open, error banner dismissed and last focus, analytics session_id and view_id in memory, outboxMemory, and a prefetch set. No sign-in, workspace, or role state. Update: keep marketing singletons separate from the session store, never merge the analytics session or view id with a MAJIC session, and keep the analytics list capped as stated above. Consumers to keep separate are mobile nav, skip links, data-request forms, and the analytics emitter.

Consumer 6: pending page, public/pending.html

State today: direct localStorage scan for outbox and draft keys, renderedSubs and renderedDrafts caches, lastStatus, and storageOkCache. No sign-in, workspace, or role state, metadata only and no field values shown. Update: read submissions and drafts through the draft and outbox store interface used by Consumer 4, drop the per page scan and rendered caches, and keep discard on this device only. Consumers to update are the submission list, draft list, refresh button, and discard buttons.

Store shape and rules

View state only: signedIn derived from the server session response in the app, workspace with id and name for display only, role for display only, plus shell state for nav, dialog, and boot. The store publishes and components subscribe, no component writes workspace or role directly, no token or secret is stored in a site file, onboarding typed names map to a pending device key only, and a shared link carries filter values only and never a workspace id or a booking token. The server remains truth for sign-in, workspace scope, and every permission check.

What stays on the server

These values are never moved to client state and never derived on a page.

Booking, rates, and call time

Saved quote amounts, pickup time, call time, status, assignment, readiness, and flags come from saved records for the signed in workspace. A client cache never rewrites them, and a changed rate applies to new quotes only.

Workspace, role, and tenancy

Workspace scope, role, and permission checks stay on the server for every screen and every write. Client state never widens a list beyond the signed in workspace or role, and a shared link carries filter values only, never record data.

Consolidation order and checks

Ship in this order. Each step keeps the same visible behaviour and the same server records.

  1. Quote cache and summary first

    Apply one expiry rule to every cache tier, and derive the home page summary on every input. Check: change pickup after a quote loads and read an updated summary with no network call, then confirm an expired entry re-reads the quote endpoint.

  2. Passenger book duplicate second

    Align validation between copies, then load one shared script. Check: submit an MCI arrival and a point to point ride on each copy and read the same field errors and the same single pending request.

  3. Request demo single writer third

    Remove the second submit path and keep one outbox writer. Check: submit, reload before success, and confirm one restored entry with one reference and no duplicate pending request.

  4. Guide search derive fourth

    Derive visibility and order from the address in one pass. Check: refresh, page, and share a filtered view and confirm the same list, total, and order return, then clear search and confirm only the words are removed.

  5. Onboarding and system pages last

    Drop derived caches in onboarding and load one shared system page script for not found and offline. Check: switch role and identity and confirm the list follows checked state, and open a system page offline and confirm retry keeps the same address.

  6. Session store for sign-in, workspace, and role view state

    Introduce one session and shell store in public/app/index.html, derive drawer, inert, dialog focus, boot, and table labelling from one state, and have the onboarding store read typed workspace, person, and job from that single store with no derived caches. Check: open and close the drawer by keyboard and confirm focus returns to Menu, open a dialog and confirm focus stays inside it, change the typed workspace name on the onboarding page and confirm progress moves to the new device key with no server record changed, and confirm no site file stores a token, a secret, or a workspace id as truth.

One store per state, server truth for records

Read this map before changing shared state, then apply the steps in order with the check named for each step.