Repository navigation
Make profile achievements reflect learner progress - #11
Merged
Merged
Conversation
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.
Fixes a production truthfulness bug: a brand-new account was being shown achievements it had not earned.
The bug
src/pages/Profile.tsxrendered two achievements as literal JSX:So a fresh production account displayed both, while the streak card directly above read 0 days /
longest 0 and the dashboard read 0 quizzes taken. Real streak figures beside fabricated
achievements is the worst version of this bug: it looks like seeded demo data.
Meanwhile the backend already had genuine achievement logic —
progressService.jscreates a realfirst_quizachievement and persists it — andUserProgress.achievementswas simply never read bythe frontend. Nothing exposed it.
Option B: milestones are now real achievements
updateStudyStreakcomputed genuine streaks and fired a notification at 3/7/14/30/50/100 days, butpersisted no achievement. So wiring the page to
progress.achievementsalone would have shownfirst_quizand never a streak — a permanently half-empty section called "Recent Achievements". Amilestone now does both, via one idempotent helper:
Idempotent by id, returning whether this call awarded it so the notification fires only on the
transition.
first_quizwas refactored onto the same helper, so both paths share one contract.Streak arithmetic,
lastStudyDate, the early return for a same-day repeat, and the existingnotification behaviour are all untouched.
A learner with no progress document — studied three days but never sat an assessment — gets a
tracked streak and no achievement, because there is nothing to attach one to. That case is covered.
Exposed additively, no new endpoint
UserProgresswas already imported inauthController.js, so achievements are attached in the oneplace all three auth paths funnel through:
signup,loginandGET /auth/meall return it. Every fieldtoSafeJSON()produced is passedthrough unchanged, so this is purely additive — no new route, no changed shape for existing clients.
A missing progress document yields
[], which is the truthful answer rather than an error.Empty state with an unlock hint
Motivating, and a hint rather than a claim. Once anything is earned, only earned items are listed —
achievements are never displayed because they exist in the catalogue.
On the wording question
You asked to rename "First Quiz Completed" → "First Assessment Completed" only if the domain term
is now "assessment". Having read the backend: the persisted achievement is titled "First Steps"
and its description already reads "Completed your first assessment." The hard-coded string was the
only place still saying "quiz", and it is deleted. So there was nothing to rename — the real copy was
already consistent, and renaming the stored title would have desynced it from the existing
notification ("You've earned the 'First Steps' achievement"). A test asserts the rendered page never
says "quiz".
Two emoji removed as a side effect
The notification titles in this same function carried 🏆 and 🔥, and notifications are user-facing
via
NotificationBell.tsx. Since I was editing the function and the standing goal is no emoji in theproduct, both are gone ("Achievement unlocked", "3 day streak"). Flagging it because it is slightly
wider than the literal brief.
Tests — 16 new
attemptProcessing.test.js(+5, backend): milestone persistsstreak_3with title, description andtimestamp; nothing before the milestone; same-day repeat and a replayed day do not duplicate; a 4-day
streak does not re-award the 3-day award; a learner with no progress document neither crashes nor
gains one. Existing first-assessment coverage (
first_quizabsent before, present after, stable onreplay) already held.
profileAchievements.test.tsx(+10, frontend): nothing earned → empty state and hint, and neitherhard-coded entry present; a missing
achievementsfield reads as none earned; real achievementsrender with titles and descriptions; newest first; an achievement with no description renders;
assessment vocabulary only; and a real 3-day streak shows figures agreeing with its achievement,
while a zero streak shows no streak achievement.
Verification
Two of my own test bugs were caught before commit: an ambiguous
getByText("3")(both streak figuresrender 3), and the notification-title assertion following the emoji change.
Needs a manual check on production: sign up a fresh account, complete nothing, and confirm
Profile shows "No achievements yet" rather than two achievements.