Supabase Realtime Approval Subscription
Component Detail
Description
Infrastructure wrapper that manages Supabase Realtime channel subscriptions for the coordinator review queue and for the peer mentor's own claim list. Delivers live status updates to the UI without polling, and integrates with the BLoC/Riverpod state layer to trigger reactive rebuilds on incoming events.
realtime-approval-subscription
Summaries
Real-time status visibility is a direct driver of coordinator efficiency and driver satisfaction. This component eliminates the need for manual page refreshes by delivering instant claim status updates to both coordinators and peer mentors the moment they occur. The result is faster approval cycles, reduced administrative back-and-forth, and a more responsive experience that builds user trust in the platform. By removing polling overhead, the system also reduces server costs and improves reliability under load, contributing to a leaner operational model and a competitive edge in delivering a modern, responsive mobile experience.
This is a medium-complexity infrastructure component that underpins the real-time UX across multiple screens. It has no external service dependencies beyond the existing Supabase integration, which reduces integration risk. However, it is a foundational piece — any delay in its delivery will block the coordinator review queue and peer mentor claim list features from achieving their live-update behaviour.
Testing must cover reconnection logic under poor network conditions, subscription cleanup to prevent memory leaks, and correct event routing to BLoC/Riverpod layers. Plan for device-specific network testing (iOS/Android) as part of QA. Lifecycle management on screen disposal is a key delivery risk.
Wraps Supabase Realtime channel subscriptions for two distinct data scopes: organisation-level claims (coordinator view) and user-level claims (peer mentor view). Each subscription is identified by a channelId, enabling targeted unsubscribe and reconnect operations. Incoming change events must be routed to the correct BLoC or Riverpod provider — implement a dispatcher pattern keyed on event type and scope. Reconnection uses exponential backoff via Supabase's built-in channel lifecycle hooks.
The dispose() method must be called in the widget's dispose() lifecycle to prevent dangling subscriptions. Data model dependency is expense_claim; listen for INSERT, UPDATE, and DELETE events on this table filtered by RLS-scoped queries. Avoid holding strong references to BuildContext inside callbacks.
Responsibilities
- Open and manage Supabase Realtime channel for claim status changes
- Route incoming change events to the correct BLoC or Riverpod provider
- Reconnect automatically on channel disconnect
- Clean up subscriptions when screens are disposed
Interfaces
subscribeToOrganisationClaims(organisationId, onEvent)
subscribeToUserClaims(userId, onEvent)
unsubscribe(channelId)
reconnect(channelId)
dispose()