Client state and persistence
The client state system gives the web application one shared model for timetable work, planning, user preferences, fetched data, and short-lived request status. Redux actions describe changes, reducers apply them, selectors shape data for views, and browser storage keeps the parts that should survive a page reload. It is the state and persistence layer within the broader web application runtime.
State model
Store slices
The Redux store groups state by the kind of client data it serves. Timetables and planner data represent the user's work. Module and venue data support that work. Settings and theme state control the user's view. App state and request state describe the current browser session.
The main slices are:
| Slice | Purpose | Lifetime |
|---|---|---|
timetables | Selected lessons, colors, hidden modules, TA modules, and archived academic-year lessons | Persistent |
planner | Planned modules, placeholder modules, custom module data, and planner bounds | Persistent |
moduleBank | Fetched module lists, module details, and archive data used by timetable and planner views | Persistent cache |
venueBank | Fetched venue data used by venue features | Persistent cache |
theme | Theme choice, timetable direction, and title display | Persistent |
settings | Student, faculty, color-scheme, module-table, notification, and feature choices | Persistent |
requests | Loading, success, or failure status for named requests | Per tab |
app | Online state, active items, notifications, refresh prompts, and modal state | Per tab |
undoHistory | Recent snapshots needed for undo and redo | Session and tab-synced |
The state shape is defined by State, while the slice types describe the data that each product area owns. This split lets views read one shared model without owning the rules for how that model changes. State Reducer state types
Actions and reducers
An action is a typed description of an event. A reducer is the state rule that turns the current state and an action into the next state. Simple controls dispatch plain actions. Work that needs a request or more than one state read uses a thunk, which can dispatch more actions after it receives data.
Timetable actions also protect the state boundary before the reducer receives a change. Adding a module loads its supporting module data first, then records a generated lesson choice; if the load fails, the user receives a retry notification instead. Replacing or checking a timetable validates its module set, migrates older lesson formats, and repairs invalid lesson choices. TA actions translate between ordinary class choices and the detailed lesson identifiers needed for TA modules, then recheck the timetable when a TA module is disabled. The reducer stores the result by semester and keeps its related color, hidden-module, and TA data aligned. Planner actions follow the same pattern for adding, moving, and removing planned modules.
References: website/…/redux.ts• L7-17 website/…/timetables.ts• L72-97 website/…/timetables.ts• L208-289 website/…/timetables.ts• L388-469 website/…/timetables.test.ts• L40-99 website/…/timetables.test.ts• L235-362 website/…/timetables.test.ts• L463-641 website/…/timetables.ts• L237-318 website/…/planner.ts• L38-77 website/…/planner.ts• L60-167
Selectors
Selectors are the read boundary between the store and the views. They select a slice or derive a view-ready result, such as the lessons, colors, hidden modules, or TA modules for one semester. Planner selectors combine the plan with module data and settings to expose conflicts and module information instead of making each view repeat those rules.
This approach keeps stored data close to the user's choices while keeping display data close to the needs of a screen. It also gives request-aware selectors one place to answer questions such as whether archive data is loading or available.
References: website/…/timetables.ts• L10-57 website/…/planner.ts• L167-265 website/…/moduleBank.ts• L12-45
Client data lifecycle
State transition flow
The client data lifecycle starts with a user event or a request result and ends with updated state that views can read. Middleware handles work around the reducer path, while selectors provide the final shape used by the interface.
The flow connects user intent, remote data, state changes, and persistence as follows:
flowchart LR
U[User or view event] --> A[Action or thunk]
A --> M[Middleware]
M -->|Remote request| E[External API]
E -->|Success or failure action| R[Reducers]
A --> R
R --> S[Redux store]
S --> Q[Selectors]
Q --> V[Views]
S --> P[Persisted slices]
P --> B[Browser storage]
On a later page load, persisted slices return from browser storage and join the default state supplied by reducers. The application waits for this restore step before it asks another open tab for a full state snapshot. This order keeps restored timetable and theme data paired with the matching undo state.
References: website/…/configure-store.ts• L24-73 website/…/index.ts• L23-60 website/…/persistReducer.ts• L14-30
Remote request state
API actions use a request key to name one operation. Request middleware turns the action into a three-stage lifecycle: start, success, or failure. The requests slice stores only that lifecycle status and an error for failures, so views can show loading or error states without treating the response itself as request state.
Successful responses can update shared data slices. For example, module-list and module-detail responses populate the module bank, and the request selectors let views distinguish missing data from data that is still being fetched. Request status stays local to a browser tab. Cross-tab state sync does not copy in-flight or failed request actions because their error objects cannot safely cross the browser channel.
For the remote systems behind these actions, see Serverless and external APIs.
References: website/…/requests.ts• L19-65 website/…/requests-middleware.ts• L60-117 website/…/requests.ts• L15-53 website/…/state-sync-middleware.ts• L15-31 website/…/state-sync-middleware.ts• L55-71
Fetched data cache
Fetched module and venue data acts as a client cache for timetable and planner work. The module bank keeps a compact list for selection and fuller records for modules that the user opens or adds. It also records archive data when an older academic year is needed. The cache can remove older module records when it grows beyond its working limit, while timetable choices remain the user's persistent data.
This separation matters during reloads and failures. A timetable can remain available from the store even when a fresh module request fails, while a view can use request state to explain that its supporting details are not ready.
References: website/…/moduleBank.ts• L23-27 website/…/moduleBank.ts• L89-149 website/…/moduleBank.ts• L20-25 website/…/moduleBank.ts• L38-115
Persistence boundaries
Redux persistence
Redux persistence writes selected state slices to browser local storage. The persisted set includes the user's timetable, planner, theme, settings, and useful fetched caches. Request status, app session state, and undo history are not part of the normal persisted slice set because they describe the current tab or current session rather than durable user data.
Persistence also supports state migrations. When the shape or meaning of stored data changes, a slice can convert old data or reset stale data before the application uses it. Timetable state handles an academic-year change by moving the old lessons into its archive instead of placing them into the new year's active timetable. Settings also clears dismissed module-registration notices when their semester key is old.
References: website/…/index.ts• L10-37 website/…/timetables.ts• L32-84 website/…/settings.ts• L125-156 website/…/planner.ts• L169-207 website/…/moduleBank.ts• L124-141
Browser storage
The storage boundary hides browser storage limits and browser modes from the rest of the client. It checks whether local storage can be read and written. If it cannot, it uses an in-memory substitute so the application can still run for the current page session.
The storage helper also converts structured values to and from JSON and reports storage errors. Redux persistence uses the Redux Persist storage adapter. Other browser-only features use named keys for small values such as dismissed notices, contact details, and game scores. These values are separate from the Redux store and do not participate in Redux actions or reducers.
References: website/…/localStorage.ts• L39-76 website/…/index.ts• L5-55 website/…/keys.ts• L1-28 website/…/persistReducer.ts• L14-30
Cross-tab state
Open tabs share durable client changes through browser state synchronization. A new tab can adopt a peer's state after local persistence finishes restoring. The sync removes notifications and request state from the shared snapshot, then keeps the receiving tab's own request and notification state. This prevents one tab's temporary network work from changing another tab's loading or message state.
The sync keeps successful data actions available to other tabs. A module response can therefore hydrate shared module data in a new tab, while request start and failure actions remain local. Undo history is included in the initial full snapshot so the timetable state and its undo context stay together.
References: website/…/state-sync-middleware.ts• L15-75 website/…/configure-store.ts• L60-71 website/…/index.ts• L55-60
User preferences
Settings
Settings hold durable choices that change how the application presents or interprets the user's data. They cover the selected faculty and student type, color-scheme preference, module-table order, module-registration notices, beta access, comment loading, and prerequisite-tree layout.
Settings actions express user choices and reducer rules keep related values consistent. Module-registration dismissals include a semester key, so a new registration period does not inherit dismissals from an old period. Imported data can also restore settings, with color-scheme values converted to the current preference form.
References: website/…/settings.ts• L8-101 website/…/settings.ts• L28-45 website/…/settings.ts• L47-141 website/…/reducers.ts• L93-115
Themes and color schemes
A theme is a named color palette. A color scheme is the light or dark mode choice. These are separate concerns: the theme selects the palette, while the color-scheme preference selects light mode, dark mode, or the system choice.
Theme state also controls timetable orientation and title display. Users can select a named theme or cycle through the available themes. The selected theme and these timetable display choices persist with the client state, while the available theme names come from the product's theme data.
References: website/…/settings.ts• L1-29 website/…/theme.ts• L1-31 website/…/theme.ts• L15-60 website/…/themes.json• L1-50
Undo history
Undo history gives timetable edits a short recovery path without storing the full application history. It records selected parts of the state before watched actions, moves snapshots between past and future for undo and redo, and clears the redo path when a new watched change occurs.
The current policy watches module removal and complete timetable replacement. It stores the timetable and timetable colors, with a one-snapshot limit. Because the history is not persisted as durable data, cross-tab initialization carries it with the matching state snapshot instead of restoring it from local storage.
References: website/…/index.ts• L31-37 website/…/undoHistory.ts• L1-9 website/…/undoHistory.ts• L17-70 website/…/undoHistory.ts• L87-111 website/…/reducers.ts• L211-216
Change checklist
When these files or sections are changed, remember to consider these:
- A change to a persisted slice's shape needs a matching version or migration. Check the slice's persistence settings and its rehydration rules together.
- A new request lifecycle action must keep its request key and status metadata aligned with
requestsand with the cross-tab filter. Otherwise a view can show stale loading state or another tab can receive an unsafe payload. - A new state field used by a view should have a selector when it is derived by semester, planner context, or request status. This keeps the data rule out of individual views.
- A timetable state change that should be undoable must be represented by one of the actions watched by the undo policy. The stored key paths must also include every value that must change together.
- A new browser-only value must use a unique storage key and the storage wrapper when it is structured or allowed to fail. Do not assume that browser local storage is writable.
- A change to cross-tab state must preserve the split between shared durable data and per-tab request or notification state.
- A timetable action that changes lesson formats or TA status must preserve the conversion and validation rules used before the reducer stores the timetable.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Persisted state uses a new shape without a migration | Rehydration can produce stale or invalid client data | Add a slice migration or reset rule with the persistence version |
| A new API failure action carries a non-cloneable error into state sync | The browser channel rejects the action or a peer keeps a request stuck at loading | Keep request start and failure actions out of cross-tab sync |
| Local storage is blocked, full, or unavailable | Durable choices cannot be saved, or a storage call throws | Use the storage boundary, which falls back in memory and reports write errors |
| The academic year changes while old timetable data is persisted | Old lessons can appear in the active timetable for the wrong year | Reconcile the old lessons into the timetable archive |
| A watched timetable change omits part of the stored snapshot | Undo restores only part of the user-visible timetable state | Keep timetable data and its color map in the undo key paths |
| A timetable or TA change bypasses lesson validation or format conversion | A stored timetable can contain invalid lesson choices or the wrong identifier form | Validate timetable data and convert TA lesson choices before dispatching the state change |
Key files
| File | Why to read it |
|---|---|
| website/…/state.ts | Defines the top-level client state model |
| website/…/index.ts | Shows which slices are persisted, which are session-only, and how undo wraps the store |
| website/…/configure-store.ts | Connects the store, middleware, persistence restore, and cross-tab initialization |
| website/…/requests-middleware.ts | Defines the request lifecycle that feeds request state and data reducers |
| website/…/state-sync-middleware.ts | Defines the boundary between shared state and per-tab state |
| website/…/persistReducer.ts | Connects Redux slices to browser persistence |
| website/…/index.ts | Defines the safe JSON storage boundary for non-Redux browser data |
| website/…/timetables.ts | Shows how timetable data is fetched, validated, migrated, and changed before storage |
| website/…/timetables.ts | Shows the durable timetable model and academic-year reconciliation |
| website/…/settings.ts | Shows preference state, notice lifetime, and settings migration |
| website/…/theme.ts | Shows the theme and timetable display state |
| website/…/undoHistory.ts | Shows the snapshot rules for undo and redo |
| website/…/planner.ts | Shows how stored planner data becomes conflict-aware view data |