fix(frontend): wire offline mode to network transport layers#280
Merged
Conversation
Tied the Zustand isOfflineMode toggle directly to the WebSocket connection and TanStack Query hooks. The WebSocket now closes gracefully and all HTTP polling pauses when offline mode is active, preventing background network errors and saving battery. Closes #129
Removed the unused 'ServerCrash' icon from lucide-react-native imports in app/(tabs)/map.tsx. This resolves the @typescript-eslint/no-unused-vars warning that was causing the strict CI/CD pipeline checks to fail. Fixed usePrefrencesStore switching to usePreferencesStore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
name: Pull Request
about: Standard PR format for all QuakeGuard contributions
title: "fix(frontend): wire offline mode to network transport layers"
Overview
This PR resolves an issue where the
isOfflineModetoggle in the Zustand store had no actual effect on the app's transport layers, resulting in continuous background polling, WebSocket reconnection attempts, and error log spam when the user intentionally went offline. The app's network layers now actively watch this state and completely suspend all traffic when offline mode is engaged.Changes Made
WebSocketContext.tsx: Added auseEffectwatcher forisOfflineMode. Introduced anintentionalCloseref so that when the user toggles offline mode, the socket closes gracefully and bypasses the exponential backoff reconnection loop.api/hooks/useDashboard.ts: InjectedisOfflineModefrom the Zustand store into theuseSensorsanduseRecentReadingshooks, applying theenabled: !isOfflineModeflag to instantly freeze background refetching intervals.api/hooks/useSensors.ts: Applied the identicalenabled: !isOfflineModecheck to theuseSensorStatisticsquery to prevent HTTP calls for sensor statistics while disconnected.Impact & Next Steps
Engaging Offline Mode now fully guarantees zero network traffic, eliminating error spam, saving battery life, and preventing memory leaks from backed-up query retries.
Next Steps: We should ensure the UI clearly reflects this disconnected state to the user (e.g., greying out the live seismograph) so they know data is intentionally paused.
Testing Performed
isOfflineModeto ON and verified via console/network inspector that the WebSocket closed gracefully without triggering reconnection loops, and all HTTP polling ceased.isOfflineModeto OFF and verified the WebSocket instantly re-established its connection and TanStack queries resumed fetching live data.Related Issues
Closes #129
Closes #130
Closes #131
Closes #132
Closes #133