Skip to content

Agent Directive: Offline "Now & Next" & Local Overrides

Objective

Implement the offline-first querying engine in the Astro PWA using Dexie.js. Ensure the application can calculate real-time "Now & Next" logistics entirely on-device and support local user mutations (overrides) for last-minute schedule changes.

Execution Sequence

1. Update the Dexie.js Schema

  • Navigate to the frontend database configuration (app/src/db/ or similar Dexie setup file).
  • Update the Act schema to support local overrides. Add the following boolean and optional fields:
    • is_local_override: boolean (default to false)
    • local_start_time: string (optional)
    • local_end_time: string (optional)
    • local_stage_id: string (optional)

2. Implement the "Now & Next" Logic Hook

  • Create a new utility or React/Solid hook (e.g., app/src/utils/nowAndNext.ts).
  • Write a function that accepts the current Date.now() and queries the local Dexie.js database for acts where the user highlight is > 0.
  • The function must return:
    • Now: The act currently playing (where current time is between start and end time).
    • Next: The next act scheduled to play.
    • Transition Time: The calculated spatial travel time between the "Now" stage and the "Next" stage.
  • Crucial Logic: The query must prefer local_start_time and local_stage_id over the master schedule data if is_local_override is true.

3. Sync Conflict Resolution

  • Read the offline sync logic in docs/08-sync-engine.md (or the corresponding source file if already implemented).
  • Ensure that when the background Service Worker fetches fresh JSON data from the ERO Edge API, it performs a differential merge (upsert) in Dexie.js. It MUST NOT overwrite any rows where is_local_override === true.

4. Update the System Builder

  • Read SYSTEM_BUILDER.md.
  • Add docs/15-offline-now-next-engine.md to the Artefact Index.
  • Insert this as Step 4 under Phase 1: Frontend Foundation.