Commit Graph

22 Commits

Author SHA1 Message Date
MarkLo127 42b5b8dab8 Implement Plan C3: Cloud Sync Retry with Local Caching
Features:
- Add cloud sync retry service for failed report uploads
- Automatic retry loop that runs every 30 seconds
- Exponential backoff: 1 attempt per 30s with max 5 retries per report
- Reports always saved locally (IndexedDB) - cloud sync failures don't block user
- SyncInitializer component starts retry loop on app startup

Changes:
- frontend/lib/sync-retry.ts: New service for managing cloud sync retries
  - retryPendingSyncs(): Attempt to sync all pending reports
  - markForRetry(): Mark a report for retry
  - startRetryLoop(): Start automatic retry background task
  - stopRetryLoop(): Clean up retry loop on app shutdown
  - getPendingSyncCount(): Get number of reports awaiting sync

- frontend/components/providers/SyncInitializer.tsx: Client component that:
  - Initializes retry loop only when user is authenticated
  - Cleans up on component unmount
  - Logs retry service startup/shutdown

- frontend/app/layout.tsx: Add SyncInitializer to root layout
  - Ensure retry loop starts automatically for authenticated users

- frontend/app/analysis/page.tsx: Improve error handling
  - Log warning when cloud sync fails
  - Report remains safely in IndexedDB even if cloud save fails

Impact:
- Reports never get lost even if cloud save fails temporarily
- Automatic retry ensures eventual consistency with cloud
- User experience improved: no more "report deleted" after 1 hour
- Network issues no longer result in data loss
- Addresses original issue: reports now persists locally indefinitely

Technical Design:
- Retry tracking uses in-memory Map (resets on page refresh)
- Future enhancement: could persist retry state to localStorage
- Cloud sync becomes eventual consistency rather than immediate

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-12 21:35:29 +08:00
MarkLo 16e513a921 新增英文語系支援 2025-12-24 01:20:33 +08:00
MarkLo 40b9a02c42 2025-12-20 09:38:17 +08:00
MarkLo a724f2f447 2025-12-20 09:27:15 +08:00
MarkLo 67830031cc 2025-12-20 09:12:54 +08:00
MarkLo d0d0f7a803 2025-12-18 19:14:09 +08:00
MarkLo 7fabb34e01 2025-12-18 19:00:42 +08:00
MarkLo de28c3e129 2025-12-17 18:54:15 +08:00
MarkLo 908dafc733 2025-12-17 18:15:51 +08:00
MarkLo 53f9202ce8 2025-12-17 18:01:45 +08:00
MarkLo 81d77bea80 2025-12-17 17:48:08 +08:00
MarkLo 99fc89eafe 2025-12-17 06:03:17 +08:00
MarkLo 3568ff5b33 2025-12-15 03:38:56 +08:00
MarkLo 8ca4072233 fix: add apple-touch-icon.png for iOS Safari compatibility 2025-12-14 02:30:55 +08:00
MarkLo beb6ea6bdc 2025-12-13 23:26:03 +08:00
MarkLo 9280c71bfc 2025-12-13 22:50:40 +08:00
MarkLo 5d3751602e 2025-12-13 06:00:19 +08:00
MarkLo e1eaf964f6 2025-12-01 01:54:44 +08:00
MarkLo 8d679007bf 2025-11-25 17:03:17 +08:00
MarkLo 40eeb31361 2025-11-21 07:25:16 +08:00
MarkLo cc47085cd4 2025-11-21 03:29:20 +08:00
MarkLo 2872f18b47 2025-11-20 21:56:47 +08:00