Skip to content

fix(frontend): wire offline mode to network transport layers#280

Merged
GiZano merged 2 commits into
mainfrom
frontend/issue-129-offlineMode
May 19, 2026
Merged

fix(frontend): wire offline mode to network transport layers#280
GiZano merged 2 commits into
mainfrom
frontend/issue-129-offlineMode

Conversation

@GiZano

@GiZano GiZano commented May 19, 2026

Copy link
Copy Markdown
Owner

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 isOfflineMode toggle 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 a useEffect watcher for isOfflineMode. Introduced an intentionalClose ref so that when the user toggles offline mode, the socket closes gracefully and bypasses the exponential backoff reconnection loop.
  • api/hooks/useDashboard.ts: Injected isOfflineMode from the Zustand store into the useSensors and useRecentReadings hooks, applying the enabled: !isOfflineMode flag to instantly freeze background refetching intervals.
  • api/hooks/useSensors.ts: Applied the identical enabled: !isOfflineMode check to the useSensorStatistics query 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

  • Booted the app and verified the WebSocket connected and TanStack Query began polling normally.
  • Toggled isOfflineMode to ON and verified via console/network inspector that the WebSocket closed gracefully without triggering reconnection loops, and all HTTP polling ceased.
  • Toggled isOfflineMode to 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

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
@GiZano GiZano requested a review from riccardo0731 as a code owner May 19, 2026 19:50
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
@GiZano GiZano merged commit dbf9b00 into main May 19, 2026
2 checks passed
@GiZano GiZano deleted the frontend/issue-129-offlineMode branch May 20, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant