Commit Graph

15 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
MarkLo127 d58e80a962 2026-01-27 13:22:52 +08:00
MarkLo 16e513a921 新增英文語系支援 2025-12-24 01:20:33 +08:00
MarkLo 4bbeaa8e18 2025-12-17 05:41:30 +08:00
MarkLo cf4aaa09b1 feat: auto-save reports + fix PDF download from history
1. Auto-save reports when page closes:
   - Added beforeunload handler to auto-save analysis to history
   - Saves to local IndexedDB and cloud (if authenticated)
   - Prevents data loss if user accidentally closes the page

2. Fix PDF download from history page:
   - Made taskId optional in DownloadReports component
   - Added direct mode: can pass reports data directly
   - Updated backend to support both task-based and direct-data modes
   - History reports now have download PDF option available
2025-12-14 03:21:59 +08:00
MarkLo 4269fdec26 2025-12-12 19:01:49 +08:00
MarkLo c2b8706bf2 2025-12-07 17:13:57 +08:00
MarkLo 34dc5b0f87 2025-12-02 23:03:41 +08:00
MarkLo e1eaf964f6 2025-12-01 01:54:44 +08:00
MarkLo 63ac0668ac 2025-11-25 02:13:52 +08:00
MarkLo e898ebb2b5 2025-11-21 05:12:02 +08:00
MarkLo 8ef63d715c 2025-11-21 04:43:46 +08:00
MarkLo cc47085cd4 2025-11-21 03:29:20 +08:00
MarkLo 44fd92850d 2025-11-20 23:19:22 +08:00
MarkLo 2872f18b47 2025-11-20 21:56:47 +08:00