Skip to content

新增 apps/mobile 完整登入同步迴圈(Phase 4)#12

Merged
Retsomm merged 2 commits into
mainfrom
dev
Jul 13, 2026
Merged

新增 apps/mobile 完整登入同步迴圈(Phase 4)#12
Retsomm merged 2 commits into
mainfrom
dev

Conversation

@Retsomm

@Retsomm Retsomm commented Jul 13, 2026

Copy link
Copy Markdown
Owner
  • useProgress.ts 接上 Clerk:未登入沿用 AsyncStorage 訪客模式,登入後打 apps/web 既有的五支 API(migrate-local/answer/save-toggle/finish-level/finish-review), 伺服器回傳的權威 Progress 覆蓋本地樂觀更新
  • 新增 context/ProgressContext.tsx(ProgressProvider)讓 Home/Profile 兩個 tab 共用同一份 progress state,避免各自呼叫 hook 造成搬遷邏輯重複觸發
  • 修正搬遷時重讀 AsyncStorage 可能撞上尚未落盤的 race,改用記憶體內的 progressRef
  • iOS/Android 模擬器皆已實測:訪客進度登入後正確搬進資料庫且前後一致
  • docs/roadmap.md、docs/rn-migration.md 同步更新目前進度與除錯記錄

Summary by CodeRabbit

  • New Features

    • Added shared progress tracking across Home and Profile screens.
    • Progress now syncs with your account across devices after signing in.
    • Visitor progress can be transferred to your account during first sign-in.
    • Profile statistics now reflect shared progress, including XP, streaks, completed levels, and answered questions.
    • Added reliable loading behavior while progress data is restored.
  • Documentation

    • Updated migration and roadmap documentation to reflect completed mobile progress synchronization.

- useProgress.ts 接上 Clerk:未登入沿用 AsyncStorage 訪客模式,登入後打 apps/web
  既有的五支 API(migrate-local/answer/save-toggle/finish-level/finish-review),
  伺服器回傳的權威 Progress 覆蓋本地樂觀更新
- 新增 context/ProgressContext.tsx(ProgressProvider)讓 Home/Profile 兩個 tab
  共用同一份 progress state,避免各自呼叫 hook 造成搬遷邏輯重複觸發
- 修正搬遷時重讀 AsyncStorage 可能撞上尚未落盤的 race,改用記憶體內的 progressRef
- iOS/Android 模擬器皆已實測:訪客進度登入後正確搬進資料庫且前後一致
- docs/roadmap.md、docs/rn-migration.md 同步更新目前進度與除錯記錄

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
easy-learn Skipped Skipped Jul 13, 2026 3:46am

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Retsomm, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ac441add-7c38-48ac-810d-eb3da3ab9b3d

📥 Commits

Reviewing files that changed from the base of the PR and between 6ea6c4f and e3f3b35.

📒 Files selected for processing (2)
  • apps/mobile/app/(tabs)/profile.tsx
  • apps/mobile/hooks/useProgress.ts
📝 Walkthrough

Walkthrough

The mobile app now centralizes progress in a provider, hydrates visitor data from AsyncStorage, synchronizes signed-in progress with server APIs, and lets Home and Profile consume the same state. Migration and roadmap documentation were updated to record the completed flow and validation.

Changes

Mobile progress synchronization

Layer / File(s) Summary
Progress state and server synchronization
apps/mobile/hooks/useProgress.ts
useProgressState hydrates local progress, handles visitor migration and server authority, and synchronizes authenticated progress mutations.
Shared context wiring
apps/mobile/context/ProgressContext.tsx, apps/mobile/app/_layout.tsx
ProgressProvider exposes one progress state instance around the navigation tree, while useProgress enforces provider usage.
Home and Profile progress consumers
apps/mobile/app/(tabs)/index.tsx, apps/mobile/app/(tabs)/profile.tsx
Home and Profile read shared progress; Profile waits for hydration before rendering derived statistics.
Migration status and validation records
docs/rn-migration.md, docs/roadmap.md
Documentation records the completed synchronization phase, validation process, and updated project roadmap.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant ProgressProvider
  participant AsyncStorage
  participant Clerk
  participant ProgressAPI
  participant HomeProfileTabs
  App->>ProgressProvider: mount around navigation tree
  ProgressProvider->>AsyncStorage: hydrate local progress
  Clerk->>ProgressProvider: expose signed-in state and token
  ProgressProvider->>ProgressAPI: migrate or load authenticated progress
  HomeProfileTabs->>ProgressProvider: read shared progress
  HomeProfileTabs->>ProgressAPI: sync progress mutations
  ProgressAPI-->>ProgressProvider: return server-authoritative progress
Loading

Possibly related PRs

  • Retsomm/EasyLearn#3: Adds related wrong-question review and streak behavior using shared progress fields and handlers.
  • Retsomm/EasyLearn#8: Adds the progress API routes called by the mobile synchronization hook.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly matches the main change: adding the apps/mobile Phase 4 login sync loop.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/mobile/app/`(tabs)/profile.tsx:
- Around line 72-82: Update the signed-in profile view’s outer View in the
hydrated branch to use containerStyle instead of styles.container, matching the
other profile branches and preserving safe-area insets.

In `@apps/mobile/hooks/useProgress.ts`:
- Around line 121-136: Gate the signed-in server-sync branches in all four
progress mutation callbacks, including answerQuestion, on migratedRef.current
before calling getToken or posting. Keep local progress updates immediate, and
allow each POST to start only after the initial progress fetch and migrate-local
flow has completed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c426396-cc30-43c4-864d-b786e988c6d7

📥 Commits

Reviewing files that changed from the base of the PR and between 9ae99fd and 6ea6c4f.

📒 Files selected for processing (7)
  • apps/mobile/app/(tabs)/index.tsx
  • apps/mobile/app/(tabs)/profile.tsx
  • apps/mobile/app/_layout.tsx
  • apps/mobile/context/ProgressContext.tsx
  • apps/mobile/hooks/useProgress.ts
  • docs/rn-migration.md
  • docs/roadmap.md

Comment thread apps/mobile/app/(tabs)/profile.tsx
Comment thread apps/mobile/hooks/useProgress.ts
- 已登入分支改用 containerStyle,避免內容被狀態列遮住
- 四個進度異動函式(answer/toggleSaved/finishLevel/finishReview)改為等
  migrate-local 搬遷完成才打伺服器 API,避免搬遷回應蓋掉剛登入就作答的結果

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Retsomm
Retsomm merged commit 97fdc44 into main Jul 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant