Appearance
Agent Directive: Offline Synchronisation Engine
Objective
Implement the background synchronisation logic for the Astro PWA. The application must hydrate its local Dexie database from the Cloudflare edge API when online and queue local modifications when offline.
Execution Sequence
1. Implement the Sync Logic
- Create a new file at
app/src/lib/sync.ts. - Implement a
hydrateSchedule()function that callsGET /api/datafrom the Cloudflare Worker and overwrites the local Dexiefestivals,stages, andbandstables with the master dataset. - Implement a
pushLocalChanges()function that queries Dexie for any user routes wheresync_status = 'pending', pushes them to the Cloudflare API, and updates their status to'synced'upon success.
2. Integrate Network Event Listeners
- Update
app/src/pages/index.astro. - Add client-side JavaScript to listen for
window.addEventListener('online')andwindow.addEventListener('offline'). - Trigger
pushLocalChanges()automatically when the device regains connectivity. - Trigger
hydrateSchedule()on initial page load if the Dexie tables are empty and the device is online.