Update History live after completing a lesson (#91) - #98
Merged
Conversation
markLearned patched the cache with a client-side guess (the caller's concept id, no title/topic) and only a full reload — an app restart — brought the true server history. Reload /me/state after /daily/complete so the History tab reflects the completed concept immediately. If the reload fails the completion has already persisted, so patch in place rather than rolling it back.
markLearned recorded ProgressContext's locally-selected concept, so a signed-in user completing the server's concept stored the wrong one — visible on the reload failure fallback and as a brief wrong-title flash before the reload. Thread the concept the screen actually showed (the server's, when signed in) into markLearned, carrying its title and topic into the optimistic/fallback record.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #91.
Root cause
HistoryScreenreadsprogress.learnedreactively, so it does re-render whenprogress changes. The problem was upstream:
remoteProgressRepository.markLearnedpatched the in-memory cache with a client-side guess — the caller's concept
id, with no title/topic — and never re-fetched. The authoritative history
(
/me/state→ completeddaily_assignments) was only loaded on a fullProgressContext.load(), i.e. an app restart. So until you restarted, Historyshowed stale/mismatched data.
Fix
After
POST /v1/daily/complete, reload/v1/me/stateand return that, soprogress.learnedbecomes the true server record (correct concept, title, topic)and History updates in the same session — no restart. The optimistic update in
ProgressContextstill shows a row instantly; the reload corrects it a momentlater.
Reload-failure safety (the lesson from the #90 review): if the reload fails, the
completion has already persisted server-side, so patch in place using the streaks
the complete call returned rather than throwing — a succeeded completion is never
rolled back.
Verification
npx tsc --noEmitclean. (Mobile has no unit-test harness; this is aclient-only state-propagation fix.)
Mirrors the same reload-on-mutation pattern used for saved concepts in #96.