Cache Statistics for Offline Viewing
The statistics dashboard must cache the most recently loaded statistics data locally on the device so that the dashboard remains accessible when the user is offline. The cache should store the complete dataset including chart data and summary card values. When online, the cache should be refreshed automatically on dashboard load and invalidated when new activities are registered. A visible indicator should communicate when cached data is being displayed. The cache implementation uses the stats-cache-manager component backed by local device storage.
User Story
Acceptance Criteria
- Given I have previously loaded my statistics while online, When I open the statistics screen while offline, Then I see my most recently cached statistics with a banner or indicator informing me that I am viewing offline data
- Given I am online and load the statistics dashboard, When the data loads successfully, Then the local cache is updated with the new data for future offline use
- Given I register a new activity while offline, When I later sync and reload the statistics, Then the cache is invalidated and updated to include the newly registered activity
- Given the cache is empty and I am offline, When I open the statistics screen, Then I see an informative empty state explaining that statistics are unavailable offline and prompting me to connect to load data
- Given cached data is displayed, When I regain connectivity, Then the dashboard automatically refreshes from the server without requiring manual intervention
Business Value
Peer mentors frequently operate in community settings, homes, and remote locations where connectivity is unreliable. All three organizations serve users across Norway including rural and northern regions. Offline capability prevents the frustration of a blank statistics screen and ensures peer mentors can access their data during meetings or presentations where demonstrating their contribution is valuable.
Components
- Statistics Cache Manager data
- Stats Cache Invalidator infrastructure
- Stats Repository data
- Supabase Stats Database Views infrastructure
- Coordinator Statistics BLoC infrastructure
- Personal Statistics BLoC infrastructure