π΄ Offline Sync β
Offline Sync (providers/sync-provider.tsx) β
SyncProvider monitors network state and app foreground transitions to automatically flush any notes created while offline.
Sync Triggers β
| Trigger | Delay |
|---|---|
| Network reconnects | 1.5s debounce |
| App comes to foreground | Immediate |
| New note added to offline queue | Immediate |
Retry Strategy β
Failed uploads use exponential backoff: 5 retries with delays of 5s, 25s, 125s, 625s, 3125s (max ~52 min total). After 5 failures, the note is marked failed and an alert is shown to the user.
Reading Sync State β
tsx
import { useSyncContext } from '@/providers/sync-provider';
const { syncState, failedCount, retryAll } = useSyncContext();
// syncState: 'idle' | 'syncing' | 'error'
// failedCount: number of permanently failed notes
// retryAll(): manually retry all failed notesOffline Queue (hooks/use-offline-queue.ts) β
Notes created without connectivity are saved to MMKV (synchronous key-value storage, faster than AsyncStorage).
The offlineNotes array is shaped as Draft[] so it can be rendered in the same list component as synced notes.
ts
const { offlineNotes, addToQueue, removeFromQueue } = useOfflineQueue();
// Add a note to the queue (called automatically by useCreateNote on network error)
addToQueue(draft);
// Remove after successful sync
removeFromQueue(draft.id);