dracosh 0.1.0 → 0.3.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/README.md +49 -22
- package/assets/sounds/badge-1.wav +0 -0
- package/assets/sounds/badge-2.wav +0 -0
- package/assets/sounds/badge-3.wav +0 -0
- package/assets/sounds/badge-4.wav +0 -0
- package/locales/de.json +1046 -0
- package/locales/en.json +1029 -0
- package/locales/fr.json +1094 -0
- package/locales/pl.json +1117 -0
- package/locales/uk.json +1118 -0
- package/package.json +2 -2
- package/src/alerts.js +7 -4
- package/src/backup.js +96 -0
- package/src/cardline.js +71 -0
- package/src/cli.js +106 -38
- package/src/commands.js +15 -13
- package/src/demo.js +11 -0
- package/src/diff.js +13 -7
- package/src/i18n.js +68 -0
- package/src/judge.js +51 -12
- package/src/library.js +154 -0
- package/src/lock.js +64 -0
- package/src/manage.js +165 -0
- package/src/pause.js +22 -0
- package/src/progress.js +202 -93
- package/src/quiet.js +4 -3
- package/src/scheduler.js +39 -30
- package/src/session.js +181 -33
- package/src/settings.js +15 -13
- package/src/starter.js +47 -0
- package/src/store.js +58 -17
- package/src/tips.js +17 -25
- package/src/ui/AddCard.js +496 -0
- package/src/ui/AnswerInput.js +28 -13
- package/src/ui/App.js +360 -89
- package/src/ui/BadgeUnlock.js +51 -0
- package/src/ui/Badges.js +79 -20
- package/src/ui/Choice.js +38 -0
- package/src/ui/Companion.js +24 -39
- package/src/ui/Confetti.js +2 -2
- package/src/ui/Decks.js +99 -0
- package/src/ui/DieRoll.js +104 -0
- package/src/ui/Evolution.js +11 -10
- package/src/ui/Hatch.js +9 -7
- package/src/ui/Header.js +62 -19
- package/src/ui/Help.js +74 -0
- package/src/ui/Mascot.js +89 -40
- package/src/ui/Missed.js +15 -13
- package/src/ui/Preview.js +123 -29
- package/src/ui/Reset.js +71 -0
- package/src/ui/Settings.js +34 -23
- package/src/ui/Stats.js +28 -24
- package/src/ui/Summary.js +18 -10
- package/src/ui/TheOne.js +122 -0
- package/src/ui/icons.js +156 -25
- package/src/ui/kit.js +87 -2
- package/src/vacation.js +9 -3
- package/src/words.js +22 -14
- package/assets/sounds/badge.wav +0 -0
- package/data/tips.json +0 -1362
- package/src/ui/Tip.js +0 -25
package/src/ui/App.js
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
import { Fragment, useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { Box,
|
|
2
|
+
import { Box, useApp, useInput, useStdout } from "ink";
|
|
3
3
|
import { commandsFor } from "../commands.js";
|
|
4
|
-
import { diffChars } from "../diff.js";
|
|
4
|
+
import { accentMarks, diffChars } from "../diff.js";
|
|
5
5
|
import { AnswerInput } from "./AnswerInput.js";
|
|
6
6
|
import { Header } from "./Header.js";
|
|
7
|
-
import {
|
|
7
|
+
import { setLanguage, t } from "../i18n.js";
|
|
8
|
+
import { Bar, cellWidth, cutToWidth, html, KeyHints, Marked, Text, theme, Typewriter, usePanelWidth } from "./kit.js";
|
|
8
9
|
import { hintTarget, makeHint } from "../hint.js";
|
|
9
|
-
import { formatClock, inQuietHours,
|
|
10
|
+
import { formatClock, inQuietHours, quietEnd } from "../quiet.js";
|
|
11
|
+
import { startOfTomorrow } from "../scheduler.js";
|
|
12
|
+
import { formatDay } from "../vacation.js";
|
|
13
|
+
import { dayKey } from "../dates.js";
|
|
10
14
|
import { shouldShowTip } from "../tips.js";
|
|
15
|
+
import { sessionLength } from "../settings.js";
|
|
11
16
|
import { Badges } from "./Badges.js";
|
|
12
17
|
import { Companion } from "./Companion.js";
|
|
13
18
|
import { Confetti } from "./Confetti.js";
|
|
19
|
+
import { BadgeUnlock, badgeSound } from "./BadgeUnlock.js";
|
|
20
|
+
import { DieRoll } from "./DieRoll.js";
|
|
14
21
|
import { Evolution } from "./Evolution.js";
|
|
15
22
|
import { Hatch } from "./Hatch.js";
|
|
23
|
+
import { AddCard } from "./AddCard.js";
|
|
24
|
+
import { Decks } from "./Decks.js";
|
|
25
|
+
import { Reset } from "./Reset.js";
|
|
26
|
+
import { Help } from "./Help.js";
|
|
16
27
|
import { Missed } from "./Missed.js";
|
|
17
28
|
import { Settings } from "./Settings.js";
|
|
18
29
|
import { Stats } from "./Stats.js";
|
|
19
30
|
import { Summary } from "./Summary.js";
|
|
20
|
-
import {
|
|
31
|
+
import { TheOne } from "./TheOne.js";
|
|
21
32
|
|
|
22
|
-
const SPINNER = ["
|
|
33
|
+
const SPINNER = ["⠚", "⠓", "⠋", "⠙"]; // the old braille dots on a 2×2 square: the gap goes round
|
|
23
34
|
const TICK_MS = 250; // the steady redraw: slow enough to stay idle for hours, fast enough for the spinner
|
|
24
35
|
const SLEEP_AFTER_MS = 3 * 60_000; // no key pressed for this long while waiting → the dragon dozes off
|
|
25
|
-
const PAUSED_SLEEP_AFTER_MS = 15_000; // during
|
|
36
|
+
const PAUSED_SLEEP_AFTER_MS = 15_000; // during a pause or quiet hours it nods off again much sooner
|
|
37
|
+
const SETTLE_MS = 400; // keys right after a card appears or its answer is revealed are a double press, not a choice
|
|
26
38
|
const CHEER_STYLE = {
|
|
27
|
-
goal: { icon: "
|
|
28
|
-
evolve: { icon: "
|
|
39
|
+
goal: { icon: "▪", color: theme.good },
|
|
40
|
+
evolve: { icon: "▴", color: theme.accent },
|
|
29
41
|
badge: { icon: "✦", color: theme.warn },
|
|
30
42
|
combo: { icon: "»", color: theme.warn }
|
|
31
43
|
};
|
|
@@ -35,53 +47,85 @@ function clock(ms) {
|
|
|
35
47
|
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
// your answer with every letter judged: green lined up with the expected word,
|
|
50
|
+
// your answer with every letter judged: green lined up with the expected word, underlined didn't
|
|
39
51
|
function AnswerDiff({ given, closest }) {
|
|
40
52
|
const parts = diffChars(given, closest);
|
|
41
53
|
return html`
|
|
42
54
|
<${Text}>
|
|
43
|
-
<${Text} dimColor
|
|
44
|
-
${parts.map((p, i) => html`<${Text} key=${i} color=${p.ok ? theme.good : theme.
|
|
55
|
+
<${Text} dimColor>${t("quiz.youWrote")}<//>
|
|
56
|
+
${parts.map((p, i) => html`<${Text} key=${i} color=${p.ok ? theme.good : theme.text} underline=${!p.ok}>${p.ch}<//>`)}
|
|
45
57
|
<//>
|
|
46
58
|
`;
|
|
47
59
|
}
|
|
48
60
|
|
|
61
|
+
// the right answers after one written without its accents, the letters you wrote plain underlined: jabłko
|
|
62
|
+
function AccentedAnswers({ expected, given, closest }) {
|
|
63
|
+
return expected.map((answer, i) => {
|
|
64
|
+
const marks = answer === closest ? accentMarks(given, answer) : null;
|
|
65
|
+
return html`
|
|
66
|
+
<${Text} key=${i}>
|
|
67
|
+
${i > 0 ? " / " : ""}${marks ? marks.map((p, k) => html`<${Text} key=${k} underline=${!p.ok}>${p.ch}<//>`) : answer}
|
|
68
|
+
<//>
|
|
69
|
+
`;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
49
73
|
function Verdict({ outcome, question }) {
|
|
50
|
-
if (outcome.result === "skipped") return html`<${Text} dimColor>– skipped<//>`;
|
|
51
74
|
const wrong = outcome.result === "wrong";
|
|
52
75
|
const showDiff = outcome.closest && outcome.given && !outcome.overruled && (wrong || outcome.result === "typo");
|
|
53
76
|
return html`
|
|
54
77
|
<${Box} flexDirection="column">
|
|
55
|
-
<${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${question.expected.join("
|
|
78
|
+
<${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${outcome.result === "accent" ? html`<${AccentedAnswers} expected=${question.expected} given=${outcome.given} closest=${outcome.closest} />` : question.expected.join(" / ")}${outcome.result === "typo" ? t("quiz.closeEnough") : ""}<//>
|
|
56
79
|
${showDiff && html`<${AnswerDiff} given=${outcome.given} closest=${outcome.closest} />`}
|
|
57
|
-
${question.word.example && html`<${Text} dimColor
|
|
80
|
+
${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
|
|
58
81
|
${(outcome.hinted || outcome.overruled) &&
|
|
59
82
|
html`
|
|
60
83
|
<${Box} marginTop=${1} flexDirection="column">
|
|
61
|
-
${outcome.hinted && html`<${Text} dimColor
|
|
62
|
-
${outcome.overruled && html`<${Text} color=${theme.good}
|
|
84
|
+
${outcome.hinted && html`<${Text} dimColor>${t("quiz.hintUsed")}<//>`}
|
|
85
|
+
${outcome.overruled && html`<${Text} color=${theme.good}>${t("quiz.countedCorrect")}${question.tour ? "" : t("quiz.acceptedFromNow", { answer: outcome.accepted })}<//>`}
|
|
63
86
|
<//>
|
|
64
87
|
`}
|
|
65
88
|
<//>
|
|
66
89
|
`;
|
|
67
90
|
}
|
|
68
91
|
|
|
69
|
-
|
|
92
|
+
// the answer shown after an empty Enter, and the question that follows: did you know it?
|
|
93
|
+
function Revealed({ question, nudge }) {
|
|
94
|
+
return html`
|
|
95
|
+
<${Box} flexDirection="column">
|
|
96
|
+
<${Text} color=${theme.accent} bold>${question.expected.join(" / ")}<//>
|
|
97
|
+
${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
|
|
98
|
+
<${Box} marginTop=${1}>
|
|
99
|
+
<${Text} bold>${t("quiz.didYouKnow")} <//>
|
|
100
|
+
<${Text} color=${nudge ? theme.warn : theme.text} bold=${nudge}>${t("quiz.gradeKeys")}<//>
|
|
101
|
+
<//>
|
|
102
|
+
<//>
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const BADGE_FIRST_MS = 400; // after the answer's own sound
|
|
107
|
+
const BADGE_STAGGER_MS = 700; // several badges at once light up one after another
|
|
108
|
+
|
|
109
|
+
function Cheers({ cheers, play }) {
|
|
110
|
+
const lines = cheers.filter((cheer) => cheer.kind !== "badge");
|
|
111
|
+
const badges = cheers.filter((cheer) => cheer.kind === "badge");
|
|
70
112
|
return html`
|
|
71
113
|
<${Box} flexDirection="column" paddingX=${1} marginTop=${1}>
|
|
72
|
-
${
|
|
114
|
+
${lines.map((cheer, i) => {
|
|
73
115
|
const style = CHEER_STYLE[cheer.kind] ?? CHEER_STYLE.combo;
|
|
74
116
|
return html`<${Text} key=${i} color=${style.color} bold>${style.icon} ${cheer.text}<//>`;
|
|
75
117
|
})}
|
|
118
|
+
${badges.map((badge, i) => html`<${BadgeUnlock} key=${badge.id} ...${badge} delay=${BADGE_FIRST_MS + i * BADGE_STAGGER_MS} sound=${badgeSound(i)} play=${play} />`)}
|
|
76
119
|
<//>
|
|
77
120
|
`;
|
|
78
121
|
}
|
|
79
122
|
|
|
80
123
|
// The card's top edge with the direction ("EN → PL") set into its right corner, like a title on the border
|
|
81
124
|
function CardTop({ label, width, color }) {
|
|
82
|
-
const tag = ` ${label} `;
|
|
83
125
|
const tail = 2;
|
|
84
|
-
const
|
|
126
|
+
const room = Math.max(4, width - 2 - tail - 4); // a label too long for a narrow window is cut short
|
|
127
|
+
const tag = ` ${cutToWidth(label, room)} `;
|
|
128
|
+
const dashes = Math.max(0, width - 2 - cellWidth(tag) - tail);
|
|
85
129
|
return html`
|
|
86
130
|
<${Text}>
|
|
87
131
|
<${Text} color=${color}>╭${"─".repeat(dashes)}<//>
|
|
@@ -91,24 +135,61 @@ function CardTop({ label, width, color }) {
|
|
|
91
135
|
`;
|
|
92
136
|
}
|
|
93
137
|
|
|
138
|
+
// "at 14:30", "tomorrow", "on 14 Oct"
|
|
139
|
+
function whenDue(at, now) {
|
|
140
|
+
const tomorrow = startOfTomorrow(now);
|
|
141
|
+
if (at < tomorrow) return t("quiz.when.at", { time: formatClock(at) });
|
|
142
|
+
return at < startOfTomorrow(tomorrow) ? t("quiz.when.tomorrow") : t("quiz.when.on", { day: formatDay(dayKey(at)) });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// what the quiz shows when the deck has nothing to ask: no countdown, just the way on
|
|
146
|
+
function EmptyDeck({ deck, tour, count, nextDue, dayDone, now, width }) {
|
|
147
|
+
const [title, next] = tour
|
|
148
|
+
? [t("quiz.empty.tourTitle"), t("quiz.empty.tourNext")]
|
|
149
|
+
: !count
|
|
150
|
+
? [t("quiz.empty.noCardsTitle", { deck }), t("quiz.empty.noCardsNext")]
|
|
151
|
+
: nextDue >= startOfTomorrow(now) && !dayDone
|
|
152
|
+
? [t("quiz.empty.deckDoneTitle", { deck }), t("quiz.empty.deckDoneNext", { when: whenDue(nextDue, now) })]
|
|
153
|
+
: nextDue >= startOfTomorrow(now)
|
|
154
|
+
? [t("quiz.empty.dayDoneTitle"), t("quiz.empty.dayDoneNext", { when: whenDue(nextDue, now) })]
|
|
155
|
+
: [t("quiz.empty.laterTitle"), t("quiz.empty.laterNext", { when: whenDue(nextDue, now) })];
|
|
156
|
+
return html`
|
|
157
|
+
<${Box} flexDirection="column" width=${width}>
|
|
158
|
+
<${CardTop} label=${deck} width=${width} color=${theme.accent} />
|
|
159
|
+
<${Box} flexDirection="column" borderStyle="round" borderTop=${false} borderColor=${theme.accent} paddingX=${2} paddingY=${1}>
|
|
160
|
+
<${Text} bold>${title}<//>
|
|
161
|
+
<${Text}>${next}<//>
|
|
162
|
+
<//>
|
|
163
|
+
<//>
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
|
|
94
167
|
function TipBox({ tip, width }) {
|
|
95
168
|
return html`
|
|
96
169
|
<${Box} flexDirection="column" paddingX=${1} marginTop=${2} width=${width}>
|
|
97
|
-
<${Box} marginBottom=${1}><${Text} color=${theme.accent}
|
|
170
|
+
<${Box} marginBottom=${1}><${Text} color=${theme.accent}>${t("quiz.tip", { cat: tip.cat })}<//><//>
|
|
98
171
|
<${Typewriter} text=${tip.text} dimColor />
|
|
99
172
|
<//>
|
|
100
173
|
`;
|
|
101
174
|
}
|
|
102
175
|
|
|
103
|
-
|
|
176
|
+
// `library` holds the /add actions (src/manage.js) and `onSwitchDeck` points the session at another
|
|
177
|
+
// deck; the preview gallery passes neither.
|
|
178
|
+
export function App({ session, deck: initialDeck, initialSettings, alerts, persistSettings, onExit, library, onSwitchDeck }) {
|
|
104
179
|
const { exit: exitApp } = useApp();
|
|
105
180
|
const exit = onExit ?? exitApp; // the preview gallery runs the quiz as a scene and takes quitting back to its menu
|
|
106
181
|
const { stdout } = useStdout();
|
|
107
182
|
const [settings, setSettings] = useState(initialSettings);
|
|
108
|
-
|
|
183
|
+
const [deck, setDeck] = useState(initialDeck);
|
|
184
|
+
const [addNew, setAddNew] = useState(false); // /add opened from "+ New deck" in /decks
|
|
185
|
+
const [restUntil, setRestUntil] = useState(null); // nothing is waiting until then (after the last card due now)
|
|
186
|
+
const [empty, setEmpty] = useState(null); // { tour, count, nextDue } when there is nothing to ask right now
|
|
187
|
+
// quiz | settings | reset | add | decks | stats | badges | companion | help | missed | evolve | the-one | die | summary | hatch
|
|
109
188
|
const [screen, setScreen] = useState(() => (session.isFirstRun() ? "hatch" : "quiz"));
|
|
110
189
|
const [tip, setTip] = useState(null);
|
|
111
|
-
const [phase, setPhase] = useState("loading"); // loading | asking | waiting
|
|
190
|
+
const [phase, setPhase] = useState("loading"); // loading | asking | grading (answer revealed) | waiting | empty
|
|
191
|
+
const [nudge, setNudge] = useState(false); // Enter while grading: the 1/2 keys light up
|
|
192
|
+
const [confirming, setConfirming] = useState(false); // /correct waits for yes or no
|
|
112
193
|
const [question, setQuestion] = useState(null);
|
|
113
194
|
const [outcome, setOutcome] = useState(null);
|
|
114
195
|
const [problem, setProblem] = useState("");
|
|
@@ -121,11 +202,19 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
121
202
|
const [petEvent, setPetEvent] = useState(null); // { kind: "jump" | "shake", at } → a little hop or head-shake
|
|
122
203
|
const [confetti, setConfetti] = useState(false);
|
|
123
204
|
const [evolution, setEvolution] = useState(null); // { from, to, name } while the ceremony plays
|
|
205
|
+
const [freshBadges, setFreshBadges] = useState([]); // won since /badges was last opened; they light up there
|
|
206
|
+
const [ceremonies, setCeremonies] = useState([]); // full-screen moments still to show: "evolve", "the-one"
|
|
124
207
|
const [lastActive, setLastActive] = useState(Date.now()); // last key press or new question: the dragon sleeps after a long gap
|
|
125
208
|
const busy = useRef(false);
|
|
209
|
+
const shownAt = useRef(0); // when the card or its revealed answer appeared (SETTLE_MS)
|
|
210
|
+
const sessionDone = useRef(0); // cards answered in this study session (the "session" rhythm)
|
|
211
|
+
const [sessionWait, setSessionWait] = useState(false); // waiting for Enter, not for the clock
|
|
126
212
|
const asleepRef = useRef(false);
|
|
127
213
|
const bestCombo = useRef(0);
|
|
128
214
|
const settingsRef = useRef(settings);
|
|
215
|
+
const tourSync = useRef(Promise.resolve());
|
|
216
|
+
const deckRef = useRef(deck);
|
|
217
|
+
deckRef.current = deck;
|
|
129
218
|
settingsRef.current = settings;
|
|
130
219
|
const snoozeRef = useRef(0);
|
|
131
220
|
snoozeRef.current = snoozeUntil;
|
|
@@ -136,10 +225,17 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
136
225
|
return Math.max(snoozeRef.current > t ? snoozeRef.current : 0, inQuietHours(t, quiet) ? quietEnd(t, quiet) : 0);
|
|
137
226
|
};
|
|
138
227
|
|
|
139
|
-
|
|
140
|
-
|
|
228
|
+
// `nextDue`: nothing is waiting until then, so the next question waits for it (never sooner than usual).
|
|
229
|
+
// In a study session Enter asks the next card instead of the clock, until the set number is done.
|
|
230
|
+
const waitForNext = useCallback((nextDue = null) => {
|
|
231
|
+
const usual = Date.now() + settingsRef.current.everyMs;
|
|
232
|
+
const length = sessionLength(settingsRef.current.rhythm);
|
|
233
|
+
const studying = settingsRef.current.rhythm !== "minutes" && !nextDue && (length === null || sessionDone.current < length);
|
|
234
|
+
setSessionWait(studying);
|
|
235
|
+
setNextAt(studying ? Infinity : nextDue ? Math.max(nextDue, usual) : usual);
|
|
236
|
+
setRestUntil(nextDue);
|
|
141
237
|
setPhase("waiting");
|
|
142
|
-
setTip(shouldShowTip(settingsRef.current.tips) ? session.nextTip() : null);
|
|
238
|
+
setTip(!session.inTour() && shouldShowTip(settingsRef.current.tips) ? session.nextTip() : null);
|
|
143
239
|
}, [session]);
|
|
144
240
|
|
|
145
241
|
const ask = useCallback(async () => {
|
|
@@ -149,14 +245,24 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
149
245
|
setNotice("");
|
|
150
246
|
setHintLevel(0);
|
|
151
247
|
setCommandMode(false);
|
|
248
|
+
setConfirming(false);
|
|
152
249
|
try {
|
|
153
250
|
const next = await session.next();
|
|
154
251
|
setQuestion(next);
|
|
155
252
|
setOutcome(null);
|
|
253
|
+
setEmpty(null);
|
|
254
|
+
shownAt.current = Date.now();
|
|
156
255
|
setPhase("asking");
|
|
157
256
|
} catch (err) {
|
|
158
|
-
|
|
159
|
-
|
|
257
|
+
if (!err.empty) {
|
|
258
|
+
setProblem(err.message);
|
|
259
|
+
return waitForNext();
|
|
260
|
+
}
|
|
261
|
+
setQuestion(null);
|
|
262
|
+
setEmpty({ tour: err.tour, count: err.count, nextDue: err.nextDue, dayDone: err.dayDone });
|
|
263
|
+
setOutcome(err.cheers.length ? { result: "done", cheers: err.cheers } : null);
|
|
264
|
+
if (err.cheers.length) celebrate({ result: "exact", cheers: err.cheers, combo: session.totals.combo });
|
|
265
|
+
setPhase("empty");
|
|
160
266
|
}
|
|
161
267
|
}, [session, waitForNext]);
|
|
162
268
|
|
|
@@ -170,13 +276,29 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
170
276
|
return () => clearInterval(id);
|
|
171
277
|
}, []);
|
|
172
278
|
|
|
279
|
+
// with nothing to practise, the quiz picks up again by itself once the next card is due
|
|
173
280
|
useEffect(() => {
|
|
174
|
-
if (phase !== "
|
|
281
|
+
if (phase !== "empty" || !empty?.nextDue || screen !== "quiz" || confirming || now < empty.nextDue || pauseEnd(now)) return;
|
|
282
|
+
alerts.ask();
|
|
283
|
+
ask();
|
|
284
|
+
}, [now, phase, empty, screen, confirming, ask, alerts]);
|
|
285
|
+
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
// a /correct question stays open: the next card waits for its answer
|
|
288
|
+
if (phase !== "waiting" || confirming || screen === "summary" || screen === "evolve" || screen === "the-one" || screen === "die") return;
|
|
175
289
|
if (now >= nextAt && !pauseEnd(now)) {
|
|
176
290
|
alerts.ask();
|
|
177
291
|
ask();
|
|
178
292
|
}
|
|
179
|
-
}, [now, phase, nextAt, screen, ask, alerts]);
|
|
293
|
+
}, [now, phase, nextAt, screen, confirming, ask, alerts]);
|
|
294
|
+
|
|
295
|
+
// Esc on an empty line is easy to press by habit: it quits only when pressed twice in a row
|
|
296
|
+
const escArmed = useRef(0);
|
|
297
|
+
const escapeExit = () => {
|
|
298
|
+
if (Date.now() - escArmed.current < 3000) return requestExit();
|
|
299
|
+
escArmed.current = Date.now();
|
|
300
|
+
setNotice(t("quiz.escAgain"));
|
|
301
|
+
};
|
|
180
302
|
|
|
181
303
|
// quitting goes through the session summary when there is anything to sum up
|
|
182
304
|
const requestExit = useCallback(() => {
|
|
@@ -190,11 +312,29 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
190
312
|
setLastActive(Date.now());
|
|
191
313
|
});
|
|
192
314
|
|
|
315
|
+
// the answer is revealed: you say whether you knew it. 1/2 or ←/→ (AZERTY's digits need Shift, so
|
|
316
|
+
// & and é too); Esc is "didn't know"; Enter never grades, it only shows the keys again
|
|
317
|
+
useInput((input, key) => {
|
|
318
|
+
if (screen !== "quiz" || phase !== "grading" || asleepRef.current || Date.now() - shownAt.current < SETTLE_MS) return;
|
|
319
|
+
if (input === "1" || input === "&" || key.leftArrow || key.escape) return gradeSelf(false);
|
|
320
|
+
if (input === "2" || input === "é" || key.rightArrow) return gradeSelf(true);
|
|
321
|
+
if (key.return) setNudge(true);
|
|
322
|
+
});
|
|
323
|
+
|
|
193
324
|
useInput((input, key) => {
|
|
194
|
-
|
|
325
|
+
// only the yes key accepts: Enter is too easy to press twice after "/correct" from the menu
|
|
326
|
+
if (screen !== "quiz" || !confirming || asleepRef.current) return;
|
|
327
|
+
const is = (keys) => t(keys).split("|").includes(input.toLowerCase());
|
|
328
|
+
if (is("choice.yesKey")) return overrule();
|
|
329
|
+
if (is("choice.noKey") || key.escape) setConfirming(false);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
useInput((input, key) => {
|
|
333
|
+
if (screen !== "quiz" || (phase !== "waiting" && phase !== "empty") || commandMode || confirming) return;
|
|
195
334
|
if (input === "/") return setCommandMode(true);
|
|
196
|
-
if (
|
|
197
|
-
if (key.
|
|
335
|
+
if (input === "q") return requestExit();
|
|
336
|
+
if (key.escape) return escapeExit();
|
|
337
|
+
if (key.return && phase === "waiting" && !busy.current) ask();
|
|
198
338
|
});
|
|
199
339
|
|
|
200
340
|
const clearProblem = useCallback(() => {
|
|
@@ -208,53 +348,82 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
208
348
|
bestCombo.current = Math.max(bestCombo.current, result.combo);
|
|
209
349
|
setPetEvent({ kind: result.result === "wrong" ? "shake" : "jump", at: Date.now() });
|
|
210
350
|
if (result.cheers.some((c) => c.kind === "goal")) setConfetti(true);
|
|
351
|
+
const queue = [];
|
|
211
352
|
if (result.cheers.some((c) => c.kind === "evolve")) {
|
|
212
353
|
const companion = session.stats().companion;
|
|
213
|
-
setEvolution({ from: Math.max(0, companion.index - 1), to: companion.index, name: companion.name });
|
|
214
|
-
|
|
354
|
+
setEvolution({ from: Math.max(0, companion.index - 1), to: companion.index, name: companion.name, element: companion.element });
|
|
355
|
+
queue.push("evolve");
|
|
356
|
+
}
|
|
357
|
+
if (result.cheers.some((c) => c.id === "dragons-die")) queue.push("die");
|
|
358
|
+
if (result.cheers.some((c) => c.id === "one-ring")) queue.push("the-one");
|
|
359
|
+
if (queue.length) {
|
|
360
|
+
setCeremonies(queue.slice(1));
|
|
361
|
+
setScreen(queue[0]);
|
|
215
362
|
}
|
|
216
363
|
}
|
|
217
364
|
|
|
365
|
+
// after a full-screen ceremony: the next one if both happened at once, otherwise back to the quiz
|
|
366
|
+
function nextCeremony() {
|
|
367
|
+
const [next, ...rest] = ceremonies;
|
|
368
|
+
setCeremonies(rest);
|
|
369
|
+
setScreen(next ?? "quiz");
|
|
370
|
+
}
|
|
371
|
+
|
|
218
372
|
function runCommand(name, args = "") {
|
|
219
373
|
setCommandMode(false);
|
|
220
374
|
if (name === "/quit") return requestExit();
|
|
221
375
|
if (name === "/settings") return setScreen("settings");
|
|
222
376
|
if (name === "/stats") return setScreen("stats");
|
|
223
|
-
if (name === "/badges")
|
|
377
|
+
if (name === "/badges") {
|
|
378
|
+
return session
|
|
379
|
+
.openBadges()
|
|
380
|
+
.then((fresh) => {
|
|
381
|
+
setFreshBadges(fresh);
|
|
382
|
+
setScreen("badges");
|
|
383
|
+
})
|
|
384
|
+
.catch((err) => setProblem(err.message));
|
|
385
|
+
}
|
|
224
386
|
if (name === "/companion") return setScreen("companion");
|
|
225
|
-
if (name === "/tip") return setScreen("tip");
|
|
226
387
|
if (name === "/missed") return setScreen("missed");
|
|
388
|
+
if (name === "/help") return setScreen("help");
|
|
389
|
+
if (name === "/add") return library ? (setAddNew(false), setScreen("add")) : setNotice(t("quiz.previewNoAdd"));
|
|
390
|
+
if (name === "/decks") return library ? setScreen("decks") : setNotice(t("quiz.previewNoDecks"));
|
|
227
391
|
if (name === "/hint" && phase === "asking") return setHintLevel((level) => level + 1);
|
|
228
|
-
if (name === "/
|
|
392
|
+
if (name === "/pause") {
|
|
229
393
|
return session
|
|
230
|
-
.
|
|
231
|
-
.then(
|
|
394
|
+
.pause(args)
|
|
395
|
+
.then(({ snooze, list, message }) => {
|
|
396
|
+
if (snooze === "off") setSnoozeUntil(0);
|
|
397
|
+
if (typeof snooze === "number") {
|
|
398
|
+
setSnoozeUntil(Date.now() + snooze);
|
|
399
|
+
return phase === "asking" ? setNotice(t("quiz.pausedUntilNotice", { time: formatClock(Date.now() + snooze) })) : undefined; // while waiting, the status line says it
|
|
400
|
+
}
|
|
401
|
+
const paused = list && snoozeRef.current > Date.now() ? t("quiz.pausedUntilList", { time: formatClock(snoozeRef.current) }) : "";
|
|
402
|
+
setNotice(paused + message);
|
|
403
|
+
})
|
|
232
404
|
.catch((err) => setProblem(err.message));
|
|
233
405
|
}
|
|
234
|
-
if (name === "/
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (name === "/skip") {
|
|
245
|
-
setOutcome({ result: "skipped", cheers: [] });
|
|
246
|
-
return waitForNext();
|
|
247
|
-
}
|
|
248
|
-
if (name === "/correct" && session.canOverrule()) {
|
|
249
|
-
return session
|
|
406
|
+
if (name === "/correct" && session.canOverrule()) return setConfirming(true); // asked first: a misclick would accept the answer for good
|
|
407
|
+
setProblem(t("quiz.unknownCommand", { name }));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// /correct, confirmed: the last answer counts as right and is accepted from now on
|
|
411
|
+
function overrule() {
|
|
412
|
+
setConfirming(false);
|
|
413
|
+
if (busy.current) return;
|
|
414
|
+
busy.current = true;
|
|
415
|
+
return session
|
|
250
416
|
.overrule()
|
|
251
417
|
.then((result) => {
|
|
252
418
|
setOutcome(result);
|
|
253
419
|
celebrate(result);
|
|
420
|
+
if (phase === "empty") return ask(); // the card's next date changed: look again
|
|
421
|
+
waitForNext(result.nextDue);
|
|
254
422
|
})
|
|
255
|
-
.catch((err) => setProblem(
|
|
256
|
-
|
|
257
|
-
|
|
423
|
+
.catch((err) => setProblem(t("quiz.saveFailed", { error: err.message })))
|
|
424
|
+
.finally(() => {
|
|
425
|
+
busy.current = false;
|
|
426
|
+
});
|
|
258
427
|
}
|
|
259
428
|
|
|
260
429
|
function changeSettings(patch) {
|
|
@@ -265,38 +434,124 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
265
434
|
alerts.configure({ sound: next.sound, volume: next.volume });
|
|
266
435
|
persistSettings(patch).catch(() => {});
|
|
267
436
|
if (patch.everyMs && phase === "waiting") setNextAt((at) => at - previous.everyMs + patch.everyMs);
|
|
437
|
+
if (patch.rhythm) {
|
|
438
|
+
sessionDone.current = 0;
|
|
439
|
+
if (phase === "waiting" && !restUntil) waitForNext(); // the wait follows the new rhythm right away
|
|
440
|
+
}
|
|
268
441
|
if (patch.volume !== undefined || patch.sound === true) alerts.play("correct-0"); // audible preview
|
|
442
|
+
if (patch.language) changeLanguage(patch.language);
|
|
269
443
|
}
|
|
270
444
|
|
|
445
|
+
// Every text follows at the next render; the tour is translated too, and asked again in the new
|
|
446
|
+
// language. One translation at a time, so flicking through languages ends on the last one.
|
|
447
|
+
function changeLanguage(lang) {
|
|
448
|
+
setLanguage(lang);
|
|
449
|
+
if (!library) return;
|
|
450
|
+
tourSync.current = tourSync.current
|
|
451
|
+
.then(() => library.matchTourLanguage())
|
|
452
|
+
.then((renamed) => {
|
|
453
|
+
if (!renamed) return;
|
|
454
|
+
if (deckRef.current === renamed.from) {
|
|
455
|
+
deckRef.current = renamed.to;
|
|
456
|
+
onSwitchDeck?.(renamed.to);
|
|
457
|
+
setDeck(renamed.to);
|
|
458
|
+
}
|
|
459
|
+
if (phase === "asking" && question?.tour) ask();
|
|
460
|
+
})
|
|
461
|
+
.catch(() => {});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// An empty answer reveals the card, and you grade yourself (gradeSelf). An empty Enter right after the
|
|
465
|
+
// card appeared is the second half of the Enter that asked it: ignored.
|
|
271
466
|
async function submit(raw) {
|
|
272
467
|
const text = raw.trim();
|
|
273
|
-
if (
|
|
468
|
+
if (busy.current) return;
|
|
469
|
+
if (!text) {
|
|
470
|
+
if (Date.now() - shownAt.current < SETTLE_MS) return;
|
|
471
|
+
session.reveal(question);
|
|
472
|
+
shownAt.current = Date.now();
|
|
473
|
+
setNudge(false);
|
|
474
|
+
return setPhase("grading");
|
|
475
|
+
}
|
|
476
|
+
await settle(() => session.answer(question, text, { hinted: hintLevel > 0 }));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const gradeSelf = (knew) => settle(() => session.selfGrade(question, knew, { hinted: hintLevel > 0 }));
|
|
480
|
+
|
|
481
|
+
// a graded answer: the verdict, the celebration, then the wait for the next card
|
|
482
|
+
async function settle(grading) {
|
|
483
|
+
if (busy.current) return;
|
|
274
484
|
busy.current = true;
|
|
485
|
+
let nextDue = null;
|
|
275
486
|
try {
|
|
276
|
-
const result = await
|
|
487
|
+
const result = await grading();
|
|
488
|
+
nextDue = result.nextDue;
|
|
489
|
+
sessionDone.current += 1;
|
|
490
|
+
const length = sessionLength(settingsRef.current.rhythm);
|
|
491
|
+
if (length !== null && sessionDone.current === length) setNotice(t("quiz.sessionDone", { count: length }));
|
|
277
492
|
setOutcome(result);
|
|
278
493
|
celebrate(result);
|
|
279
494
|
} catch (err) {
|
|
280
|
-
setProblem(
|
|
495
|
+
setProblem(t("quiz.saveFailed", { error: err.message }));
|
|
281
496
|
} finally {
|
|
282
497
|
busy.current = false;
|
|
283
|
-
waitForNext();
|
|
498
|
+
waitForNext(nextDue);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// /decks and a first deck from /add: quiz another deck from now on, and remember it
|
|
503
|
+
function switchDeck(name) {
|
|
504
|
+
setScreen("quiz");
|
|
505
|
+
if (name === deck) return;
|
|
506
|
+
onSwitchDeck?.(name);
|
|
507
|
+
setDeck(name);
|
|
508
|
+
changeSettings({ deck: name });
|
|
509
|
+
ask();
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Reset (from /settings), after a backup. Everything brings back the tour and the hatching egg.
|
|
513
|
+
async function reset(scope) {
|
|
514
|
+
await library.backupBeforeReset();
|
|
515
|
+
await session.reset(scope);
|
|
516
|
+
setFreshBadges([]);
|
|
517
|
+
if (scope === "progress") {
|
|
518
|
+
setScreen("quiz");
|
|
519
|
+
return setNotice(t("quiz.progressReset"));
|
|
284
520
|
}
|
|
521
|
+
const tour = await library.resetLibrary();
|
|
522
|
+
onSwitchDeck?.(tour);
|
|
523
|
+
setDeck(tour);
|
|
524
|
+
changeSettings({ deck: null });
|
|
525
|
+
setScreen("hatch");
|
|
526
|
+
ask();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// after /add: a first deck of your own replaces the tour; a deck started from /decks (or in place
|
|
530
|
+
// of an empty one) becomes the one you practise; new cards end an empty state
|
|
531
|
+
function addDone({ deck: started, removed, stale = [], added, dropped }) {
|
|
532
|
+
setScreen("quiz");
|
|
533
|
+
if (removed.length) session.forget(removed).catch(() => {});
|
|
534
|
+
if (stale.length) session.forgetKeys(stale).catch(() => {});
|
|
535
|
+
const switching = started && (removed.length || phase === "empty" || addNew);
|
|
536
|
+
if (switching) switchDeck(started);
|
|
537
|
+
else if (phase === "empty" && added) ask();
|
|
538
|
+
const notes = [dropped && t("quiz.cardNotSaved"), started && !switching && t("quiz.deckReadyElsewhere", { deck: started, current: deck })];
|
|
539
|
+
setNotice(notes.filter(Boolean).join(" ")); // after ask(), which clears the notice
|
|
285
540
|
}
|
|
286
541
|
|
|
287
|
-
const width =
|
|
288
|
-
const border = !outcome ? theme.accent : outcome.result === "wrong" ? theme.bad :
|
|
542
|
+
const width = usePanelWidth();
|
|
543
|
+
const border = !outcome ? theme.accent : outcome.result === "wrong" ? theme.bad : theme.good;
|
|
289
544
|
const pausedUntil = pauseEnd(now);
|
|
290
545
|
const tick = Math.floor(now / TICK_MS);
|
|
291
546
|
const frame = SPINNER[tick % SPINNER.length];
|
|
292
547
|
const stats = session.stats();
|
|
293
548
|
// mood: how the last answer went, otherwise whether today's goal is done (Header adds the blinking)
|
|
294
549
|
const resting = stats.today.goalMet ? "smile" : "idle";
|
|
295
|
-
const face = outcome?.result === "wrong" ? "sad" : outcome
|
|
550
|
+
const face = outcome?.result === "wrong" ? "sad" : outcome ? "happy" : resting;
|
|
296
551
|
// strictly boolean: a bare 0 leaking into the markup crashes Ink ("Text string must be rendered inside <Text>")
|
|
297
552
|
const paused = pausedUntil > nextAt || (now >= nextAt && pausedUntil > 0);
|
|
298
553
|
// asleep: no key pressed for a while, whether a question is open or not; a key always wakes it,
|
|
299
|
-
// even during
|
|
554
|
+
// even during a pause or quiet hours (where it nods off again sooner)
|
|
300
555
|
const idleLimit = phase === "waiting" && pausedUntil > 0 ? PAUSED_SLEEP_AFTER_MS : SLEEP_AFTER_MS;
|
|
301
556
|
const asleep = phase !== "loading" && now - lastActive > idleLimit;
|
|
302
557
|
asleepRef.current = asleep;
|
|
@@ -310,56 +565,72 @@ export function App({ session, deck, initialSettings, alerts, persistSettings, o
|
|
|
310
565
|
if (screen === "evolve" && evolution)
|
|
311
566
|
return html`<${Box} flexDirection="column" marginY=${1}><${Evolution} ...${evolution} onClose=${() => {
|
|
312
567
|
setEvolution(null);
|
|
313
|
-
|
|
568
|
+
nextCeremony();
|
|
314
569
|
}} /><//>`;
|
|
570
|
+
if (screen === "die")
|
|
571
|
+
return html`<${Box} flexDirection="column" marginY=${1}><${DieRoll} element=${stats.companion.element} stage=${stats.companion.index} play=${alerts.play} onClose=${nextCeremony} /><//>`;
|
|
572
|
+
if (screen === "the-one") return html`<${Box} flexDirection="column" marginY=${1}><${TheOne} play=${alerts.play} onClose=${nextCeremony} /><//>`;
|
|
315
573
|
if (screen === "stats") return html`<${Box} flexDirection="column" marginY=${1}><${Stats} stats=${stats} getMonth=${session.month} onClose=${() => setScreen("quiz")} /><//>`;
|
|
316
|
-
if (screen === "companion") return html`<${Box} flexDirection="column" marginY=${1}><${Companion} current=${stats.companion.index} best=${stats.streak.best} onClose=${() => setScreen("quiz")} /><//>`;
|
|
317
|
-
if (screen === "
|
|
574
|
+
if (screen === "companion") return html`<${Box} flexDirection="column" marginY=${1}><${Companion} current=${stats.companion.index} best=${stats.streak.best} element=${stats.companion.element} roll=${stats.companion.roll} onClose=${() => setScreen("quiz")} /><//>`;
|
|
575
|
+
if (screen === "help") return html`<${Box} flexDirection="column" marginY=${1}><${Help} onClose=${() => setScreen("quiz")} /><//>`;
|
|
318
576
|
if (screen === "missed") return html`<${Box} flexDirection="column" marginY=${1}><${Missed} getMissed=${session.missed} onClose=${() => setScreen("quiz")} /><//>`;
|
|
319
|
-
if (screen === "badges") return html`<${Box} flexDirection="column" marginY=${1}><${Badges} badges=${stats.badges} onClose=${() => setScreen("quiz")} /><//>`;
|
|
577
|
+
if (screen === "badges") return html`<${Box} flexDirection="column" marginY=${1}><${Badges} badges=${stats.badges} fresh=${freshBadges} onClose=${() => setScreen("quiz")} /><//>`;
|
|
320
578
|
|
|
321
579
|
return html`
|
|
322
580
|
<${Box} flexDirection="column" marginY=${1}>
|
|
323
|
-
<${Header} deck=${deck} everyMs=${settings.everyMs} wordCount=${question?.wordCount} stats=${stats} combo=${session.totals.combo} face=${face} event=${petEvent} tick=${tick} asleep=${asleep} />
|
|
581
|
+
<${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} />
|
|
324
582
|
<${Box} marginTop=${1} flexDirection="column">
|
|
325
|
-
${screen === "settings"
|
|
326
|
-
|
|
327
|
-
|
|
583
|
+
${screen === "settings" && html`<${Settings} settings=${settings} onChange=${changeSettings} onClose=${() => setScreen("quiz")} onAction=${library ? () => setScreen("reset") : null} />`}
|
|
584
|
+
${screen === "reset" && html`<${Reset} stats=${stats} actions=${library} onConfirm=${reset} onClose=${() => setScreen("settings")} />`}
|
|
585
|
+
${screen === "add" && html`<${AddCard} current=${deck} actions=${library} onDone=${addDone} startNew=${addNew} />`}
|
|
586
|
+
${screen === "decks" && html`<${Decks} current=${deck} actions=${library} onDirections=${async (cardIds, directions) => {
|
|
587
|
+
await session.setDirections(cardIds, directions);
|
|
588
|
+
if (phase === "asking" && question && cardIds.includes(question.word.noteId)) ask(); // the open card follows the new way at once
|
|
589
|
+
}} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onClose=${() => setScreen("quiz")} />`}
|
|
590
|
+
${!["settings", "reset", "add", "decks"].includes(screen) &&
|
|
591
|
+
html`
|
|
328
592
|
<${Fragment}>
|
|
329
593
|
${question &&
|
|
330
594
|
html`
|
|
331
595
|
<${Box} flexDirection="column" width=${width}>
|
|
332
596
|
<${CardTop} label=${question.label} width=${width} color=${border} />
|
|
333
597
|
<${Box} flexDirection="column" borderStyle="round" borderTop=${false} borderColor=${border} paddingX=${2} paddingTop=${1}>
|
|
334
|
-
<${
|
|
335
|
-
${
|
|
598
|
+
<${Marked} bold text=${question.prompt} plain=${!question.tour} />
|
|
599
|
+
${question.context && html`<${Text} dimColor>(${question.context})<//>`}
|
|
600
|
+
${phase === "asking" && hintLevel > 0 && html`<${Text} dimColor>${t("quiz.hintLabel")} ${makeHint(hintTarget(question.expected), hintLevel)}<//>`}
|
|
336
601
|
<${Box} marginTop=${1} flexDirection="column">
|
|
337
|
-
${phase === "asking" && html`<${AnswerInput} key=${question.word.noteId + question.direction} onSubmit=${submit} onCommand=${runCommand} onExit=${
|
|
338
|
-
${phase
|
|
602
|
+
${phase === "asking" && html`<${AnswerInput} key=${question.word.noteId + question.direction} onSubmit=${submit} onCommand=${runCommand} onExit=${escapeExit} onEdit=${clearProblem} commands=${commandsFor({ phase: "asking" })} />`}
|
|
603
|
+
${phase === "grading" && html`<${Revealed} question=${question} nudge=${nudge} />`}
|
|
604
|
+
${phase !== "asking" && phase !== "grading" && outcome && html`<${Verdict} outcome=${outcome} question=${question} />`}
|
|
339
605
|
<//>
|
|
340
606
|
<//>
|
|
341
607
|
<//>
|
|
342
608
|
`}
|
|
609
|
+
${phase === "empty" && html`<${EmptyDeck} deck=${deck} ...${empty} now=${now} width=${width} />`}
|
|
343
610
|
${confetti && html`<${Confetti} width=${width} onDone=${() => setConfetti(false)} />`}
|
|
344
|
-
${outcome?.cheers?.length > 0 && html`<${Cheers} cheers=${outcome.cheers} />`}
|
|
611
|
+
${outcome?.cheers?.length > 0 && html`<${Cheers} cheers=${outcome.cheers} play=${alerts.play} />`}
|
|
345
612
|
${phase === "waiting" && tip && html`<${TipBox} tip=${tip} width=${width} />`}
|
|
346
613
|
<${Box} paddingX=${1} marginTop=${1} flexDirection="column">
|
|
347
|
-
${question?.cached && html`<${Text} color=${theme.warn}>Anki is offline, using the saved word list<//>`}
|
|
348
614
|
${problem && html`<${Text} color=${theme.bad}>${problem}<//>`}
|
|
349
|
-
${phase === "loading" && html`<${Text}
|
|
615
|
+
${phase === "loading" && html`<${Text}><${Text} color=${theme.accent}>${frame}<//><${Text} dimColor>${t("quiz.loading")}<//><//>`}
|
|
350
616
|
${notice && html`<${Text} color=${theme.accent}>${notice}<//>`}
|
|
351
|
-
${
|
|
617
|
+
${confirming && html`<${Text} color=${theme.warn}>${t("quiz.correctConfirm", { answer: session.wrongAnswer() })}<//>`}
|
|
618
|
+
${phase === "waiting" && paused && html`<${Text} dimColor>${t("quiz.pausedUntil", { time: formatClock(pausedUntil) })}${inQuietHours(now, settings.quiet) ? t("quiz.quietHours") : ""}<//>`}
|
|
619
|
+
${phase === "waiting" && !paused && restUntil && nextAt - now > settings.everyMs && html`<${Text} dimColor>${t("quiz.nothingWaiting", { when: whenDue(restUntil, now) })}<//>`}
|
|
620
|
+
${phase === "waiting" && !paused && sessionWait && sessionLength(settings.rhythm) && html`<${Text} dimColor>${t("quiz.sessionProgress", { done: sessionDone.current, count: sessionLength(settings.rhythm) })}<//>`}
|
|
352
621
|
${phase === "waiting" &&
|
|
353
622
|
!paused &&
|
|
623
|
+
!sessionWait &&
|
|
624
|
+
!(restUntil && nextAt - now > settings.everyMs) &&
|
|
354
625
|
html`
|
|
355
626
|
<${Text}>
|
|
356
|
-
<${Text}
|
|
627
|
+
<${Text} color=${theme.accent}>${frame} <//>
|
|
357
628
|
<${Bar} value=${Math.max(0, nextAt - now)} max=${settings.everyMs} width=${14} color="#6b5e8a" />
|
|
358
|
-
<${Text} dimColor
|
|
629
|
+
<${Text} dimColor>${t("quiz.nextCardIn", { time: clock(nextAt - now) })}<//>
|
|
359
630
|
<//>
|
|
360
631
|
`}
|
|
361
|
-
${phase === "waiting" && commandMode && html`<${AnswerInput} commandOnly initial="/" commands=${commandsFor({ phase: "waiting", canOverrule: session.canOverrule() })} onCommand=${runCommand} onCancel=${() => setCommandMode(false)} onEdit=${clearProblem} />`}
|
|
362
|
-
${phase !== "loading" && !commandMode && html`<${
|
|
632
|
+
${(phase === "waiting" || phase === "empty") && commandMode && html`<${AnswerInput} commandOnly initial="/" commands=${commandsFor({ phase: "waiting", canOverrule: session.canOverrule() })} onCommand=${runCommand} onCancel=${() => setCommandMode(false)} onEdit=${clearProblem} />`}
|
|
633
|
+
${phase !== "loading" && !commandMode && html`<${KeyHints} text=${confirming ? t("keyHints.confirm", { yes: t("choice.yesKey").split("|")[0], no: t("choice.noKey").split("|")[0] }) : phase === "grading" ? t("keyHints.grading") : phase === "asking" ? t("keyHints.asking") : phase === "empty" ? t("keyHints.empty") : session.canOverrule() ? t("keyHints.correctFirst", { rest: t(sessionWait ? "keyHints.sessionWaiting" : "keyHints.waiting") }) : t(sessionWait ? "keyHints.sessionWaiting" : "keyHints.waiting")} />`}
|
|
363
634
|
<//>
|
|
364
635
|
<//>
|
|
365
636
|
`}
|