dracosh 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ui/App.js CHANGED
@@ -11,6 +11,8 @@ import { Bar, cellWidth, cutToWidth, html, KeyHints, Marked, Text, theme, Typewr
11
11
  import { hintTarget, makeHint } from "../hint.js";
12
12
  import { formatClock, inQuietHours, quietEnd } from "../quiet.js";
13
13
  import { NEW_PER_DAY, startOfTomorrow } from "../scheduler.js";
14
+ import { languageName, setOwnLanguage } from "../language.js";
15
+ import { hasFirstWords, sampleCard } from "../firstwords.js";
14
16
  import { formatDay } from "../vacation.js";
15
17
  import { dayKey } from "../dates.js";
16
18
  import { shouldShowTip } from "../tips.js";
@@ -22,8 +24,17 @@ import { BadgeUnlock, badgeSound } from "./BadgeUnlock.js";
22
24
  import { DieRoll } from "./DieRoll.js";
23
25
  import { Evolution } from "./Evolution.js";
24
26
  import { Hatch } from "./Hatch.js";
27
+ import { LanguageSearch } from "./Languages.js";
28
+ import { FIRST_WORDS_COUNT, Welcome } from "./Welcome.js";
29
+ import { AiSetup } from "./Ai.js";
30
+ import { VoiceSetup } from "./Voice.js";
25
31
  import { AddCard } from "./AddCard.js";
32
+ import { ImportScreen } from "./Import.js";
26
33
  import { Decks } from "./Decks.js";
34
+ import { Choice, choiceHints } from "./Choice.js";
35
+ import { elementName } from "../progress.js";
36
+ import { Trash } from "./Trash.js";
37
+ import { Cards, CardsDeckPick } from "./Cards.js";
27
38
  import { Reset } from "./Reset.js";
28
39
  import { Help } from "./Help.js";
29
40
  import { Missed } from "./Missed.js";
@@ -86,10 +97,11 @@ function Verdict({ outcome, question }) {
86
97
  const held = outcome.held ? heldText(outcome.held) : null;
87
98
  return html`
88
99
  <${Box} flexDirection="column">
89
- <${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${outcome.result === "accent" || outcome.result === "umlaut" || outcome.result === "article-umlaut" ? html`<${AccentedAnswers} expected=${question.expected} given=${outcome.given} closest=${outcome.closest} />` : question.expected.join(" / ")}${outcome.result === "typo" ? t("quiz.closeEnough") : ""}<//>
100
+ <${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${outcome.result === "accent" || outcome.result === "umlaut" || outcome.result === "article-umlaut" ? html`<${AccentedAnswers} expected=${question.expected} given=${outcome.given} closest=${outcome.closest} />` : question.expected.join(" / ")}${outcome.result === "typo" ? t("quiz.closeEnough") : ""}${question.word.ai ? html`<${Text} color=${theme.accent} bold=${false}> ✦<//>` : ""}<//>
90
101
  ${ALMOST.includes(outcome.result) && html`<${Text} color=${theme.warn}>${t(`quiz.almost.${outcome.result}`)}<//>`}
91
102
  ${showDiff && html`<${AnswerDiff} given=${outcome.given} closest=${outcome.closest} />`}
92
103
  ${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
104
+ ${wrong && question.word.ai && html`<${Box} marginTop=${1}><${Text} color=${theme.accent}>${t("quiz.fromAi")}<//><//>`}
93
105
  ${(outcome.hinted || outcome.overruled || held) &&
94
106
  html`
95
107
  <${Box} marginTop=${1} flexDirection="column">
@@ -106,7 +118,7 @@ function Verdict({ outcome, question }) {
106
118
  function Revealed({ question, nudge }) {
107
119
  return html`
108
120
  <${Box} flexDirection="column">
109
- <${Text} color=${theme.accent} bold>${question.expected.join(" / ")}<//>
121
+ <${Text} color=${theme.accent} bold>${question.expected.join(" / ")}${question.word.ai ? html`<${Text} bold=${false}> ✦<//>` : ""}<//>
110
122
  ${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
111
123
  <${Box} marginTop=${1}>
112
124
  <${Text} bold>${t("quiz.didYouKnow")} <//>
@@ -178,6 +190,22 @@ function EmptyDeck({ deck, tour, count, nextDue, dayDone, heldNew = 0, now, widt
178
190
  `;
179
191
  }
180
192
 
193
+ // /settings → the default look: asked first, since the element can't come back
194
+ function DragonLook({ element, onConfirm, onClose }) {
195
+ const width = usePanelWidth();
196
+ const [selected, setSelected] = useState(1);
197
+ return html`
198
+ <${Fragment}>
199
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.bad} paddingX=${2} width=${width}>
200
+ <${Text} bold color=${theme.bad}>${t("settings.lookQuestion")}<//>
201
+ <${Text} dimColor>${t("settings.lookNote", { element: elementName(element) })}<//>
202
+ <${Box} marginTop=${1}><${Choice} options=${[{ label: t("settings.lookYes"), danger: true }, { label: t("settings.lookNo") }]} selected=${selected} onMove=${setSelected} onPick=${(i) => (i === 0 ? onConfirm() : onClose())} onCancel=${onClose} /><//>
203
+ <//>
204
+ <${Box} paddingX=${1}><${KeyHints} text=${choiceHints("cancel")} /><//>
205
+ <//>
206
+ `;
207
+ }
208
+
181
209
  function TipBox({ tip, width }) {
182
210
  return html`
183
211
  <${Box} flexDirection="column" paddingX=${1} marginTop=${2} width=${width}>
@@ -189,17 +217,28 @@ function TipBox({ tip, width }) {
189
217
 
190
218
  // `library` holds the /add actions (src/manage.js) and `onSwitchDeck` points the session at another
191
219
  // deck; the preview gallery passes neither.
192
- export function App({ session, deck: initialDeck, initialSettings, alerts, persistSettings, onExit, library, onSwitchDeck }) {
220
+ // `initialMix`: the decks practised together this run (null with --deck, while settings keep the saved ones)
221
+ export function App({ session, deck: initialDeck, initialSettings, initialMix, alerts, persistSettings, onExit, library, onSwitchDeck, onMix }) {
193
222
  const { exit: exitApp } = useApp();
194
223
  const exit = onExit ?? exitApp; // the preview gallery runs the quiz as a scene and takes quitting back to its menu
195
224
  const { stdout } = useStdout();
196
225
  const [settings, setSettings] = useState(initialSettings);
197
226
  const [deck, setDeck] = useState(initialDeck);
227
+ const [mix, setMix] = useState(initialMix !== undefined ? initialMix : (initialSettings.mix ?? null)); // decks practised together: "all", or their names
198
228
  const [addNew, setAddNew] = useState(false); // /add opened from "+ New deck" in /decks
229
+ const [cardsDeck, setCardsDeck] = useState(null); // the deck /cards shows (one of several practised together)
230
+ const [addInto, setAddInto] = useState(null); // /add from /cards: straight into that deck
231
+ const [addSuggest, setAddSuggest] = useState(null); // /add from the welcome: a name and an example in your pair
232
+ const [aiFrom, setAiFrom] = useState(null); // "welcome" while AI help is set up for a first deck
233
+ const [importFrom, setImportFrom] = useState(null); // "welcome" when /import was picked there: cancelling goes back
199
234
  const [restUntil, setRestUntil] = useState(null); // nothing is waiting until then (after the last card due now)
200
235
  const [empty, setEmpty] = useState(null); // { tour, count, nextDue } when there is nothing to ask right now
201
- // quiz | settings | reset | add | decks | stats | badges | companion | help | missed | evolve | the-one | die | summary | hatch
202
- const [screen, setScreen] = useState(() => (session.isFirstRun() ? "hatch" : "quiz"));
236
+ // quiz | settings | reset | home-language | add | decks | stats | badges | companion | help | missed | evolve | the-one | die
237
+ // | summary | hatch | welcome
238
+ const [screen, setScreen] = useState(() => (session.isFirstRun() ? "hatch" : session.welcomeStep() ? "welcome" : "quiz"));
239
+ const [welcomeStep, setWelcomeStep] = useState(() => session.welcomeStep() ?? "language");
240
+ const [tourThere, setTourThere] = useState(true); // the welcome offers the tour only while there is one
241
+ const settingsRow = useRef(0); // /settings opens on the row it was left on (Your language comes back to it)
203
242
  const [tip, setTip] = useState(null);
204
243
  const [phase, setPhase] = useState("loading"); // loading | asking | grading (answer revealed) | waiting | empty
205
244
  const [nudge, setNudge] = useState(false); // Enter while grading: the 1/2 keys light up
@@ -284,6 +323,12 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
284
323
  ask();
285
324
  }, [ask]);
286
325
 
326
+ // a natural voice that stopped working (key, credit) says so once; words go on in the system's voice
327
+ useEffect(() => {
328
+ alerts.configure({ onVoiceProblem: (message) => setNotice(message) });
329
+ return () => alerts.configure({ onVoiceProblem: null });
330
+ }, [alerts]);
331
+
287
332
  // one steady clock for the whole app: spinner, countdown, mascot blink and combo flicker
288
333
  useEffect(() => {
289
334
  const id = setInterval(() => setNow(Date.now()), TICK_MS);
@@ -402,6 +447,9 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
402
447
  if (name === "/missed") return setScreen("missed");
403
448
  if (name === "/help") return setScreen("help");
404
449
  if (name === "/add") return library ? (setAddNew(false), setScreen("add")) : setNotice(t("quiz.previewNoAdd"));
450
+ if (name === "/import") return library ? (setImportFrom(null), setScreen("import")) : setNotice(t("quiz.previewNoImport"));
451
+ if (name === "/cards") return !library ? setNotice(t("quiz.previewNoDecks")) : !mix && (question?.tour || empty?.tour) ? setNotice(t("cards.tourNot")) : mix ? setScreen("cards-pick") : (setCardsDeck(deck), setScreen("cards"));
452
+ if (name === "/trash") return library ? setScreen("trash") : setNotice(t("quiz.previewNoDecks"));
405
453
  if (name === "/decks") return library ? setScreen("decks") : setNotice(t("quiz.previewNoDecks"));
406
454
  if (name === "/hint" && phase === "asking") return setHintLevel((level) => level + 1);
407
455
  if (name === "/pause") {
@@ -446,7 +494,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
446
494
  const next = { ...previous, ...patch };
447
495
  settingsRef.current = next;
448
496
  setSettings(next);
449
- alerts.configure({ sound: next.sound, volume: next.volume, speak: next.speak });
497
+ alerts.configure({ sound: next.sound, volume: next.volume, speak: next.speak, voice: next.voice });
450
498
  persistSettings(patch).catch(() => {});
451
499
  if (patch.everyMs && phase === "waiting") setNextAt((at) => at - previous.everyMs + patch.everyMs);
452
500
  if (patch.rhythm) {
@@ -455,6 +503,64 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
455
503
  }
456
504
  if (patch.volume !== undefined || patch.sound === true) alerts.play("correct-0"); // audible preview
457
505
  if (patch.language) changeLanguage(patch.language);
506
+ if (patch.homeLanguage !== undefined) setOwnLanguage(patch.homeLanguage);
507
+ }
508
+
509
+ // the welcome: each answer kept at once, and the step, so it goes on there after a restart
510
+ function welcomeTo(step, patch) {
511
+ if (patch) changeSettings(patch);
512
+ setWelcomeStep(step);
513
+ session.setWelcomeStep(step).catch(() => {});
514
+ }
515
+
516
+ useEffect(() => {
517
+ if (screen === "welcome" && library) library.allDecks().then((decks) => setTourThere(decks.some((d) => d.tour)), () => {});
518
+ }, [screen, library]);
519
+
520
+ async function startWith(how) {
521
+ if (busy.current) return; // a second Enter while the first words are being made
522
+ busy.current = true;
523
+ try {
524
+ await begin(how);
525
+ } finally {
526
+ busy.current = false;
527
+ }
528
+ }
529
+
530
+ async function begin(how) {
531
+ // the import may still be cancelled, back to the welcome: it ends the welcome once it's done
532
+ if (how === "import" && library) {
533
+ setImportFrom("welcome");
534
+ return setScreen("import");
535
+ }
536
+ // a first deck from AI help: set up first, Esc there goes back to the welcome
537
+ if (how === "ai" && library && !settingsRef.current.ai) {
538
+ setAiFrom("welcome");
539
+ return setScreen("ai");
540
+ }
541
+ session.setWelcomeStep(null).catch(() => {});
542
+ if (how === "tour" || !library) return setScreen("quiz");
543
+ if (how === "own" || how === "ai") {
544
+ // the deck named after the language you're learning, and an example card in your pair; from AI
545
+ // help, a list of everyday words of the pair to ask for
546
+ const { homeLanguage, language: ui, learningLanguage: learning } = settingsRef.current;
547
+ const home = homeLanguage ?? ui;
548
+ const name = languageName(learning) ?? "";
549
+ const sample = learning && hasFirstWords(home, learning) ? sampleCard(home, learning) : null;
550
+ const request = how === "ai" && name ? t("welcome.aiRequest", { count: FIRST_WORDS_COUNT, language: name, home: languageName(home) }) : null;
551
+ setAddSuggest({ name: name && name.charAt(0).toLocaleUpperCase(ui) + name.slice(1), example: sample && `${sample.front} = ${sample.back[0]}`, request });
552
+ setAddNew(true);
553
+ return setScreen("add");
554
+ }
555
+ try {
556
+ const { deck: started, removed } = await library.startFirstWords({ home: settingsRef.current.homeLanguage ?? settingsRef.current.language, learning: settingsRef.current.learningLanguage });
557
+ if (removed.length) await session.forget(removed);
558
+ await session.workAdded();
559
+ switchDeck(started.name);
560
+ } catch (err) {
561
+ setScreen("quiz");
562
+ setProblem(err.message);
563
+ }
458
564
  }
459
565
 
460
566
  // Every text follows at the next render; the tour is translated too, and asked again in the new
@@ -524,9 +630,8 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
524
630
  }
525
631
  }
526
632
 
527
- // /decks and a first deck from /add: quiz another deck from now on, and remember it
528
- function switchDeck(name) {
529
- setScreen("quiz");
633
+ // the deck practised from now on, without leaving the screen you're on (a deck deleted or renamed in /decks)
634
+ function followDeck(name) {
530
635
  if (name === deck) return;
531
636
  onSwitchDeck?.(name);
532
637
  setDeck(name);
@@ -534,6 +639,97 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
534
639
  ask();
535
640
  }
536
641
 
642
+ // /decks → Delete, confirmed: the deck and its progress into the trash; another deck if it was this one
643
+ async function deleteDeck(name) {
644
+ const done = await library.deleteDeck(name, session.progressOf);
645
+ await session.forget(done.cardIds);
646
+ keepSavedMix((names) => names.filter((each) => each !== name));
647
+ if (Array.isArray(mix) && mix.includes(name)) {
648
+ const left = mix.filter((each) => each !== name);
649
+ practise({ deck: name === deck ? left[0] : deck, mix: left.length >= 2 ? left : null });
650
+ } else if (name === deck) followDeck(done.next);
651
+ else if (phase === "empty" || mix === "all" || question?.label === name) ask(); // its card may be the one on screen
652
+ return done;
653
+ }
654
+
655
+ // the decks saved to practise together when this run practises others (--deck): kept in step too
656
+ function keepSavedMix(change) {
657
+ const saved = settingsRef.current.mix;
658
+ if (!Array.isArray(saved) || saved === mix) return;
659
+ const next = [...new Set(change(saved))];
660
+ changeSettings({ mix: next.length >= 2 ? next : null });
661
+ }
662
+
663
+ // a deck back from the trash, with its progress; the tour gives way to it
664
+ async function restoreDeck(entryId) {
665
+ const back = await library.restoreFromTrash(entryId);
666
+ await session.restoreProgress(back.progress);
667
+ if (back.removed.length) await session.forget(back.removed);
668
+ await session.workAdded();
669
+ if (back.removed.length || (back.kind === "deck" && phase === "empty")) followDeck(back.deck);
670
+ else if (phase === "empty") ask();
671
+ return back;
672
+ }
673
+
674
+ // /cards → Delete: the cards and their progress into the trash
675
+ async function deleteCards(cardIds) {
676
+ const done = await library.deleteCards(cardsDeck ?? deck, cardIds, session.progressOf);
677
+ await session.forget(cardIds);
678
+ return done;
679
+ }
680
+
681
+ // /decks → Merge: the cards into the other deck, the emptied deck (with what was there already) to the
682
+ // trash; the decks practised follow
683
+ async function mergeDecks(from, into) {
684
+ const done = await library.mergeDecks(from, into, session.progressOf);
685
+ if (done.left.length) await session.forget(done.left);
686
+ if (Array.isArray(mix) && mix.includes(from)) {
687
+ const left = [...new Set(mix.map((name) => (name === from ? into : name)))];
688
+ practise({ deck: deck === from ? into : deck, mix: left.length >= 2 ? left : null });
689
+ } else if (deck === from) followDeck(into);
690
+ else if (phase === "empty") ask();
691
+ return done;
692
+ }
693
+
694
+ function cardsClosed(changed) {
695
+ setScreen("quiz");
696
+ if (changed && (phase === "asking" || phase === "empty")) ask(); // the card on screen may be one you changed
697
+ }
698
+
699
+ function deckRenamed(from, to) {
700
+ keepSavedMix((names) => names.map((name) => (name === from ? to : name)));
701
+ if (Array.isArray(mix) && mix.includes(from)) {
702
+ const renamed = mix.map((name) => (name === from ? to : name));
703
+ onMix?.(renamed);
704
+ setMix(renamed);
705
+ changeSettings({ mix: renamed });
706
+ }
707
+ if (from !== deck) return;
708
+ onSwitchDeck?.(to);
709
+ setDeck(to);
710
+ changeSettings({ deck: to });
711
+ }
712
+
713
+ // /decks and a first deck from /add: quiz another deck from now on, and remember it
714
+ function switchDeck(name) {
715
+ setScreen("quiz");
716
+ if (name === deck && !mix) return;
717
+ practise({ deck: name, mix: null });
718
+ }
719
+
720
+ // what the quiz asks from now on: one deck, or several together (`mix`: "all" or names), remembered
721
+ function practise({ deck: name = deck, mix: together }) {
722
+ onMix?.(together);
723
+ setMix(together);
724
+ if (name !== deck) {
725
+ onSwitchDeck?.(name);
726
+ setDeck(name);
727
+ }
728
+ changeSettings({ deck: name, mix: together });
729
+ ask();
730
+ }
731
+ const deckLabel = mix === "all" ? t("decks.allLabel") : mix ? t("decks.mixLabel", { count: mix.length }) : deck;
732
+
537
733
  // Reset (from /settings), after a backup. Everything brings back the tour and the hatching egg.
538
734
  async function reset(scope) {
539
735
  await library.backupBeforeReset();
@@ -546,15 +742,53 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
546
742
  const tour = await library.resetLibrary();
547
743
  onSwitchDeck?.(tour);
548
744
  setDeck(tour);
549
- changeSettings({ deck: null });
745
+ onMix?.(null);
746
+ setMix(null);
747
+ changeSettings({ deck: null, mix: null });
550
748
  setScreen("hatch");
551
749
  ask();
552
750
  }
553
751
 
752
+ // after /import: its first new deck (or the one cards went into) is the one you practise; the tour's
753
+ // progress goes if a deck of your own took its place
754
+ async function importDone({ deck: target, removed, added, updated }) {
755
+ if (importFrom === "welcome") session.setWelcomeStep(null).catch(() => {});
756
+ setImportFrom(null);
757
+ try {
758
+ if (removed.length) await session.forget(removed);
759
+ if (added || updated) await session.workAdded();
760
+ } catch {
761
+ // progress of removed tour cards stays: harmless
762
+ }
763
+ if (target && target !== deck) return switchDeck(target);
764
+ setScreen("quiz");
765
+ // the open card may be one the file just changed: asked again as it is now
766
+ if ((added || updated) && (phase === "asking" || phase === "empty")) ask();
767
+ }
768
+
769
+ // AI help set up (or not): from the welcome, on to the first deck, or back to the welcome
770
+ function aiClosed(said) {
771
+ if (aiFrom !== "welcome") return setScreen("settings"), said && setNotice(said);
772
+ setAiFrom(null);
773
+ if (settingsRef.current.ai) return begin("ai");
774
+ setScreen("welcome");
775
+ }
776
+
777
+ function importCancelled() {
778
+ if (importFrom === "welcome") {
779
+ setImportFrom(null);
780
+ return setScreen("welcome");
781
+ }
782
+ setScreen("quiz");
783
+ setNotice(t("cli.restore.nothingChanged"));
784
+ }
785
+
554
786
  // after /add: a first deck of your own replaces the tour; a deck started from /decks (or in place
555
787
  // of an empty one) becomes the one you practise; new cards end an empty state
556
788
  function addDone({ deck: started, removed, stale = [], added, dropped }) {
557
789
  setScreen("quiz");
790
+ setAddSuggest(null);
791
+ setAddInto(null);
558
792
  if (removed.length) session.forget(removed).catch(() => {});
559
793
  if (stale.length) session.forgetKeys(stale).catch(() => {});
560
794
  if (added) session.workAdded().catch(() => {});
@@ -585,8 +819,11 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
585
819
  if (screen === "hatch")
586
820
  return html`<${Box} flexDirection="column" marginY=${1}><${Hatch} play=${alerts.play} onDone=${() => {
587
821
  session.markHatched().catch(() => {});
588
- setScreen("quiz");
822
+ setWelcomeStep("language");
823
+ setScreen("welcome");
589
824
  }} /><//>`;
825
+ if (screen === "welcome")
826
+ return html`<${Box} flexDirection="column" marginY=${1}><${Welcome} step=${welcomeStep} settings=${settings} tour=${tourThere} onPreviewLanguage=${setLanguage} onStep=${welcomeTo} onStart=${startWith} /><//>`;
590
827
  if (screen === "summary") return html`<${Box} flexDirection="column" marginY=${1}><${Summary} stats=${stats} totals=${session.totals} bestCombo=${bestCombo.current} onDone=${exit} /><//>`;
591
828
  if (screen === "evolve" && evolution)
592
829
  return html`<${Box} flexDirection="column" marginY=${1}><${Evolution} ...${evolution} onClose=${() => {
@@ -604,17 +841,25 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
604
841
 
605
842
  return html`
606
843
  <${Box} flexDirection="column" marginY=${1}>
607
- <${Header} deck=${deck} everyMs=${settings.everyMs} rhythm=${settings.rhythm} wordCount=${question?.wordCount ?? empty?.count} stats=${stats} combo=${session.totals.combo} face=${face} event=${petEvent} tick=${tick} asleep=${asleep} />
844
+ <${Header} deck=${deckLabel} everyMs=${settings.everyMs} rhythm=${settings.rhythm} wordCount=${question?.wordCount ?? empty?.count} stats=${stats} combo=${session.totals.combo} face=${face} event=${petEvent} tick=${tick} asleep=${asleep} />
608
845
  <${Box} marginTop=${1} flexDirection="column">
609
- ${screen === "settings" && html`<${Settings} settings=${settings} onChange=${changeSettings} onClose=${() => setScreen("quiz")} onAction=${library ? () => setScreen("reset") : null} />`}
846
+ ${screen === "settings" && html`<${Settings} settings=${settings} element=${stats.companion.element} startRow=${settingsRow.current} onRow=${(row) => (settingsRow.current = row)} onChange=${changeSettings} onClose=${() => setScreen("quiz")} onAction=${library ? (row) => setScreen({ reset: "reset", homeLanguage: "home-language", dragonLook: "dragon-look", ai: "ai", voice: "voice" }[row]) : null} />`}
847
+ ${screen === "dragon-look" && html`<${DragonLook} element=${stats.companion.element} onConfirm=${() => session.defaultLook().then(() => (setScreen("settings"), setNotice(t("settings.lookDropped")))).catch((err) => setProblem(err.message))} onClose=${() => setScreen("settings")} />`}
848
+ ${screen === "home-language" && html`<${LanguageSearch} title=${t("settings.homeTitle")} note=${t("welcome.homeNote")} current=${settings.homeLanguage ?? settings.language} currentNote=${settings.homeLanguage ? t("languages.current") : t("welcome.suggested")} onBack=${() => setScreen("settings")} onPick=${(code) => (changeSettings({ homeLanguage: code }), setScreen("settings"))} />`}
849
+ ${screen === "ai" && html`<${AiSetup} current=${settings.ai} onSave=${(ai) => changeSettings({ ai })} onClose=${aiClosed} note=${aiFrom === "welcome" ? t("ai.noteWelcome") : undefined} />`}
850
+ ${screen === "voice" && html`<${VoiceSetup} current=${settings.voice} speakOn=${settings.speak} play=${alerts.playFile} onSave=${(voice) => changeSettings(voice && !settingsRef.current.speak ? { voice, speak: true } : { voice })} onClose=${(said) => (setScreen("settings"), said && setNotice(said))} />`}
610
851
  ${screen === "reset" && html`<${Reset} stats=${stats} actions=${library} onConfirm=${reset} onClose=${() => setScreen("settings")} />`}
611
- ${screen === "add" && html`<${AddCard} current=${deck} actions=${library} onDone=${addDone} startNew=${addNew} />`}
612
- ${screen === "decks" && html`<${Decks} current=${deck} actions=${library} onDirections=${async (cardIds, directions) => {
852
+ ${screen === "import" && html`<${ImportScreen} actions=${library} fromWelcome=${importFrom === "welcome"} onDone=${importDone} onCancel=${importCancelled} />`}
853
+ ${screen === "add" && html`<${AddCard} current=${deck} actions=${library} ai=${settings.ai} onDone=${addDone} startNew=${addNew} suggest=${addSuggest} into=${addInto} />`}
854
+ ${screen === "decks" && html`<${Decks} current=${deck} mix=${mix} onPractise=${practise} actions=${library} onDirections=${async (cardIds, directions) => {
613
855
  await session.setDirections(cardIds, directions);
614
856
  await session.workAdded();
615
857
  if (phase === "asking" && question && cardIds.includes(question.word.noteId)) ask(); // the open card follows the new way at once
616
- }} onLanguages=${(name) => name === deck && phase === "asking" && ask()} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onClose=${() => setScreen("quiz")} />`}
617
- ${!["settings", "reset", "add", "decks"].includes(screen) &&
858
+ }} onLanguages=${(name) => name === deck && phase === "asking" && ask()} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onDeleted=${deleteDeck} onRestored=${restoreDeck} onRenamed=${deckRenamed} onMerged=${mergeDecks} onClose=${() => setScreen("quiz")} />`}
859
+ ${screen === "cards" && html`<${Cards} deck=${cardsDeck ?? deck} actions=${library} ai=${settings.ai} onDeleted=${deleteCards} onRestored=${restoreDeck} onEdited=${(keys) => session.forgetKeys(keys)} onAdd=${() => (setAddNew(false), setAddInto(cardsDeck ?? deck), setScreen("add"))} onClose=${cardsClosed} />`}
860
+ ${screen === "cards-pick" && html`<${CardsDeckPick} actions=${library} mix=${mix} current=${deck} onPick=${(name) => (setCardsDeck(name), setScreen("cards"))} onClose=${() => setScreen("quiz")} />`}
861
+ ${screen === "trash" && html`<${Trash} actions=${library} onRestore=${restoreDeck} onClose=${() => setScreen("quiz")} />`}
862
+ ${!["settings", "ai", "voice", "reset", "home-language", "dragon-look", "import", "add", "decks", "trash", "cards", "cards-pick"].includes(screen) &&
618
863
  html`
619
864
  <${Fragment}>
620
865
  ${question &&
@@ -633,7 +878,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
633
878
  <//>
634
879
  <//>
635
880
  `}
636
- ${phase === "empty" && html`<${EmptyDeck} deck=${deck} ...${empty} now=${now} width=${width} />`}
881
+ ${phase === "empty" && html`<${EmptyDeck} deck=${deckLabel} ...${empty} now=${now} width=${width} />`}
637
882
  ${confetti && html`<${Confetti} width=${width} onDone=${() => setConfetti(false)} />`}
638
883
  ${outcome?.cheers?.length > 0 && html`<${Cheers} cheers=${outcome.cheers} play=${alerts.play} />`}
639
884
  ${phase === "waiting" && tip && html`<${TipBox} tip=${tip} width=${width} />`}