Commit 78a9a6a7 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Add first-run onboarding: full-screen walkthrough + welcome Login tagline

New OnboardingOverlay, shown once for an account with
has_completed_onboarding === false - six full-screen steps (Upload,
Telegram linking, Discovery, Social, Soundmarks, then a live Privacy
step reusing Settings' real toggles), each with a small hand-authored
Lottie animation via lottie-react's LottieLight (svg-only, no
expression engine - the full build probes a canvas 2D context at
import time, which jsdom doesn't implement). Gated in ProtectedRoute.tsx
rather than a single page, so a new user reaches it no matter which
protected route they land on first. Skip and the final "Start
exploring" both call the new completeOnboarding() (optimistic local
flip + fire-and-forget API call), so it never reappears - confirmed
against a real fresh login, not just a reload.

Extracted ToggleRow out of Settings.tsx into components/ui/ so the new
privacy step and Settings share one implementation instead of
duplicating it. Login.tsx gained a one-line welcome tagline (reusing
the PWA manifest's own description) above the sign-in form.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 0a6e132d
......@@ -15,6 +15,7 @@
"class-variance-authority": "^0.7.1",
"cn": "^0.4.0",
"leaflet": "^1.9.4",
"lottie-react": "^3.1.2",
"lucide-react": "^1.31.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
......@@ -7961,6 +7962,25 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/lottie-react": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/lottie-react/-/lottie-react-3.1.2.tgz",
"integrity": "sha512-otbTz+Kk1ksYzcWFAlcH8xFGBWkW/hUNEHy6gLvYf7kgEkZxyPT8lXJeBu/5o0xo0cdMwvd/lwkpuXCTSQmJdQ==",
"license": "MIT",
"dependencies": {
"lottie-web": "^5.13.0"
},
"peerDependencies": {
"react": "^18.2.0 || ^19.0.0",
"react-dom": "^18.2.0 || ^19.0.0"
}
},
"node_modules/lottie-web": {
"version": "5.13.0",
"resolved": "https://registry.npmjs.org/lottie-web/-/lottie-web-5.13.0.tgz",
"integrity": "sha512-+gfBXl6sxXMPe8tKQm7qzLnUy5DUPJPKIyRHwtpCpyUEYjHYRJC/5gjUvdkuO2c3JllrPtHXH5UJJK8LRYl5yQ==",
"license": "MIT"
},
"node_modules/lru-cache": {
"version": "11.5.2",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.2.tgz",
......
......@@ -19,6 +19,7 @@
"class-variance-authority": "^0.7.1",
"cn": "^0.4.0",
"leaflet": "^1.9.4",
"lottie-react": "^3.1.2",
"lucide-react": "^1.31.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
......
......@@ -102,6 +102,7 @@ export interface CurrentUser {
id: number
username: string | null
role: UserRole
has_completed_onboarding: boolean
privacy: PrivacySettings
}
......@@ -116,3 +117,11 @@ export function updatePrivacy(update: Partial<PrivacySettings>) {
json: update,
})
}
/** Called once by OnboardingOverlay when the user skips or finishes the welcome walkthrough -
* the backend endpoint is idempotent, so calling this more than once is harmless. */
export function completeOnboarding() {
return apiFetch<{ status: string; has_completed_onboarding: boolean }>('/auth/onboarding/complete', {
method: 'POST',
})
}
{"v":"5.9.0","fr":30,"ip":0,"op":75,"w":240,"h":240,"nm":"Discovery","ddd":0,"assets":[],"layers":[{"ddd":0,"ty":4,"nm":"Core","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,120.0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[0]},"o":{"a":0,"k":[100]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[30,30]},"nm":"Ellipse Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Core Group"}]},{"ddd":0,"ty":4,"nm":"Ring0","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,120.0]},"s":{"a":1,"k":[{"t":0,"s":[40,40],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":45.0,"s":[220,220]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[90],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":45.0,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[40,40]},"nm":"Ellipse Path"},{"ty":"st","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"nm":"Stroke"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Ring0 Group"}]},{"ddd":0,"ty":4,"nm":"Ring1","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,120.0]},"s":{"a":1,"k":[{"t":25,"s":[40,40],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":70.0,"s":[220,220]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":25,"s":[90],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":70.0,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[40,40]},"nm":"Ellipse Path"},{"ty":"st","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"nm":"Stroke"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Ring1 Group"}]},{"ddd":0,"ty":4,"nm":"Ring2","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,120.0]},"s":{"a":1,"k":[{"t":50,"s":[40,40],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":95.0,"s":[220,220]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":50,"s":[90],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":95.0,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[40,40]},"nm":"Ellipse Path"},{"ty":"st","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":5},"nm":"Stroke"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Ring2 Group"}]}]}
\ No newline at end of file
{"v":"5.9.0","fr":30,"ip":0,"op":75,"w":240,"h":240,"nm":"Privacy","ddd":0,"assets":[],"layers":[{"ddd":0,"ty":4,"nm":"BadgeDot","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,130.0]},"s":{"a":1,"k":[{"t":30.0,"s":[0,0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":45.0,"s":[110,110],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":50.25,"s":[100,100]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":33.75,"s":[100]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[20,20]},"nm":"Ellipse Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"BadgeDot Group"}]},{"ddd":0,"ty":4,"nm":"BadgeRing","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,130.0]},"s":{"a":1,"k":[{"t":26.25,"s":[0,0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":41.25,"s":[110,110],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":46.5,"s":[100,100]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":26.25,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[100]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[44,44]},"nm":"Ellipse Path"},{"ty":"fl","c":{"a":0,"k":[1,1,1,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"BadgeRing Group"}]},{"ddd":0,"ty":4,"nm":"Shield","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,120.0]},"s":{"a":1,"k":[{"t":0,"s":[0,0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":22.5,"s":[100,100]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":18.75,"s":[100]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"sr","p":{"a":0,"k":[0,0]},"pt":{"a":0,"k":6},"or":{"a":0,"k":85},"os":{"a":0,"k":0},"r":{"a":0,"k":0},"sy":2,"nm":"Polystar Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Shield Group"}]}]}
\ No newline at end of file
{"v":"5.9.0","fr":30,"ip":0,"op":75,"w":240,"h":240,"nm":"Social","ddd":0,"assets":[],"layers":[{"ddd":0,"ty":4,"nm":"Bubble0","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[70.0,90.0]},"s":{"a":1,"k":[{"t":0,"s":[0,0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":11.25,"s":[110,110],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":15.25,"s":[100,100]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":11.25,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":37.5,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":48.75,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[70,46]},"r":{"a":0,"k":14},"nm":"Rect Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Bubble0 Group"}]},{"ddd":0,"ty":4,"nm":"Bubble1","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[165.0,130.0]},"s":{"a":1,"k":[{"t":13,"s":[0,0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":24.25,"s":[110,110],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":28.25,"s":[100,100]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":13,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":24.25,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":50.5,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":61.75,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[70,46]},"r":{"a":0,"k":14},"nm":"Rect Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Bubble1 Group"}]},{"ddd":0,"ty":4,"nm":"Bubble2","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[100.0,175.0]},"s":{"a":1,"k":[{"t":27,"s":[0,0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":38.25,"s":[110,110],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":42.25,"s":[100,100]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":27,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":38.25,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":64.5,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[70,46]},"r":{"a":0,"k":14},"nm":"Rect Path"},{"ty":"fl","c":{"a":0,"k":[1,1,1,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Bubble2 Group"}]}]}
\ No newline at end of file
{"v":"5.9.0","fr":30,"ip":0,"op":75,"w":240,"h":240,"nm":"Soundmarks","ddd":0,"assets":[],"layers":[{"ddd":0,"ty":4,"nm":"PinHead","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":1,"k":[{"t":0,"s":[120.0,-20],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[120.0,110.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":36.0,"s":[120.0,98.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":42.00000000000001,"s":[120.0,110.0]}]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[0]},"o":{"a":0,"k":[100]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[46,46]},"nm":"Ellipse Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"PinHead Group"}]},{"ddd":0,"ty":4,"nm":"PinPoint","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":1,"k":[{"t":0,"s":[120.0,10],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[120.0,140.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":36.0,"s":[120.0,128.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":42.00000000000001,"s":[120.0,140.0]}]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[180]},"o":{"a":0,"k":[100]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"sr","p":{"a":0,"k":[0,0]},"pt":{"a":0,"k":3},"or":{"a":0,"k":20},"os":{"a":0,"k":0},"r":{"a":0,"k":0},"sy":2,"nm":"Polystar Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"PinPoint Group"}]},{"ddd":0,"ty":4,"nm":"LandingRing","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,160.0]},"s":{"a":1,"k":[{"t":30.0,"s":[20,20],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[20,20],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":63.75,"s":[180,60]}]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":33.75,"s":[90],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":63.75,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[20,20]},"nm":"Ellipse Path"},{"ty":"st","c":{"a":0,"k":[0.235,0.325,0.933,0.35]},"o":{"a":0,"k":100},"w":{"a":0,"k":4},"nm":"Stroke"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"LandingRing Group"}]}]}
\ No newline at end of file
{"v":"5.9.0","fr":30,"ip":0,"op":75,"w":240,"h":240,"nm":"Telegram","ddd":0,"assets":[],"layers":[{"ddd":0,"ty":4,"nm":"Plane","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":1,"k":[{"t":0,"s":[40,200],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[200,40]}]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[-45]},"o":{"a":1,"k":[{"t":0,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":63.75,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"sr","p":{"a":0,"k":[0,0]},"pt":{"a":0,"k":3},"or":{"a":0,"k":24},"os":{"a":0,"k":0},"r":{"a":0,"k":0},"sy":2,"nm":"Polystar Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Plane Group"}]},{"ddd":0,"ty":4,"nm":"Trail","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":1,"k":[{"t":0,"s":[40,200],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[200,40]}]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[0]},"o":{"a":1,"k":[{"t":0,"s":[60],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":63.75,"s":[60],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[0]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[10,10]},"nm":"Ellipse Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,0.35]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Trail Group"}]}]}
\ No newline at end of file
{"v":"5.9.0","fr":30,"ip":0,"op":75,"w":240,"h":240,"nm":"Upload","ddd":0,"assets":[],"layers":[{"ddd":0,"ty":4,"nm":"Arrow","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":1,"k":[{"t":0,"s":[120.0,150.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[120.0,100.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":37.5,"s":[120.0,100.0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[120.0,150.0]}]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[180]},"o":{"a":1,"k":[{"t":0,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":30.0,"s":[100],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":37.5,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":41.25,"s":[0],"i":{"x":[0.42],"y":[1]},"o":{"x":[0.58],"y":[0]}},{"t":75,"s":[100]}]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"sr","p":{"a":0,"k":[0,0]},"pt":{"a":0,"k":3},"or":{"a":0,"k":28},"os":{"a":0,"k":0},"r":{"a":0,"k":0},"sy":2,"nm":"Polystar Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,1]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Arrow Group"}]},{"ddd":0,"ty":4,"nm":"Cloud","sr":1,"ks":{"a":{"a":0,"k":[0,0]},"p":{"a":0,"k":[120.0,120.0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":[0]},"o":{"a":0,"k":[100]}},"ip":0,"op":75,"st":0,"bm":0,"shapes":[{"ty":"gr","it":[{"ty":"el","p":{"a":0,"k":[0,0]},"s":{"a":0,"k":[130,130]},"nm":"Ellipse Path"},{"ty":"fl","c":{"a":0,"k":[0.235,0.325,0.933,0.35]},"o":{"a":0,"k":100},"nm":"Fill"},{"ty":"tr","p":{"a":0,"k":[0,0]},"a":{"a":0,"k":[0,0]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}}],"nm":"Cloud Group"}]}]}
\ No newline at end of file
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { OnboardingOverlay } from './OnboardingOverlay'
import * as AuthContextModule from '../context/AuthContext'
import * as authApi from '../api/auth'
const PRIVACY = { share_location_enabled: false, allow_direct_messages: false }
function mockAuth() {
const completeOnboarding = vi.fn()
vi.spyOn(AuthContextModule, 'useAuth').mockReturnValue({
isAuthenticated: true,
role: null,
userId: null,
hasCompletedOnboarding: false,
isBusinessAdmin: false,
isSuperAdmin: false,
logout: vi.fn(),
completeLogin: vi.fn(),
completeOnboarding,
})
return completeOnboarding
}
describe('OnboardingOverlay', () => {
afterEach(() => {
vi.restoreAllMocks()
})
it('starts on the first feature step and advances through all of them via Next', async () => {
mockAuth()
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: PRIVACY } })
render(<OnboardingOverlay />)
expect(screen.getByText('Upload your music')).toBeInTheDocument()
const next = () => userEvent.click(screen.getByRole('button', { name: 'Next' }))
await next()
expect(screen.getByText('Tag from Telegram')).toBeInTheDocument()
await next()
expect(screen.getByText('Discover what’s playing')).toBeInTheDocument()
await next()
expect(screen.getByText('Hang out with other listeners')).toBeInTheDocument()
await next()
expect(screen.getByText('Music tied to places')).toBeInTheDocument()
await next()
// Final (6th) step is the privacy panel, not another feature card - no more "Next", a
// "Start exploring" button instead.
expect(screen.getByText('Your privacy, your call')).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Next' })).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Start exploring' })).toBeInTheDocument()
})
it('Skip completes onboarding from the very first step, without needing to step through the rest', async () => {
const completeOnboarding = mockAuth()
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: PRIVACY } })
render(<OnboardingOverlay />)
await userEvent.click(screen.getByRole('button', { name: 'Skip' }))
// completeOnboarding fires once the exit transition finishes (see useMountTransition),
// not synchronously on click.
await waitFor(() => expect(completeOnboarding).toHaveBeenCalled())
})
it('"Start exploring" on the final step completes onboarding', async () => {
const completeOnboarding = mockAuth()
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: PRIVACY } })
render(<OnboardingOverlay />)
for (let i = 0; i < 5; i++) {
await userEvent.click(screen.getByRole('button', { name: 'Next' }))
}
await userEvent.click(screen.getByRole('button', { name: 'Start exploring' }))
await waitFor(() => expect(completeOnboarding).toHaveBeenCalled())
})
it('the privacy step\'s toggles are live and call the real updatePrivacy API', async () => {
mockAuth()
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: PRIVACY } })
const updatePrivacy = vi.spyOn(authApi, 'updatePrivacy').mockResolvedValue({
status: 'success',
privacy: { share_location_enabled: true, allow_direct_messages: false },
})
render(<OnboardingOverlay />)
for (let i = 0; i < 5; i++) {
await userEvent.click(screen.getByRole('button', { name: 'Next' }))
}
const locationToggle = await screen.findByRole('switch', { name: 'Share my live location' })
expect(locationToggle).toHaveAttribute('aria-checked', 'false')
await userEvent.click(locationToggle)
await waitFor(() => expect(updatePrivacy).toHaveBeenCalledWith({ share_location_enabled: true }))
await waitFor(() => expect(locationToggle).toHaveAttribute('aria-checked', 'true'))
})
})
import { useCallback, useEffect, useRef, useState } from 'react'
// LottieLight (svg-only, no expression engine) rather than the full Lottie build - these
// animations are plain shape/keyframe primitives with no expressions, and the full build's
// canvas-renderer probing crashes under jsdom (no real <canvas> support) purely at import time,
// before any component even renders.
import { LottieLight as Lottie } from 'lottie-react'
import { MapPin, MessageCircle } from 'lucide-react'
import { Button } from './ui/Button'
import { ToggleRow } from './ui/ToggleRow'
import { useAuth } from '../context/AuthContext'
import { useMountTransition } from '../hooks/useMountTransition'
import { useBackButtonClose } from '../hooks/useBackButtonClose'
import { getMe, updatePrivacy, type PrivacySettings } from '../api/auth'
import { ApiError } from '../api/client'
import uploadAnim from '../assets/onboarding/upload.json'
import telegramAnim from '../assets/onboarding/telegram.json'
import discoveryAnim from '../assets/onboarding/discovery.json'
import socialAnim from '../assets/onboarding/social.json'
import soundmarksAnim from '../assets/onboarding/soundmarks.json'
import privacyAnim from '../assets/onboarding/privacy.json'
const ANIMATION_MS = 300
const STEPS = [
{
key: 'upload',
animationData: uploadAnim,
title: 'Upload your music',
description: 'Add songs straight from your device - Stax tags the artist, album, and cover art for you.',
},
{
key: 'telegram',
animationData: telegramAnim,
title: 'Tag from Telegram',
description: 'Link your Telegram account and pull music straight out of your chats.',
},
{
key: 'discovery',
animationData: discoveryAnim,
title: 'Discover what’s playing',
description: 'Hold your phone up to any speaker - Stax listens for a few seconds and identifies the song.',
},
{
key: 'social',
animationData: socialAnim,
title: 'Hang out with other listeners',
description: 'Join live rooms, pass the aux, post, and message other Stax users.',
},
{
key: 'soundmarks',
animationData: soundmarksAnim,
title: 'Music tied to places',
description: 'Drop a soundmark, see what’s playing nearby, and build live location-based playlists.',
},
] as const
// Privacy is always the final step - unlike the others above, it's interactive (the real
// Settings toggles, not just a description) rather than purely informational, so it's handled
// as its own last panel instead of living in the STEPS array.
const TOTAL_STEPS = STEPS.length + 1
/** One-time full-screen welcome walkthrough, shown the first time an account with incomplete
* onboarding reaches any protected page (see ProtectedRoute.tsx). Follows the same
* useMountTransition/useBackButtonClose choreography as AddToPlaylistModal/FullPlayer - the
* difference is this is a full takeover (z-50, above everything else) rather than a sheet,
* since a multi-step welcome tour needs more presence than a quick picker. */
export function OnboardingOverlay() {
const { completeOnboarding } = useAuth()
const [step, setStep] = useState(0)
const [closing, setClosing] = useState(false)
const { mounted, visible } = useMountTransition(!closing, ANIMATION_MS)
const closedRef = useRef(false)
const [privacy, setPrivacy] = useState<PrivacySettings | null>(null)
const [privacyError, setPrivacyError] = useState<string | null>(null)
const [savingKey, setSavingKey] = useState<keyof PrivacySettings | null>(null)
const requestClose = useCallback(() => setClosing(true), [])
useEffect(() => {
if (!mounted && !closedRef.current) {
closedRef.current = true
completeOnboarding()
}
}, [mounted, completeOnboarding])
// Fetched once on mount, not lazily on reaching the privacy step - the account's current
// privacy defaults (both off) rarely change mid-session, and fetching upfront means the
// final step never has to show its own separate loading flash after four quick taps of Next.
useEffect(() => {
getMe()
.then((res) => setPrivacy(res.user.privacy))
.catch(() => {
// Falls back to the toggles simply not rendering (see the privacy && guard below) -
// the rest of the walkthrough still works fine without this one step's data.
})
}, [])
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Escape') requestClose()
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [requestClose])
useBackButtonClose(true, requestClose)
async function handleTogglePrivacy(key: keyof PrivacySettings) {
if (!privacy) return
const next = !privacy[key]
setSavingKey(key)
setPrivacyError(null)
try {
const res = await updatePrivacy({ [key]: next })
setPrivacy(res.privacy)
} catch (err) {
setPrivacyError(err instanceof ApiError ? err.message : 'Failed to update setting')
} finally {
setSavingKey(null)
}
}
if (!mounted) return null
const onFinalStep = step === STEPS.length
const current = STEPS[step]
return (
<div
role="dialog"
aria-modal="true"
aria-label="Welcome to Stax"
className={`fixed inset-0 z-50 flex h-svh flex-col bg-background text-on-surface transition-opacity duration-300 ease-out motion-reduce:transition-none ${
visible ? 'opacity-100' : 'opacity-0'
}`}
>
<div
className="flex items-center justify-between px-4 pt-4 sm:px-6"
style={{ paddingTop: 'calc(env(safe-area-inset-top) + 1rem)' }}
>
<div className="flex gap-1.5" aria-hidden="true">
{Array.from({ length: TOTAL_STEPS }).map((_, i) => (
<span key={i} className={`h-1.5 w-6 rounded-full transition-colors ${i <= step ? 'bg-primary' : 'bg-surface-container-high'}`} />
))}
</div>
<button
onClick={requestClose}
className="rounded-full px-3 py-1.5 text-sm font-medium text-on-surface-variant transition-colors hover:bg-surface-container-high hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
>
Skip
</button>
</div>
<div className="mx-auto flex w-full max-w-md flex-1 flex-col items-center justify-center px-8 py-6">
{onFinalStep ? (
<div className="w-full">
<Lottie src={privacyAnim} loop autoplay className="mx-auto mb-6 h-48 w-48" />
<h2 className="mb-2 text-center text-xl font-semibold">Your privacy, your call</h2>
<p className="mb-6 text-center text-sm leading-relaxed text-on-surface-variant">
Both of these are off by default - turn them on if you want other Stax users to see you or message you.
You can always change this later in Settings.
</p>
{privacyError && <p className="mb-3 text-center text-sm text-error">{privacyError}</p>}
{privacy && (
<div className="space-y-3">
<ToggleRow
icon={MapPin}
label="Share my live location"
description="Let nearby users see your location and what you're playing on Soundmarks."
checked={privacy.share_location_enabled}
saving={savingKey === 'share_location_enabled'}
onToggle={() => handleTogglePrivacy('share_location_enabled')}
/>
<ToggleRow
icon={MessageCircle}
label="Allow direct messages"
description="Let other users start a direct message conversation with you."
checked={privacy.allow_direct_messages}
saving={savingKey === 'allow_direct_messages'}
onToggle={() => handleTogglePrivacy('allow_direct_messages')}
/>
</div>
)}
</div>
) : (
<div key={current.key} className="animate-content-enter w-full text-center">
<Lottie src={current.animationData} loop autoplay className="mx-auto mb-6 h-48 w-48" />
<h2 className="mb-2 text-xl font-semibold">{current.title}</h2>
<p className="text-sm leading-relaxed text-on-surface-variant">{current.description}</p>
</div>
)}
</div>
<div
className="mx-auto w-full max-w-md px-6 pb-6 sm:pb-8"
style={{ paddingBottom: 'calc(env(safe-area-inset-bottom) + 1.5rem)' }}
>
<Button
onClick={onFinalStep ? requestClose : () => setStep((s) => s + 1)}
className="w-full"
>
{onFinalStep ? 'Start exploring' : 'Next'}
</Button>
</div>
</div>
)
}
......@@ -4,15 +4,18 @@ import { describe, expect, it, vi } from 'vitest'
import { ProtectedRoute } from './ProtectedRoute'
import * as AuthContextModule from '../context/AuthContext'
function mockAuth(isAuthenticated: boolean) {
function mockAuth(isAuthenticated: boolean, overrides: Partial<ReturnType<typeof AuthContextModule.useAuth>> = {}) {
vi.spyOn(AuthContextModule, 'useAuth').mockReturnValue({
isAuthenticated,
role: null,
userId: null,
hasCompletedOnboarding: true,
isBusinessAdmin: false,
isSuperAdmin: false,
logout: vi.fn(),
completeLogin: vi.fn(),
completeOnboarding: vi.fn(),
...overrides,
})
}
......@@ -47,4 +50,23 @@ describe('ProtectedRoute', () => {
expect(screen.getByText('Login screen')).toBeInTheDocument()
expect(screen.queryByText('Library content')).not.toBeInTheDocument()
})
it('shows the onboarding overlay over the page when the account has not completed it', () => {
mockAuth(true, { hasCompletedOnboarding: false })
renderProtected()
expect(screen.getByText('Library content')).toBeInTheDocument()
expect(screen.getByRole('dialog', { name: 'Welcome to Stax' })).toBeInTheDocument()
})
it('does not show the onboarding overlay once the account has completed it', () => {
mockAuth(true, { hasCompletedOnboarding: true })
renderProtected()
expect(screen.queryByRole('dialog', { name: 'Welcome to Stax' })).not.toBeInTheDocument()
})
it('does not show the onboarding overlay while the flag is still loading (null)', () => {
mockAuth(true, { hasCompletedOnboarding: null })
renderProtected()
expect(screen.queryByRole('dialog', { name: 'Welcome to Stax' })).not.toBeInTheDocument()
})
})
import type { ReactNode } from 'react'
import { Navigate, useLocation } from 'react-router-dom'
import { useAuth } from '../context/AuthContext'
import { OnboardingOverlay } from './OnboardingOverlay'
export function ProtectedRoute({ children }: { children: ReactNode }) {
const { isAuthenticated } = useAuth()
const { isAuthenticated, hasCompletedOnboarding } = useAuth()
const location = useLocation()
if (!isAuthenticated) {
// Login.tsx reads location.state.from to send them back here once they're signed in,
// instead of dumping everyone at the same default page regardless of what they wanted.
return <Navigate to="/login" state={{ from: location }} replace />
}
return <>{children}</>
return (
<>
{children}
{/* Rendered alongside the real page, not instead of it, and gated on this file - every
protected route already passes through here, so a new user lands on the walkthrough
no matter which page they first reach, not just /home. Strictly false (not null,
which means "still loading") so it never flashes for an account that's already
onboarded while /auth/me is still resolving. */}
{hasCompletedOnboarding === false && <OnboardingOverlay />}
</>
)
}
......@@ -9,10 +9,12 @@ function mockAuth(overrides: Partial<ReturnType<typeof AuthContextModule.useAuth
isAuthenticated: true,
role: null,
userId: null,
hasCompletedOnboarding: true,
isBusinessAdmin: false,
isSuperAdmin: false,
logout: vi.fn(),
completeLogin: vi.fn(),
completeOnboarding: vi.fn(),
...overrides,
})
}
......
import type { LucideIcon } from 'lucide-react'
/** A labeled on/off switch row - shared by Settings.tsx (persisted account-level toggles) and
* OnboardingOverlay.tsx's privacy step (the exact same toggles, shown live during onboarding
* instead of just described). Extracted from Settings.tsx so both share one implementation. */
export function ToggleRow({
icon: Icon,
label,
description,
checked,
saving,
onToggle,
}: {
icon: LucideIcon
label: string
description: string
checked: boolean
saving: boolean
onToggle: () => void
}) {
return (
<div className="flex items-center gap-3 rounded-xl border border-outline-variant bg-surface-container p-4">
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-container-high text-on-surface-variant">
<Icon size={16} strokeWidth={1.75} />
</span>
<div className="min-w-0 flex-1">
<p className="text-sm font-medium text-on-surface">{label}</p>
<p className="text-xs text-on-surface-variant">{description}</p>
</div>
<button
role="switch"
aria-checked={checked}
aria-label={label}
disabled={saving}
onClick={onToggle}
className={`relative h-6 w-11 shrink-0 rounded-full transition-colors disabled:opacity-50 ${
checked ? 'bg-primary' : 'bg-surface-container-high'
}`}
>
<span
className={`absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow transition-transform ${
checked ? 'translate-x-5' : 'translate-x-0'
}`}
/>
</button>
</div>
)
}
......@@ -28,13 +28,14 @@ async function loadFreshAuthContext() {
}
function Probe({ useAuth }: { useAuth: typeof import('./AuthContext').useAuth }) {
const { isAuthenticated, role, isBusinessAdmin, isSuperAdmin } = useAuth()
const { isAuthenticated, role, isBusinessAdmin, isSuperAdmin, hasCompletedOnboarding } = useAuth()
return (
<div>
<span data-testid="auth-state">{isAuthenticated ? 'authenticated' : 'not-authenticated'}</span>
<span data-testid="role">{role ?? 'none'}</span>
<span data-testid="is-business-admin">{String(isBusinessAdmin)}</span>
<span data-testid="is-super-admin">{String(isSuperAdmin)}</span>
<span data-testid="has-completed-onboarding">{String(hasCompletedOnboarding)}</span>
</div>
)
}
......@@ -69,7 +70,7 @@ describe('AuthProvider bootstrap from stored tokens', () => {
it('is authenticated immediately when a token is already stored (e.g. a prior real login)', async () => {
setTokens('stored-access-token', 'stored-refresh-token')
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', privacy: { share_location_enabled: false, allow_direct_messages: false } } })
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } } })
render(
<AuthProvider>
......@@ -87,7 +88,7 @@ describe('AuthProvider bootstrap from stored tokens', () => {
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'dev-test-user', role: 'super_admin', privacy: { share_location_enabled: false, allow_direct_messages: false } },
user: { id: 1, username: 'dev-test-user', role: 'super_admin', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
render(
......@@ -107,7 +108,7 @@ describe('AuthProvider bootstrap from stored tokens', () => {
it('leaves role null (not "user") until the fetch resolves, and plain "user" role gates out admin UI', async () => {
setTokens('stored-access-token', 'stored-refresh-token')
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', privacy: { share_location_enabled: false, allow_direct_messages: false } } })
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } } })
render(
<AuthProvider>
......@@ -203,7 +204,7 @@ describe('completeLogin', () => {
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'real-user', role: 'user', privacy: { share_location_enabled: false, allow_direct_messages: false } },
user: { id: 1, username: 'real-user', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
function LoginButton() {
......@@ -233,6 +234,89 @@ describe('completeLogin', () => {
})
})
describe('completeOnboarding', () => {
afterEach(() => {
vi.unstubAllEnvs()
clearTokens()
vi.restoreAllMocks()
})
it('fetches and exposes hasCompletedOnboarding from /auth/me', async () => {
setTokens('stored-access-token', 'stored-refresh-token')
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
render(
<AuthProvider>
<Probe useAuth={useAuth} />
</AuthProvider>,
)
await waitFor(() => expect(screen.getByTestId('has-completed-onboarding')).toHaveTextContent('false'))
})
it('optimistically flips the local flag immediately and fires the real API call alongside', async () => {
setTokens('stored-access-token', 'stored-refresh-token')
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
const completeOnboardingSpy = vi.spyOn(authApi, 'completeOnboarding').mockResolvedValue({ status: 'success', has_completed_onboarding: true })
function FinishButton() {
const { completeOnboarding } = useAuth()
return <button onClick={() => completeOnboarding()}>Finish onboarding</button>
}
render(
<AuthProvider>
<FinishButton />
<Probe useAuth={useAuth} />
</AuthProvider>,
)
await waitFor(() => expect(screen.getByTestId('has-completed-onboarding')).toHaveTextContent('false'))
screen.getByText('Finish onboarding').click()
// setHasCompletedOnboarding(true) runs before the (unawaited, fire-and-forget) API call in
// the implementation, so the flip never actually waits on the network round trip - waitFor
// here is just about jsdom/React's own event-flush timing, not about the mocked promise.
await waitFor(() => expect(screen.getByTestId('has-completed-onboarding')).toHaveTextContent('true'))
expect(completeOnboardingSpy).toHaveBeenCalled()
})
it('never throws or surfaces an error if the API call fails - the local state has already moved on', async () => {
setTokens('stored-access-token', 'stored-refresh-token')
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'x', role: 'user', has_completed_onboarding: false, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
vi.spyOn(authApi, 'completeOnboarding').mockRejectedValue(new Error('network blip'))
function FinishButton() {
const { completeOnboarding } = useAuth()
return <button onClick={() => completeOnboarding()}>Finish onboarding</button>
}
render(
<AuthProvider>
<FinishButton />
<Probe useAuth={useAuth} />
</AuthProvider>,
)
await waitFor(() => expect(screen.getByTestId('has-completed-onboarding')).toHaveTextContent('false'))
expect(() => screen.getByText('Finish onboarding').click()).not.toThrow()
await waitFor(() => expect(screen.getByTestId('has-completed-onboarding')).toHaveTextContent('true'))
})
})
describe('logout', () => {
afterEach(() => {
vi.unstubAllEnvs()
......@@ -248,7 +332,7 @@ describe('logout', () => {
const { AuthProvider, useAuth, authApi } = await loadFreshAuthContext()
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'x', role: 'super_admin', privacy: { share_location_enabled: false, allow_direct_messages: false } },
user: { id: 1, username: 'x', role: 'super_admin', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
vi.spyOn(authApi, 'logout').mockResolvedValue({ status: 'success' })
......
......@@ -12,12 +12,19 @@ interface AuthContextValue {
/** Same lazy-null-until-/auth/me-resolves shape as `role` - used by the Home feed to tell
* "I already own this song" (play directly) from "someone else's" (claim first). */
userId: number | null
/** Same lazy-null-until-/auth/me-resolves shape as `role` - ProtectedRoute shows
* OnboardingOverlay only once this is strictly `false` (not `null`), so a momentarily-null
* value during that fetch never flashes the overlay for someone who's already onboarded. */
hasCompletedOnboarding: boolean | null
isBusinessAdmin: boolean
isSuperAdmin: boolean
logout: () => Promise<void>
/** Called by Login.tsx once /auth/login (or /auth/register) returns a real token pair -
* stores them and flips isAuthenticated. */
completeLogin: (tokens: TokenPair) => void
/** Called by OnboardingOverlay on Skip/Finish - optimistically flips the local flag (so the
* overlay closes immediately, not after a round trip) and fires the real API call alongside. */
completeOnboarding: () => void
}
const AuthContext = createContext<AuthContextValue | null>(null)
......@@ -40,11 +47,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const [isAuthenticated, setIsAuthenticated] = useState(() => !!getAccessToken())
const [role, setRole] = useState<UserRole | null>(null)
const [userId, setUserId] = useState<number | null>(null)
const [hasCompletedOnboarding, setHasCompletedOnboarding] = useState<boolean | null>(null)
useEffect(() => {
if (!isAuthenticated) {
setRole(null)
setUserId(null)
setHasCompletedOnboarding(null)
return
}
let cancelled = false
......@@ -54,6 +63,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
if (!cancelled) {
setRole(res.user.role)
setUserId(res.user.id)
setHasCompletedOnboarding(res.user.has_completed_onboarding)
}
})
.catch((err) => {
......@@ -96,11 +106,32 @@ export function AuthProvider({ children }: { children: ReactNode }) {
setIsAuthenticated(true)
}
function completeOnboarding() {
setHasCompletedOnboarding(true)
authApi.completeOnboarding().catch(() => {
// Best-effort: the overlay has already closed locally, and the endpoint is idempotent,
// so a transient failure here just means it's retried (as true->true, a no-op) the next
// time this fires - never worth surfacing an error for or blocking the close on.
})
}
const isBusinessAdmin = role === 'business_admin' || role === 'super_admin'
const isSuperAdmin = role === 'super_admin'
return (
<AuthContext.Provider value={{ isAuthenticated, role, userId, isBusinessAdmin, isSuperAdmin, logout, completeLogin }}>
<AuthContext.Provider
value={{
isAuthenticated,
role,
userId,
hasCompletedOnboarding,
isBusinessAdmin,
isSuperAdmin,
logout,
completeLogin,
completeOnboarding,
}}
>
{children}
</AuthContext.Provider>
)
......
......@@ -90,7 +90,7 @@ describe('Home', () => {
setTokens('test-access', 'test-refresh')
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: ME_ID, username: 'me', role: 'user', privacy: { share_location_enabled: false, allow_direct_messages: false } },
user: { id: ME_ID, username: 'me', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
})
......
......@@ -45,7 +45,7 @@ describe('Login', () => {
refresh_token: 'real-refresh',
token_type: 'bearer',
})
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'alice', role: 'user', privacy: { share_location_enabled: false, allow_direct_messages: false } } })
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 1, username: 'alice', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } } })
renderLogin()
await userEvent.type(screen.getByLabelText('Username'), 'alice')
......@@ -76,7 +76,7 @@ describe('Login', () => {
})
vi.spyOn(authApi, 'getMe').mockResolvedValue({
status: 'success',
user: { id: 1, username: 'alice', role: 'business_admin', privacy: { share_location_enabled: false, allow_direct_messages: false } },
user: { id: 1, username: 'alice', role: 'business_admin', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } },
})
renderLogin([{ pathname: '/login', state: { from: { pathname: '/business' } } }])
......@@ -93,7 +93,7 @@ describe('Login', () => {
refresh_token: 'real-refresh',
token_type: 'bearer',
})
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 2, username: 'newuser', role: 'user', privacy: { share_location_enabled: false, allow_direct_messages: false } } })
vi.spyOn(authApi, 'getMe').mockResolvedValue({ status: 'success', user: { id: 2, username: 'newuser', role: 'user', has_completed_onboarding: true, privacy: { share_location_enabled: false, allow_direct_messages: false } } })
renderLogin()
await userEvent.click(screen.getByText("Don't have an account? Register"))
......
......@@ -55,9 +55,14 @@ export function Login() {
<div className="mb-8 flex flex-col items-center gap-2 text-center">
<Headphones size={28} strokeWidth={2} className="text-primary" />
<h1 className="text-xl font-semibold tracking-tight">Stax</h1>
{/* Same copy as the PWA manifest's own description (vite.config.ts) - this is the
one place a brand-new visitor reads it before anything else, so it carries the
"welcome" framing the rest of onboarding (OnboardingOverlay, right after this)
continues once they're signed in. */}
<p className="text-sm text-on-surface-variant">
{mode === 'login' ? 'Sign in to your account.' : 'Create an account.'}
Discover, tag, and remix music from your own uploads and Telegram chats.
</p>
<p className="text-xs text-outline">{mode === 'login' ? 'Sign in to your account.' : 'Create an account.'}</p>
</div>
<form onSubmit={handleSubmit} className="space-y-3">
......
......@@ -46,6 +46,7 @@ const BACKEND_DONE: DoneGroup[] = [
'Telegram phone/code account-linking (/auth/telegram/*), attaches to the already-authenticated caller (fixed 2026-08-18 - used to silently create a disconnected identity instead); handles accounts with two-step verification via a 412 + /auth/telegram/password step',
'Rate limited: login (10 attempts/account/15min, 100/source/hr), Telegram request_code (5/phone/10min, 20/IP/hr) - independent of each other despite sharing a table',
'Privacy settings (2026-09-13): two opt-in booleans on UserProfile (share_location_enabled, allow_direct_messages - both default False), surfaced on GET /auth/me and updated via PATCH /auth/privacy. UserProfile existed before this but had no reader/writer anywhere; _get_or_create_profile treats a missing row as "opted out," not an error, since that\'s the actual shape of every account that existed before these columns did.',
'User.has_completed_onboarding (2026-10-08), the signal behind the new first-run walkthrough below - register and login previously returned byte-identical responses, so nothing could tell "brand new account" from "used this for months." server_default=true backfills every existing/historical row (and anything inserted outside /auth/register, including test fixtures) as already-onboarded; only the register handler explicitly passes False for a genuinely new account. New POST /auth/onboarding/complete (idempotent) flips it; GET /auth/me returns the current value.',
],
},
{
......@@ -195,6 +196,7 @@ const FRONTEND_DONE: DoneGroup[] = [
'Telegram linking page: phone + code (+ two-step verification password if the account has it enabled), then browse linked chats and save any found song to the library (tags via /music/tag)',
'Per-song 30-second preview button in the chat music list, playable through the shared player before deciding whether to save (2026-08-23)',
'Multi-select save in the chat music list (2026-09-01): each not-yet-saved row gets a checkbox; selecting any shows a sticky "Save N selected" bar. Still calls /music/tag once per song sequentially - there\'s no batch endpoint, and Shazam/AcoustID lookups are heavy enough per call that racing them wouldn\'t help - but it\'s one tap instead of one per song',
'First-run onboarding walkthrough (2026-10-08), closing the one gap left on the backlog since the very first redesign: a brand-new account used to land straight on Home with zero explanation. New OnboardingOverlay, shown once (gated on the account\'s has_completed_onboarding flag, checked in ProtectedRoute.tsx - so it reaches a new user no matter which protected page they land on first, not just /home) - six full-screen steps covering Upload, Telegram linking, Discovery, Social, and Soundmarks, each with a small hand-authored Lottie animation (lottie-react\'s SVG-only/no-expressions LottieLight build - the full build probes a canvas 2D context at import time, which jsdom doesn\'t implement, so tests needed a getContext stub too), then a final privacy step reusing Settings\' own ToggleRow component (extracted into ui/) wired to the real PATCH /auth/privacy - choices made during onboarding actually take effect, not a static preview. "Skip" and the final "Start exploring" both call the new completeOnboarding() (optimistic local flip + fire-and-forget API call) so it never reappears, confirmed against a real fresh login (not just a reload) on another session. Login.tsx also gained a one-line welcome tagline (the PWA manifest\'s own description) above the sign-in form, so onboarding\'s "welcome" framing starts before the account even exists.',
],
},
{
......@@ -280,11 +282,6 @@ const FRONTEND_TODO: WorkItem[] = [
status: 'blocked',
note: "Verified 2026-08-31: the deployed preview server's cert is self-signed (issuer=subject=CN=example.org, from @vitejs/plugin-basic-ssl) bound to a bare IP - Chrome/Android are stricter than a manually-trusted secure context and won't reliably fire beforeinstallprompt or show the omnibox icon over it, which is what made install feel broken even with a correct manifest+service worker. Same blocker as the reverse-proxy item below: needs a real domain + a browser-trusted cert (Let's Encrypt) before this can work end to end, not a frontend fix.",
},
{
item: 'New-user onboarding flow',
status: 'needs-design',
note: "Noted 2026-10-06, not started - there's currently no first-run walkthrough at all; a brand-new account lands straight on Home/Library with no explanation of what Stax does or how to get music into it (Upload vs. Telegram linking vs. Discovery).",
},
{
item: 'Delete buttons + confirm dialogs for playlists and playlist tracks',
status: 'ready',
......
......@@ -31,6 +31,7 @@ describe('Settings', () => {
id: 1,
username: 'me',
role: 'user',
has_completed_onboarding: true,
privacy: { share_location_enabled: false, allow_direct_messages: false },
},
})
......
import { useEffect, useState } from 'react'
import { MapPin, MessageCircle, Monitor, Moon, Sun, type LucideIcon } from 'lucide-react'
import { Layout } from '../components/Layout'
import { ToggleRow } from '../components/ui/ToggleRow'
import { ApiError } from '../api/client'
import { getMe, updatePrivacy, type PrivacySettings } from '../api/auth'
import { useTheme, type ThemePreference } from '../context/ThemeContext'
......@@ -42,50 +43,6 @@ function AppearanceRow() {
)
}
function ToggleRow({
icon: Icon,
label,
description,
checked,
saving,
onToggle,
}: {
icon: LucideIcon
label: string
description: string
checked: boolean
saving: boolean
onToggle: () => void
}) {
return (
<div className="flex items-center gap-3 rounded-xl border border-outline-variant bg-surface-container p-4">
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-container-high text-on-surface-variant">
<Icon size={16} strokeWidth={1.75} />
</span>
<div className="min-w-0 flex-1">
<p className="text-sm font-medium text-on-surface">{label}</p>
<p className="text-xs text-on-surface-variant">{description}</p>
</div>
<button
role="switch"
aria-checked={checked}
aria-label={label}
disabled={saving}
onClick={onToggle}
className={`relative h-6 w-11 shrink-0 rounded-full transition-colors disabled:opacity-50 ${
checked ? 'bg-primary' : 'bg-surface-container-high'
}`}
>
<span
className={`absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow transition-transform ${
checked ? 'translate-x-5' : 'translate-x-0'
}`}
/>
</button>
</div>
)
}
/** Both privacy toggles are account-level, not "social content," so they get their own minimal
* page rather than living inside Social.tsx. Both default off (opt-in) - see PrivacySettings. */
export function Settings() {
......
......@@ -21,6 +21,33 @@ window.Element.prototype.setPointerCapture = vi.fn()
window.Element.prototype.releasePointerCapture = vi.fn()
window.Element.prototype.hasPointerCapture = vi.fn(() => false)
// jsdom has no real <canvas> rendering - lottie-web's player probes a canvas 2D context at
// import time (not just when actually rendering an animation) to feature-detect, and throws
// immediately on module load without this, before OnboardingOverlay's test even gets to render
// anything. A minimal no-op context is enough; nothing here asserts on actual pixels.
window.HTMLCanvasElement.prototype.getContext = vi.fn(() => ({
fillRect: vi.fn(),
clearRect: vi.fn(),
getImageData: vi.fn(() => ({ data: [] })),
putImageData: vi.fn(),
createImageData: vi.fn(() => []),
setTransform: vi.fn(),
drawImage: vi.fn(),
save: vi.fn(),
restore: vi.fn(),
beginPath: vi.fn(),
moveTo: vi.fn(),
lineTo: vi.fn(),
closePath: vi.fn(),
stroke: vi.fn(),
fill: vi.fn(),
translate: vi.fn(),
scale: vi.fn(),
rotate: vi.fn(),
arc: vi.fn(),
measureText: vi.fn(() => ({ width: 0 })),
})) as unknown as typeof window.HTMLCanvasElement.prototype.getContext
// jsdom doesn't implement matchMedia at all - useInstallPrompt's isStandalone() check
// (display-mode: standalone) throws "not a function" without this. Always reports no match,
// which is correct for tests: nothing is ever actually running in standalone display mode.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment