-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOnboardingModal.tsx
More file actions
1355 lines (1293 loc) Β· 55.7 KB
/
Copy pathOnboardingModal.tsx
File metadata and controls
1355 lines (1293 loc) Β· 55.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { AnimatePresence, motion } from "framer-motion";
import {
AlertCircle,
AudioLines,
Check,
Database,
FileText,
FileDown,
CheckCircle2,
ChevronLeft,
ChevronRight,
Disc3,
Eye,
EyeOff,
ExternalLink,
FolderOpen,
Globe,
Layers,
Loader2,
Mic2,
Music,
Palette,
Play,
SkipForward,
Sparkles,
UserRound,
X,
} from "lucide-react";
import { openUrl } from "@tauri-apps/plugin-opener";
import { useModalA11y } from "../../hooks/useModalA11y";
import { useLibrary } from "../../hooks/useLibrary";
import { useProfile } from "../../hooks/useProfile";
import { useTheme } from "../../hooks/useTheme";
import { useSkin } from "../../hooks/useSkin";
import { THEME_PRESETS } from "../../lib/themes";
import { SKIN_PRESETS } from "../../lib/skins";
import { pickFolder } from "../../lib/tauri/dialog";
import type { ScanSummary } from "../../lib/tauri/library";
import {
SUPPORTED_LANGUAGES,
normalizeSupportedLanguageCode,
} from "../../i18n";
import { getAutoAnalyze, setAutoAnalyze } from "../../lib/tauri/analysis";
import {
getLyricsDefaultDestination,
setLyricsDefaultDestination,
type LyricsDestination,
} from "../../lib/tauri/lyrics";
import {
getLastfmApiKey,
getLastfmApiSecret,
lastfmGetStatus,
lastfmLogin,
setLastfmApiKey,
setLastfmApiSecret,
type LastfmStatus,
} from "../../lib/tauri/integration";
interface OnboardingModalProps {
/** Closes the wizard. Persists `onboarding.dismissed=true` on the
* parent side so the modal doesn't reappear next launch. */
onSkip: () => void;
}
type StepId =
| "welcome"
| "language"
| "profile"
| "localOnly"
| "appearance"
| "lyrics"
| "folder"
| "lastfm"
| "scan"
| "done";
const STEPS: ReadonlyArray<StepId> = [
"welcome",
"language",
"profile",
"localOnly",
"appearance",
"lyrics",
"folder",
"lastfm",
"scan",
"done",
];
/**
* Name the backend hardcodes for the auto-bootstrapped first profile
* (see [`state.rs::create_default_profile`](src-tauri/src/state.rs)).
* Not localised β a user-created profile from the "New profile" modal
* always carries a user-supplied name, so anything other than this
* literal means we already have the user's intent and the rename
* step would be redundant.
*/
const AUTO_BOOTSTRAP_PROFILE_NAME = "Default";
const STEP_ICONS: Record<StepId, typeof Music> = {
welcome: Music,
language: Globe,
profile: UserRound,
localOnly: AlertCircle,
appearance: Palette,
lyrics: Mic2,
folder: FolderOpen,
lastfm: AudioLines,
scan: Disc3,
done: Sparkles,
};
/**
* Reads the browser/system language and tells the caller whether
* i18next ended up on a "real" detected language (matching the user's
* locale) or fell back to English because the OS language isn't
* supported. The UI uses this to show a green "Detected" badge or a
* yellow "we couldn't match your language" fallback hint on the
* language step.
*/
function detectInitialLanguage(): { code: string; fallback: boolean } {
const raw =
(typeof navigator !== "undefined"
? (navigator.language ?? navigator.languages?.[0])
: null) ?? "en";
const normalized = normalizeSupportedLanguageCode(raw);
// normalizeSupportedLanguageCode returns the first supported code
// ("en") when the system locale can't be matched. If we end up on
// "en" but the user's raw locale doesn't actually start with "en",
// that's a genuine fallback β surface it to the user.
const isFallback = normalized === "en" && !raw.toLowerCase().startsWith("en");
return { code: normalized, fallback: isFallback };
}
type ScanState =
| { kind: "idle" }
| { kind: "running"; path: string }
| { kind: "done"; summary: ScanSummary; path: string }
| { kind: "error"; message: string };
/**
* Multi-step first-run wizard. Inspired by Lokal's onboarding flow,
* adapted to WaveFlow's feature set:
*
* 1. welcome β branding + skip-or-start
* 2. language β confirm the auto-detected UI language with a green
* "Detected" badge, or surface the fallback when the
* user's system locale isn't one of our 17 supported
* languages (e.g. Egyptian Arabic resolves to "ar",
* Greek falls back to "en" with a yellow hint)
* 3. localOnly β set expectation that WaveFlow is not a streaming service
* 4. folder β pick music folder + auto-analyze toggle
* 5. lastfm β recommended scrobbling/bio integration (the user asked
* for this to be highlighted)
* 6. scan β confirm + kick off the initial library scan
* 7. done β celebrate + start listening
*
* Discord Rich Presence is intentionally NOT a wizard step. It defaults
* to ON in the backend (`app_setting['integrations.discord_rpc'] = true`)
* so new users get the activity card by default; opt-out lives in
* Settings β Integrations.
*
* Shown by `AppLayout` once per profile (latched via
* `onboarding.dismissed` profile setting). The wizard never persists
* its own progress: closing mid-flow means the user starts from
* step 1 next time, which is the desired UX for a 30-second flow.
*/
export function OnboardingModal({ onSkip }: OnboardingModalProps) {
const { t, i18n } = useTranslation();
const { libraries, createLibrary, importFolder } = useLibrary();
const { activeProfile, renameProfile } = useProfile();
const { theme, setThemeId } = useTheme();
const { skin, setSkinId } = useSkin();
// Decide ONCE at mount whether to include the `profile` rename
// step, then never recompute it. The parent gates this modal on a
// resolved active profile (see [`ui.md`](../../docs/features/ui.md)),
// so the lazy initializer always has the truthful value.
//
// Recomputing this on every `activeProfile` change would shrink
// the steps array under our feet right after `renameProfile`
// optimistically updates the context β `stepIndex` would still
// point to the old `profile` position (now occupied by `localOnly`),
// and the subsequent `goNext()` would skip `localOnly` entirely.
const [includeProfileStep] = useState(
() => activeProfile?.name === AUTO_BOOTSTRAP_PROFILE_NAME,
);
const steps = useMemo(
() => (includeProfileStep ? STEPS : STEPS.filter((s) => s !== "profile")),
[includeProfileStep],
);
const [stepIndex, setStepIndex] = useState(0);
const stepId = steps[stepIndex];
// Reset the body scroll on every step transition. The
// `AnimatePresence` swap re-renders the content but the surrounding
// scroll container is reused, so a user who scrolled to fill the
// tall Last.fm step would land mid-page on the next step otherwise.
const scrollBodyRef = useRef<HTMLDivElement>(null);
useEffect(() => {
scrollBodyRef.current?.scrollTo({ top: 0, behavior: "auto" });
}, [stepId]);
// Profile-name step state. Seeded from the active profile so the
// input reflects whatever name the auto-bootstrapper picked
// ("Default" on a fresh install).
const [profileName, setProfileName] = useState("");
const [profileBusy, setProfileBusy] = useState(false);
const [profileError, setProfileError] = useState<string | null>(null);
useEffect(() => {
if (activeProfile && profileName === "") {
// eslint-disable-next-line react-hooks/set-state-in-effect
setProfileName(activeProfile.name);
}
}, [activeProfile, profileName]);
// Folder + scan state shared across steps.
const [musicFolder, setMusicFolder] = useState<string | null>(null);
const [scanState, setScanState] = useState<ScanState>({ kind: "idle" });
// Quick settings on the folder step. Hydrated from the backend at
// mount so toggles already reflect any preference set elsewhere
// (rare on first run, but the wizard CAN be reopened in dev).
const [autoAnalyze, setAutoAnalyzeState] = useState(true);
// Issue #201 β pre-flight the lyrics-write destination so users who
// want to keep their tag block clean don't have to discover the
// Settings card after first save. Initial render uses `tag` so the
// grid renders before the fetch lands; the effect below pulls the
// app-wide stored value, and a click here writes the setting
// immediately so a wizard cancel still persists the choice.
const [lyricsDestination, setLyricsDestinationState] =
useState<LyricsDestination>("tag");
const [lyricsBusy, setLyricsBusy] = useState(false);
// True once the user has clicked a tile in the lyrics step. Lets
// the initial fetch's then-handler defer to a manual pick that
// landed first β same race the LyricsEditorModal hits, only here
// the modal isn't reopened so we don't need to reset between
// steps.
const lyricsUserTouchedRef = useRef(false);
// Last.fm form state. The backend wants api key + secret + username
// + password to mint a session via auth.getMobileSession; we mirror
// the SettingsView shape so this step is essentially a compact
// version of the Integrations panel.
const [lastfmKey, setLastfmKey] = useState("");
const [lastfmSecret, setLastfmSecret] = useState("");
const [lastfmSecretVisible, setLastfmSecretVisible] = useState(false);
const [lastfmUsername, setLastfmUsername] = useState("");
const [lastfmPassword, setLastfmPassword] = useState("");
const [lastfmPasswordVisible, setLastfmPasswordVisible] = useState(false);
const [lastfmStatus, setLastfmStatus] = useState<LastfmStatus | null>(null);
const [lastfmBusy, setLastfmBusy] = useState(false);
const [lastfmError, setLastfmError] = useState<string | null>(null);
// Initial language detection β frozen at mount so the "Detected"
// badge keeps pointing at the user's system locale even after they
// manually switch language inside the step. The active selection is
// read live from i18n.resolvedLanguage further down.
const initialDetection = useMemo(() => detectInitialLanguage(), []);
const activeLanguageCode = normalizeSupportedLanguageCode(
i18n.resolvedLanguage ?? i18n.language,
);
// Modal a11y wiring. The wizard is "open" for its entire lifetime
// (the parent unmounts it when the user clicks Skip / Start), so
// Escape funnels to onSkip and we always trap focus.
const dialogRef = useModalA11y<HTMLDivElement>(true, onSkip);
// Hydrate stored preferences once on mount. Failures are swallowed
// because they only affect the initial toggle state β saving a
// toggle later still works either way.
useEffect(() => {
let cancelled = false;
void (async () => {
try {
const value = await getAutoAnalyze();
if (!cancelled) setAutoAnalyzeState(value);
} catch (err) {
console.error("[Onboarding] read auto_analyze failed", err);
}
try {
const dest = await getLyricsDefaultDestination();
if (cancelled || lyricsUserTouchedRef.current) return;
setLyricsDestinationState(dest);
} catch (err) {
console.error(
"[Onboarding] read lyrics default destination failed",
err,
);
}
try {
const key = await getLastfmApiKey();
if (!cancelled && key) setLastfmKey(key);
} catch (err) {
console.error("[Onboarding] read lastfm api key failed", err);
}
try {
const secret = await getLastfmApiSecret();
if (!cancelled && secret) setLastfmSecret(secret);
} catch (err) {
console.error("[Onboarding] read lastfm api secret failed", err);
}
try {
const status = await lastfmGetStatus();
if (!cancelled) setLastfmStatus(status);
} catch (err) {
console.error("[Onboarding] read lastfm status failed", err);
}
})();
return () => {
cancelled = true;
};
}, []);
const Icon = STEP_ICONS[stepId];
const goNext = () => setStepIndex((i) => Math.min(steps.length - 1, i + 1));
const goBack = () => setStepIndex((i) => Math.max(0, i - 1));
// === Language step actions ==========================================
const handlePickLanguage = (code: string) => {
i18n.changeLanguage(code).catch((err) => {
console.error("[Onboarding] changeLanguage failed", err);
});
};
// === Profile step actions ===========================================
const handleProfileContinue = async () => {
const trimmed = profileName.trim();
if (!trimmed) {
setProfileError(t("onboarding.profile.required"));
return;
}
// The modal is supposed to open only once the profile is resolved
// (see ui.md), but guard against the race anyway β without this we
// would silently drop the user's name and advance.
if (!activeProfile) {
setProfileError(t("onboarding.profile.unavailable"));
return;
}
// Skip the backend round-trip when the name hasn't actually
// changed (user accepted the seeded default).
if (trimmed !== activeProfile.name) {
setProfileBusy(true);
setProfileError(null);
try {
await renameProfile(activeProfile.id, trimmed);
} catch (err) {
console.error("[Onboarding] rename profile failed", err);
setProfileError(err instanceof Error ? err.message : String(err));
setProfileBusy(false);
return;
}
setProfileBusy(false);
}
goNext();
};
// === Folder step actions ============================================
const handlePickFolder = async () => {
let path: string | null;
try {
path = await pickFolder();
} catch (err) {
console.error("[Onboarding] pickFolder failed", err);
return;
}
if (!path) return;
setMusicFolder(path);
};
const handleToggleAutoAnalyze = async (next: boolean) => {
setAutoAnalyzeState(next);
try {
await setAutoAnalyze(next);
} catch (err) {
console.error("[Onboarding] set auto_analyze failed", err);
// Roll back so the toggle reflects truth.
setAutoAnalyzeState(!next);
}
};
const handlePickLyricsDestination = async (next: LyricsDestination) => {
if (next === lyricsDestination || lyricsBusy) return;
lyricsUserTouchedRef.current = true;
const previous = lyricsDestination;
setLyricsBusy(true);
setLyricsDestinationState(next);
try {
await setLyricsDefaultDestination(next);
} catch (err) {
console.error("[Onboarding] set lyrics default destination failed", err);
// Roll back so the grid reflects what's actually persisted.
setLyricsDestinationState(previous);
} finally {
setLyricsBusy(false);
}
};
// === Last.fm step actions ===========================================
const handleOpenLastfmKeyPage = async () => {
try {
await openUrl("https://www.last.fm/api/account/create");
} catch (err) {
console.error("[Onboarding] open lastfm key page failed", err);
}
};
const handleLastfmLogin = async () => {
const trimmedKey = lastfmKey.trim();
const trimmedSecret = lastfmSecret.trim();
const trimmedUser = lastfmUsername.trim();
if (!trimmedKey || !trimmedSecret || !trimmedUser || !lastfmPassword) {
setLastfmError(t("onboarding.lastfm.missingFields"));
return;
}
setLastfmBusy(true);
setLastfmError(null);
try {
// Persist the key + secret first so the backend has them
// available when it composes the signed login request.
await setLastfmApiKey(trimmedKey);
await setLastfmApiSecret(trimmedSecret);
const status = await lastfmLogin(trimmedUser, lastfmPassword);
setLastfmStatus(status);
setLastfmPassword("");
} catch (err) {
console.error("[Onboarding] lastfm login failed", err);
setLastfmError(err instanceof Error ? err.message : String(err));
} finally {
setLastfmBusy(false);
}
};
// === Scan step actions ==============================================
const handleScanNow = async () => {
if (!musicFolder) return;
setScanState({ kind: "running", path: musicFolder });
try {
let libraryId = libraries[0]?.id;
if (libraryId == null) {
const created = await createLibrary({
name: t("onboarding.defaultLibraryName"),
});
libraryId = created.id;
}
const summary = await importFolder(libraryId, musicFolder);
setScanState({ kind: "done", summary, path: musicFolder });
goNext();
} catch (err) {
setScanState({
kind: "error",
message: err instanceof Error ? err.message : String(err),
});
}
};
// Progress bar segments β one per step, filled up to (and including)
// the active step. We never animate beyond the current index so
// back-navigation visually dims the trailing bars.
const progress = useMemo(
() => steps.map((_, i) => i <= stepIndex),
[steps, stepIndex],
);
const isLastStep = stepIndex === steps.length - 1;
const showCloseButton = stepIndex === 0;
return (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.18, ease: "easeOut" }}
className="fixed inset-0 z-100 bg-black/80 backdrop-blur-md flex items-center justify-center p-4"
>
<motion.div
ref={dialogRef}
role="dialog"
aria-modal="true"
aria-labelledby="onboarding-title"
initial={{ opacity: 0, scale: 0.95, y: 8 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
transition={{ type: "spring", stiffness: 380, damping: 28, mass: 0.6 }}
// Cap the modal at the viewport height (minus the parent's 1rem
// padding on each side = 2rem) and lay out as a column with a
// scrollable middle. Without this cap the wizard's tallest step
// (Last.fm with 4 inputs + button) pushed both the progress bar
// and the action bar off-screen on 1080p displays (#107).
className="relative w-full max-w-lg rounded-3xl bg-white dark:bg-zinc-900 shadow-2xl border border-zinc-200 dark:border-zinc-800 overflow-hidden flex flex-col max-h-[calc(100vh-2rem)]"
>
{/* Close button β only available on the very first step so the
user can't half-onboard themselves into a broken state. */}
{showCloseButton && (
<button
type="button"
onClick={onSkip}
aria-label={t("common.close")}
className="absolute top-4 right-4 z-10 p-2 rounded-full text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors"
>
<X size={18} />
</button>
)}
{/* Progress bar β sticky header inside the flex column so it
stays visible while the body scrolls. */}
<div className="flex items-center gap-1.5 p-4 pb-0 shrink-0">
{progress.map((isFilled, i) => (
<div
key={i}
className={`h-1 flex-1 rounded-full transition-colors duration-300 ${
isFilled ? "bg-emerald-500" : "bg-zinc-200 dark:bg-zinc-800"
}`}
/>
))}
</div>
<div
ref={scrollBodyRef}
className="px-8 pt-6 overflow-y-auto flex-1 min-h-0"
>
<AnimatePresence mode="wait">
<motion.div
key={stepId}
initial={{ opacity: 0, x: 16 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -16 }}
transition={{ duration: 0.2, ease: "easeOut" }}
>
<div className="flex justify-center mb-5">
<div className="p-3.5 bg-emerald-500/10 rounded-2xl">
<Icon size={32} className="text-emerald-500" />
</div>
</div>
<h2
id="onboarding-title"
className="text-center text-2xl font-bold text-zinc-900 dark:text-white"
>
{t(`onboarding.${stepId}.title`)}
</h2>
<p className="mt-3 text-center text-sm text-zinc-600 dark:text-zinc-400 leading-relaxed">
{t(`onboarding.${stepId}.description`)}
</p>
{/* === Step bodies ====================================== */}
{stepId === "language" && (
<div className="mt-6 space-y-4">
{initialDetection.fallback ? (
<div className="rounded-xl border border-amber-500/30 bg-amber-500/10 p-3 flex items-start gap-3">
<AlertCircle
size={16}
className="text-amber-500 shrink-0 mt-0.5"
aria-hidden="true"
/>
<p className="text-xs text-amber-700 dark:text-amber-200/90 leading-relaxed">
{t("onboarding.language.fallback")}
</p>
</div>
) : null}
<div className="grid grid-cols-2 sm:grid-cols-3 gap-2 max-h-[280px] overflow-y-auto pr-1">
{SUPPORTED_LANGUAGES.map((lang) => {
const isActive = lang.code === activeLanguageCode;
const isDetected =
!initialDetection.fallback &&
lang.code === initialDetection.code;
return (
<button
key={lang.code}
type="button"
onClick={() => handlePickLanguage(lang.code)}
aria-pressed={isActive}
className={`relative px-3 py-2.5 rounded-xl border text-sm text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500 ${
isActive
? "border-emerald-500 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"
: "border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 text-zinc-700 dark:text-zinc-300 hover:border-zinc-300 dark:hover:border-zinc-600"
}`}
>
<span className="block truncate font-medium">
{lang.nativeLabel}
</span>
{isDetected && (
<span
className="absolute top-1.5 right-1.5 inline-flex items-center justify-center w-4 h-4 rounded-full bg-emerald-500 text-white"
aria-label={t("onboarding.language.detected")}
title={t("onboarding.language.detected")}
>
<CheckCircle2 size={12} strokeWidth={2.5} />
</span>
)}
</button>
);
})}
</div>
</div>
)}
{stepId === "profile" && (
<div className="mt-6 space-y-3">
<Input
label={t("onboarding.profile.nameLabel")}
value={profileName}
onChange={(next) => {
setProfileName(next);
if (profileError) setProfileError(null);
}}
placeholder={t("onboarding.profile.namePlaceholder")}
/>
<p className="text-xs text-zinc-500 dark:text-zinc-400 leading-relaxed">
{t("onboarding.profile.hint")}
</p>
{profileError && (
<p className="text-xs text-rose-500" role="alert">
{profileError}
</p>
)}
</div>
)}
{stepId === "localOnly" && (
<div className="mt-6 rounded-xl border border-amber-500/30 bg-amber-500/10 p-4">
<div className="flex items-start gap-3">
<AlertCircle
size={18}
className="text-amber-500 shrink-0 mt-0.5"
aria-hidden="true"
/>
<div className="space-y-2 text-xs text-amber-700 dark:text-amber-200/90 leading-relaxed">
<p className="font-semibold">
{t("onboarding.localOnly.calloutTitle")}
</p>
<ul className="list-disc list-inside space-y-1">
<li>{t("onboarding.localOnly.bulletOwn")}</li>
<li>{t("onboarding.localOnly.bulletImport")}</li>
<li>{t("onboarding.localOnly.bulletScrobble")}</li>
</ul>
</div>
</div>
</div>
)}
{stepId === "appearance" && (
<div className="mt-6 space-y-6">
{/* Theme picker β same visual contract as Settings β
Appearance but inline, no card wrapper. Each click
fires `setThemeId` which writes to
`profile_setting['appearance.theme.id']` so the
choice survives the onboarding-then-quit edge case. */}
<div className="space-y-3">
<div className="flex items-center gap-2">
<Palette
size={16}
className="text-zinc-400 shrink-0"
aria-hidden="true"
/>
<h3 className="text-sm font-semibold text-zinc-900 dark:text-white">
{t("onboarding.appearance.theme.title")}
</h3>
</div>
<div className="grid grid-cols-3 sm:grid-cols-5 gap-2">
{THEME_PRESETS.map((preset) => {
const isActive = preset.id === theme.id;
return (
<button
key={preset.id}
type="button"
onClick={(event) => setThemeId(preset.id, event)}
aria-pressed={isActive}
aria-label={t(preset.labelKey)}
className={`group relative rounded-lg border overflow-hidden transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500 ${
isActive
? "border-emerald-500 ring-2 ring-emerald-500/30"
: "border-zinc-200 dark:border-zinc-700 hover:border-zinc-300 dark:hover:border-zinc-600"
}`}
>
<div
className="h-10 flex items-center justify-between px-2"
style={{
backgroundColor:
preset.ambient ??
(preset.mode === "dark"
? "#121212"
: "#ffffff"),
}}
>
<div className="flex space-x-0.5">
<div
className="w-2 h-2 rounded-full"
style={{
backgroundColor: preset.accent[400],
}}
/>
<div
className="w-2 h-2 rounded-full"
style={{
backgroundColor: preset.accent[500],
}}
/>
<div
className="w-2 h-2 rounded-full"
style={{
backgroundColor: preset.accent[600],
}}
/>
</div>
{isActive && (
<Check
size={11}
strokeWidth={3}
style={{ color: preset.accent[500] }}
/>
)}
</div>
<div className="px-2 py-1 bg-white dark:bg-zinc-900 text-left">
<div className="text-[10px] font-medium text-zinc-700 dark:text-zinc-200 truncate">
{t(preset.labelKey)}
</div>
</div>
</button>
);
})}
</div>
</div>
{/* Skin picker β orthogonal axis to theme. Click
fires `setSkinId` which writes
`profile_setting['appearance.skin.id']`. */}
<div className="space-y-3">
<div className="flex items-center gap-2">
<Layers
size={16}
className="text-zinc-400 shrink-0"
aria-hidden="true"
/>
<h3 className="text-sm font-semibold text-zinc-900 dark:text-white">
{t("onboarding.appearance.skin.title")}
</h3>
</div>
<div className="grid grid-cols-2 sm:grid-cols-3 gap-2">
{SKIN_PRESETS.map((preset) => {
const isActive = preset.id === skin.id;
return (
<button
key={preset.id}
type="button"
onClick={() => setSkinId(preset.id)}
aria-pressed={isActive}
className={`group relative rounded-lg border px-3 py-2.5 text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500 ${
isActive
? "border-emerald-500 ring-2 ring-emerald-500/30 bg-emerald-50 dark:bg-emerald-500/10"
: "border-zinc-200 dark:border-zinc-700 hover:border-zinc-300 dark:hover:border-zinc-600 bg-white dark:bg-zinc-800/50"
}`}
>
<div className="flex items-center justify-between gap-2">
<span className="text-xs font-semibold text-zinc-800 dark:text-zinc-100 truncate">
{t(preset.labelKey)}
</span>
{isActive && (
<Check
size={12}
strokeWidth={3}
className="text-emerald-500 shrink-0"
/>
)}
</div>
<span className="block text-[10px] text-zinc-500 dark:text-zinc-400 mt-0.5 truncate">
{t(preset.descriptionKey)}
</span>
</button>
);
})}
</div>
</div>
<p className="text-[11px] text-zinc-400 italic">
{t("onboarding.appearance.hint")}
</p>
</div>
)}
{stepId === "lyrics" && (
<div className="mt-6 space-y-4">
<div
role="radiogroup"
aria-label={t("onboarding.lyrics.title")}
className="grid grid-cols-1 sm:grid-cols-3 gap-2"
>
{(
[
{ id: "tag", Icon: FileText },
{ id: "sidecar", Icon: FileDown },
{ id: "db_only", Icon: Database },
] as const
).map(({ id, Icon }) => {
const isActive = lyricsDestination === id;
return (
<button
key={id}
type="button"
role="radio"
aria-checked={isActive}
disabled={lyricsBusy}
onClick={() => void handlePickLyricsDestination(id)}
className={`group relative rounded-xl border p-3 text-left transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500 disabled:opacity-50 ${
isActive
? "border-emerald-500 ring-2 ring-emerald-500/30 bg-emerald-50 dark:bg-emerald-500/10"
: "border-zinc-200 dark:border-zinc-700 hover:border-zinc-300 dark:hover:border-zinc-600 bg-white dark:bg-zinc-800/50"
}`}
>
<div className="flex items-start justify-between gap-2">
<Icon
size={18}
className={
isActive
? "text-emerald-600 dark:text-emerald-400"
: "text-zinc-400"
}
aria-hidden="true"
/>
{isActive && (
<Check
size={14}
strokeWidth={3}
className="text-emerald-500"
/>
)}
</div>
<div className="mt-2 text-sm font-semibold text-zinc-900 dark:text-white">
{t(`lyricsEditor.destination.${id}.label`)}
</div>
<div className="mt-1 text-[11px] text-zinc-500 dark:text-zinc-400 leading-snug">
{t(`lyricsEditor.destination.${id}.hint`)}
</div>
</button>
);
})}
</div>
<p className="text-[11px] text-zinc-400 italic">
{t("onboarding.lyrics.hint")}
</p>
</div>
)}
{stepId === "folder" && (
<div className="mt-6 space-y-4">
<button
type="button"
onClick={handlePickFolder}
className="w-full rounded-xl border-2 border-dashed border-zinc-300 dark:border-zinc-700 px-4 py-5 text-center cursor-pointer hover:border-emerald-500/50 hover:bg-emerald-500/5 transition-all group"
>
<FolderOpen
size={22}
className={`mx-auto mb-2 transition-colors ${
musicFolder
? "text-emerald-500"
: "text-zinc-400 group-hover:text-emerald-500"
}`}
aria-hidden="true"
/>
{musicFolder ? (
<>
<p className="text-sm text-zinc-900 dark:text-zinc-100 break-all px-2">
{musicFolder}
</p>
<p className="mt-1 text-xs text-zinc-500">
{t("onboarding.folder.changeHint")}
</p>
</>
) : (
<p className="text-sm text-zinc-500 dark:text-zinc-400 group-hover:text-zinc-900 dark:group-hover:text-white transition-colors">
{t("onboarding.folder.placeholder")}
</p>
)}
</button>
<div className="rounded-xl border border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-800/40 p-4 space-y-3">
<p className="text-[10px] font-bold tracking-widest uppercase text-zinc-400">
{t("onboarding.folder.quickSettings")}
</p>
<ToggleRow
label={t("onboarding.folder.autoAnalyze.title")}
description={t(
"onboarding.folder.autoAnalyze.description",
)}
value={autoAnalyze}
onChange={handleToggleAutoAnalyze}
/>
</div>
</div>
)}
{stepId === "lastfm" && (
<div className="mt-6 space-y-4">
{/* "Recommended" pill so the step visually stands out
from the other optionals, per the user's "highlight
Last.fm" directive. */}
<div className="flex items-center justify-center gap-2">
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-[10px] font-bold tracking-wider uppercase bg-emerald-500/15 text-emerald-600 dark:text-emerald-300 border border-emerald-500/30">
<Mic2 size={11} />
{t("onboarding.lastfm.recommendedBadge")}
</span>
</div>
{lastfmStatus?.connected ? (
<div className="rounded-xl border border-emerald-500/30 bg-emerald-500/10 p-4 flex items-start gap-3">
<CheckCircle2
size={18}
className="text-emerald-500 shrink-0 mt-0.5"
aria-hidden="true"
/>
<div className="text-sm">
<p className="font-semibold text-emerald-700 dark:text-emerald-300">
{t("onboarding.lastfm.connectedTitle", {
user: lastfmStatus.username ?? "",
})}
</p>
<p className="mt-1 text-xs text-emerald-700/80 dark:text-emerald-200/80">
{t("onboarding.lastfm.connectedSubtitle")}
</p>
</div>
</div>
) : (
<div className="rounded-xl border border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-800/40 p-4 space-y-3">
<button
type="button"
onClick={handleOpenLastfmKeyPage}
className="w-full inline-flex items-center justify-center gap-2 text-xs font-medium text-emerald-600 dark:text-emerald-400 hover:text-emerald-700 dark:hover:text-emerald-300 transition-colors"
>
{t("onboarding.lastfm.keyHint")}
<ExternalLink size={12} aria-hidden="true" />
</button>
<Input
label={t("onboarding.lastfm.keyLabel")}
value={lastfmKey}
onChange={setLastfmKey}
placeholder={t("onboarding.lastfm.keyPlaceholder")}
/>
<Input
label={t("onboarding.lastfm.secretLabel")}
value={lastfmSecret}
onChange={setLastfmSecret}
placeholder={t("onboarding.lastfm.secretPlaceholder")}
type={lastfmSecretVisible ? "text" : "password"}
rightSlot={
<VisibilityToggle
visible={lastfmSecretVisible}
onToggle={() => setLastfmSecretVisible((v) => !v)}
ariaLabel={t("onboarding.lastfm.toggleSecret")}
/>
}
/>
<Input
label={t("onboarding.lastfm.userLabel")}
value={lastfmUsername}
onChange={setLastfmUsername}
placeholder={t("onboarding.lastfm.userPlaceholder")}
/>
<Input
label={t("onboarding.lastfm.passwordLabel")}
value={lastfmPassword}
onChange={setLastfmPassword}
placeholder={t("onboarding.lastfm.passwordPlaceholder")}
type={lastfmPasswordVisible ? "text" : "password"}
rightSlot={
<VisibilityToggle
visible={lastfmPasswordVisible}
onToggle={() => setLastfmPasswordVisible((v) => !v)}
ariaLabel={t("onboarding.lastfm.togglePassword")}
/>
}
/>
{lastfmError && (
<p className="text-xs text-rose-500" role="alert">
{lastfmError}
</p>
)}
<button
type="button"
onClick={handleLastfmLogin}
disabled={lastfmBusy}
className="w-full inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
{lastfmBusy ? (
<Loader2 size={16} className="animate-spin" />
) : (
<Mic2 size={16} />
)}
{t("onboarding.lastfm.connect")}
</button>
</div>
)}
</div>
)}
{stepId === "scan" && (
<div className="mt-6 space-y-3">
{scanState.kind === "running" ? (
<div className="flex flex-col items-center gap-3 py-2">