Skip to content

[FEATURE]: Add offline announcement draft queue with background sync recovery #27

Description

@Hanu2908

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

  1. 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.
  2. 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.
  3. 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].
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: pwaProgressive Web App, service workers, and offline syncarea: reliabilityFault tolerance, data integrity, and fallback handlingenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions