Description
ClassHub is an academic PWA designed for mobile-first campus environments with intermittent Wi-Fi and mobile connectivity. Currently, if a Class Representative or Teacher attempts to publish an announcement while offline or during a network drop, the request fails.
We need to extend our existing IndexedDB offline action queue (src/lib/offlineDb.ts) to store pending announcement drafts locally and automatically replay them when network connectivity is restored.
Relevant files
src/lib/offlineDb.ts (IndexedDB schema and action queue helpers)
src/lib/offlineSync.ts (Network listener and background action playback)
src/pages/app/AnnouncementsPage.tsx (Announcement composer)
tests/unit/offlineSync.test.ts (Unit test suite for offline queueing and playback)
Requirements and acceptance criteria
-
IndexedDB action extension:
- Extend
OfflineAction in src/lib/offlineDb.ts to support type: 'announcement'.
- Ensure the action stores payload data:
title, body, priority, deadline, targetBatch, sectionId, and authorId.
-
Offline composer behavior:
- When submitting an announcement while
!navigator.onLine or upon a fetch failure, enqueue the action via enqueueAction('announcement', payload).
- Display a notification/indicator:
"Saved offline — will publish automatically when you reconnect".
- Optimistically prepend the draft into the announcements list with a subtle
"Queued (Offline)" badge.
-
Reconnection & playback:
- In
src/lib/offlineSync.ts, update playbackOfflineActionsClient to handle 'announcement' actions by inserting them into Supabase via supabase.from('announcements').insert(...).
- Upon successful server response, dequeue the action from IndexedDB and invalidate the React Query cache
['announcements', sectionId].
-
Testing:
- Add unit tests in
tests/unit/offlineSync.test.ts covering:
- Enqueueing an announcement payload when offline.
- Playback execution upon online event.
- Successful dequeueing and retry on failure.
- All tests must pass with
npm test.
Testing locally
npm test tests/unit/offlineSync.test.ts
Description
ClassHub is an academic PWA designed for mobile-first campus environments with intermittent Wi-Fi and mobile connectivity. Currently, if a Class Representative or Teacher attempts to publish an announcement while offline or during a network drop, the request fails.
We need to extend our existing IndexedDB offline action queue (
src/lib/offlineDb.ts) to store pending announcement drafts locally and automatically replay them when network connectivity is restored.Relevant files
src/lib/offlineDb.ts(IndexedDB schema and action queue helpers)src/lib/offlineSync.ts(Network listener and background action playback)src/pages/app/AnnouncementsPage.tsx(Announcement composer)tests/unit/offlineSync.test.ts(Unit test suite for offline queueing and playback)Requirements and acceptance criteria
IndexedDB action extension:
OfflineActioninsrc/lib/offlineDb.tsto supporttype: 'announcement'.title,body,priority,deadline,targetBatch,sectionId, andauthorId.Offline composer behavior:
!navigator.onLineor upon a fetch failure, enqueue the action viaenqueueAction('announcement', payload)."Saved offline — will publish automatically when you reconnect"."Queued (Offline)"badge.Reconnection & playback:
src/lib/offlineSync.ts, updateplaybackOfflineActionsClientto handle'announcement'actions by inserting them into Supabase viasupabase.from('announcements').insert(...).['announcements', sectionId].Testing:
tests/unit/offlineSync.test.tscovering:npm test.Testing locally
npm test tests/unit/offlineSync.test.ts