dracosh 0.5.0 → 0.7.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 +22 -9
- package/locales/de.json +215 -21
- package/locales/en.json +215 -21
- package/locales/fr.json +231 -22
- package/locales/pl.json +245 -21
- package/locales/uk.json +248 -24
- package/package.json +3 -2
- package/src/backup.js +10 -1
- package/src/cli.js +14 -7
- package/src/commands.js +3 -0
- package/src/firstwords.js +49 -0
- package/src/judge.js +1 -1
- package/src/language.js +11 -6
- package/src/library.js +122 -2
- package/src/manage.js +149 -4
- package/src/progress.js +12 -4
- package/src/scheduler.js +107 -15
- package/src/session.js +59 -17
- package/src/settings.js +7 -1
- package/src/store.js +33 -9
- package/src/transfer.js +22 -5
- package/src/ui/AddCard.js +13 -11
- package/src/ui/AnswerInput.js +24 -3
- package/src/ui/App.js +242 -18
- package/src/ui/Cards.js +236 -0
- package/src/ui/Choice.js +6 -1
- package/src/ui/Decks.js +181 -15
- package/src/ui/Help.js +2 -3
- package/src/ui/Import.js +316 -0
- package/src/ui/Languages.js +48 -9
- package/src/ui/Preview.js +22 -1
- package/src/ui/Settings.js +18 -6
- package/src/ui/Trash.js +63 -0
- package/src/ui/Welcome.js +79 -0
- package/src/words.js +27 -4
package/src/ui/Languages.js
CHANGED
|
@@ -128,40 +128,79 @@ export function LanguagePicker({ deck, sample, languages, learning = null, home,
|
|
|
128
128
|
`;
|
|
129
129
|
|
|
130
130
|
const example = sample ? cutToWidth(side === "front" ? sample.front : sample.back.join(" / "), 24) : "";
|
|
131
|
-
const top = Math.max(0, Math.min(selected - Math.floor(SHOWN / 2), options.length - SHOWN));
|
|
132
131
|
const noteOf = (code) => {
|
|
133
132
|
if (code === UNKNOWN) return t("languages.mixedNote");
|
|
134
133
|
if (code !== languages[side]) return "";
|
|
135
134
|
return languages.guessed ? t("languages.guessed") : t("languages.current");
|
|
136
135
|
};
|
|
136
|
+
return html`<${LanguageList} title=${t(side === "front" ? "languages.frontQuestion" : "languages.backQuestion", { deck })} note=${example && t("languages.example", { sample: example })} query=${query} options=${options} selected=${selected} noteOf=${noteOf} />`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// the search and its list, as both pickers show them; `nameOf` names an option (a language by default)
|
|
140
|
+
// `step`: where in a series of questions this one is ("2/4"), said in the key hints
|
|
141
|
+
function LanguageList({ title, note, query, options, selected, noteOf, noMatch = options.length === 0, step = "", nameOf = (code) => (code === UNKNOWN ? t("languages.mixed") : languageName(code)) }) {
|
|
142
|
+
const panel = usePanelWidth();
|
|
143
|
+
const top = Math.max(0, Math.min(selected - Math.floor(SHOWN / 2), options.length - SHOWN));
|
|
137
144
|
return html`
|
|
138
145
|
<${Fragment}>
|
|
139
146
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
140
|
-
<${Text} bold color=${theme.accent}>${
|
|
141
|
-
${
|
|
147
|
+
<${Text} bold color=${theme.accent}>${title}<//>
|
|
148
|
+
${note && html`<${Text} dimColor>${note}<//>`}
|
|
142
149
|
<${Box} marginTop=${1}>
|
|
143
150
|
<${Box} flexShrink=${0}><${Text} dimColor>${t("languages.search")} <//><//>
|
|
144
151
|
<${Text} wrap="truncate-start">${query}<//>
|
|
145
152
|
<${Box} flexShrink=${0}><${Text} inverse> <//><//>
|
|
146
153
|
<//>
|
|
147
154
|
<${Box} flexDirection="column">
|
|
148
|
-
${
|
|
155
|
+
${noMatch && html`<${Text} dimColor wrap="truncate-end">${t("languages.noMatch", { query: cutToWidth(query, 20) })}<//>`}
|
|
149
156
|
<${Text} dimColor>${top > 0 ? " ↑" : " "}<//>
|
|
150
157
|
${options.slice(top, top + SHOWN).map((code, i) => {
|
|
151
158
|
const on = top + i === selected;
|
|
152
|
-
const
|
|
153
|
-
const note = noteOf(code);
|
|
159
|
+
const extra = noteOf(code);
|
|
154
160
|
return html`
|
|
155
161
|
<${Box} key=${code}>
|
|
156
|
-
<${Box} flexShrink=${0}><${Text} color=${on ? theme.accent : undefined} bold=${on}>${on ? "❯" : " "} ${
|
|
157
|
-
${
|
|
162
|
+
<${Box} flexShrink=${0}><${Text} color=${on ? theme.accent : undefined} bold=${on}>${on ? "❯" : " "} ${nameOf(code)}<//><//>
|
|
163
|
+
${extra && html`<${Text} dimColor wrap="truncate-end"> ${extra}<//>`}
|
|
158
164
|
<//>
|
|
159
165
|
`;
|
|
160
166
|
})}
|
|
161
167
|
<${Text} dimColor>${top + SHOWN < options.length ? " ↓" : " "}<//>
|
|
162
168
|
<//>
|
|
163
169
|
<//>
|
|
164
|
-
<${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.languagePick")} /><//>
|
|
170
|
+
<${Box} paddingX=${1}><${KeyHints} text=${step ? `${step} · ${t("keyHints.languagePick")}` : t("keyHints.languagePick")} /><//>
|
|
165
171
|
<//>
|
|
166
172
|
`;
|
|
167
173
|
}
|
|
174
|
+
|
|
175
|
+
// One language, asked with a search (the welcome, /settings): `current` selected to begin with, and
|
|
176
|
+
// marked `currentNote` ("current", or "suggested" for a guess); `exclude` left out. `other`: a last
|
|
177
|
+
// option for "none of these" (UNKNOWN), named so and always there, whatever is typed. → onPick(code);
|
|
178
|
+
// Esc clears the search, then goes back (onBack).
|
|
179
|
+
export function LanguageSearch({ title, note, current = null, currentNote = t("languages.current"), exclude = [], other = null, step = "", onPick, onBack }) {
|
|
180
|
+
const listFor = (text) => [...matching(text, [current]).filter((code) => code !== UNKNOWN && !exclude.includes(code)), ...(other ? [UNKNOWN] : [])];
|
|
181
|
+
const [query, setQuery] = useState("");
|
|
182
|
+
const options = listFor(query);
|
|
183
|
+
const startAt = (list) => Math.max(0, current ? list.indexOf(current) : 0);
|
|
184
|
+
const [selected, setSelected] = useState(() => startAt(options));
|
|
185
|
+
|
|
186
|
+
function search(text) {
|
|
187
|
+
setQuery(text);
|
|
188
|
+
setSelected(text ? 0 : startAt(listFor(text)));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
useInput((input, key) => {
|
|
192
|
+
if (key.escape || key.leftArrow) return query ? search("") : onBack?.();
|
|
193
|
+
if (key.return) return options[selected] && onPick(options[selected]);
|
|
194
|
+
if (key.upArrow) return setSelected((i) => Math.max(0, i - 1));
|
|
195
|
+
if (key.downArrow) return setSelected((i) => Math.max(0, Math.min(options.length - 1, i + 1)));
|
|
196
|
+
if (key.backspace || key.delete) return query && search(query.slice(0, -1));
|
|
197
|
+
if (key.ctrl && input === "u") return search("");
|
|
198
|
+
const text = input.replace(/[\u0000-\u001f\u007f]/g, "");
|
|
199
|
+
if (text && !key.ctrl && !key.meta) search(query + text);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const nameOf = (code) => (code === UNKNOWN ? other : languageName(code));
|
|
203
|
+
const noteOf = (code) => (code === current ? currentNote : "");
|
|
204
|
+
const noMatch = Boolean(query) && options.every((code) => code === UNKNOWN) && !(other && look(other).includes(look(query.trim())));
|
|
205
|
+
return html`<${LanguageList} title=${title} note=${note} query=${query} options=${options} selected=${selected} noteOf=${noteOf} nameOf=${nameOf} noMatch=${noMatch} step=${step} />`;
|
|
206
|
+
}
|
package/src/ui/Preview.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t } from "../i18n.js";
|
|
1
|
+
import { language, setLanguage, t } from "../i18n.js";
|
|
2
2
|
import { Fragment, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { Box, useApp, useInput } from "ink";
|
|
4
4
|
import { DEMO_CLOZE, DEMO_SENTENCES, DEMO_WORDS } from "../demo.js";
|
|
@@ -16,6 +16,7 @@ import { Badges } from "./Badges.js";
|
|
|
16
16
|
import { Confetti } from "./Confetti.js";
|
|
17
17
|
import { Evolution } from "./Evolution.js";
|
|
18
18
|
import { Hatch } from "./Hatch.js";
|
|
19
|
+
import { Welcome } from "./Welcome.js";
|
|
19
20
|
import { Header, Snore, useBlink, useMove } from "./Header.js";
|
|
20
21
|
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
21
22
|
import { Mascot } from "./Mascot.js";
|
|
@@ -174,6 +175,24 @@ function ConfettiLab({ onBack }) {
|
|
|
174
175
|
`;
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
// The welcome after the hatching, step by step; nothing is kept, and the app's language comes back
|
|
179
|
+
// as it was when you leave
|
|
180
|
+
function WelcomeLab({ onBack }) {
|
|
181
|
+
const [before] = useState(language);
|
|
182
|
+
const [step, setStep] = useState("language");
|
|
183
|
+
const [settings, setSettings] = useState({ language: before, homeLanguage: null, learningLanguage: null });
|
|
184
|
+
const leave = () => {
|
|
185
|
+
setLanguage(before);
|
|
186
|
+
onBack();
|
|
187
|
+
};
|
|
188
|
+
useInput((input, key) => key.escape && step === "language" && leave());
|
|
189
|
+
return html`<${Welcome} step=${step} settings=${settings} onPreviewLanguage=${setLanguage} onStep=${(next, patch) => {
|
|
190
|
+
if (patch?.language) setLanguage(patch.language);
|
|
191
|
+
setSettings((now) => ({ ...now, ...patch }));
|
|
192
|
+
setStep(next);
|
|
193
|
+
}} onStart=${leave} />`;
|
|
194
|
+
}
|
|
195
|
+
|
|
177
196
|
// labels and hints come from the locale, read each time the menu is drawn
|
|
178
197
|
const scene = (id, text = () => [t(`preview.scenes.${id}.label`), t(`preview.scenes.${id}.hint`)]) => ({
|
|
179
198
|
id,
|
|
@@ -186,6 +205,7 @@ const scene = (id, text = () => [t(`preview.scenes.${id}.label`), t(`preview.sce
|
|
|
186
205
|
});
|
|
187
206
|
const SCENES = [
|
|
188
207
|
scene("hatch"),
|
|
208
|
+
scene("welcome"),
|
|
189
209
|
...STAGES.slice(1).map((stage, i) => scene(`evolve-${i + 1}`, () => [t("preview.evolution", { name: stage.name }), t("preview.evolutionHint", { count: stage.from })])),
|
|
190
210
|
...["mascot", "quiz", "add", "reveal", "cloze", "quiz-look", "unlock", "the-one", "die", "confetti", "stats", "badges", "summary"].map((id) => scene(id))
|
|
191
211
|
];
|
|
@@ -248,6 +268,7 @@ export function Preview({ alerts }) {
|
|
|
248
268
|
const to = Number(scene.slice("evolve-".length));
|
|
249
269
|
return wrap(html`<${Evolution} key=${run} from=${to - 1} to=${to} name=${STAGES[to].name} onClose=${back} />`);
|
|
250
270
|
}
|
|
271
|
+
if (scene === "welcome") return wrap(html`<${WelcomeLab} key=${run} onBack=${back} />`);
|
|
251
272
|
if (scene === "mascot") return wrap(html`<${MascotLab} onBack=${back} />`);
|
|
252
273
|
if (scene === "quiz-look") return wrap(html`<${QuizLookLab} onBack=${back} />`);
|
|
253
274
|
if (scene === "confetti") return wrap(html`<${ConfettiLab} onBack=${back} />`);
|
package/src/ui/Settings.js
CHANGED
|
@@ -3,6 +3,8 @@ import { Box, useInput } from "ink";
|
|
|
3
3
|
import { language, LANGUAGES, t } from "../i18n.js";
|
|
4
4
|
import { GOALS, INTERVALS, QUIET_PRESETS, RHYTHMS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
|
|
5
5
|
import { formatQuiet } from "../quiet.js";
|
|
6
|
+
import { languageName } from "../language.js";
|
|
7
|
+
import { elementName } from "../progress.js";
|
|
6
8
|
import { Bar, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
7
9
|
|
|
8
10
|
function VolumeValue({ value }) {
|
|
@@ -12,6 +14,7 @@ function VolumeValue({ value }) {
|
|
|
12
14
|
// label and hint come from settings.rows.<key> in the locale
|
|
13
15
|
const ALL_ROWS = [
|
|
14
16
|
{ key: "language", options: Object.keys(LANGUAGES), format: (code) => LANGUAGES[code] },
|
|
17
|
+
{ key: "homeLanguage", action: true, format: (code) => languageName(code) ?? t("settings.notSet") },
|
|
15
18
|
{ key: "rhythm", options: RHYTHMS, format: (v) => t(`settings.rhythms.${v}`) },
|
|
16
19
|
{ key: "everyMs", options: INTERVALS, format: formatInterval },
|
|
17
20
|
{ key: "sound", options: [true, false], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
|
|
@@ -21,6 +24,7 @@ const ALL_ROWS = [
|
|
|
21
24
|
{ key: "tips", options: TIP_MODES, format: (v) => t(`settings.tipModes.${v}`) },
|
|
22
25
|
{ key: "skipWeekends", options: [true, false], format: (v) => t(v ? "settings.weekendsRest" : "settings.weekendsCount"), toggle: true },
|
|
23
26
|
{ key: "quiet", options: QUIET_PRESETS, format: formatQuiet },
|
|
27
|
+
{ key: "dragonLook", action: true, onlyWith: "element", format: (element) => elementName(element) },
|
|
24
28
|
{ key: "reset", action: true, format: () => t("settings.pressEnter") }
|
|
25
29
|
];
|
|
26
30
|
const label = (row) => t(`settings.rows.${row.key}.label`);
|
|
@@ -31,13 +35,21 @@ const nearestIndex = (options, value) => {
|
|
|
31
35
|
return options.reduce((best, option, i) => (Math.abs(option - value) < Math.abs(options[best] - value) ? i : best), 0);
|
|
32
36
|
};
|
|
33
37
|
|
|
34
|
-
// Changes apply and persist immediately; there is no save step. Action rows (Reset) open
|
|
35
|
-
// screen through `onAction`; without it (the preview) they are left out.
|
|
36
|
-
|
|
38
|
+
// Changes apply and persist immediately; there is no save step. Action rows (Your language, Reset) open
|
|
39
|
+
// their own screen through `onAction(key)`; without it (the preview) they are left out.
|
|
40
|
+
// `startRow` and `onRow`: the row to open on, and each row moved to, so a screen opened from a row
|
|
41
|
+
// comes back to it
|
|
42
|
+
// `element`: the dragon's element, if the die gave it one (the row to go back to the default look)
|
|
43
|
+
export function Settings({ settings, element = null, onChange, onClose, onAction, startRow = 0, onRow = () => {} }) {
|
|
37
44
|
const panel = usePanelWidth();
|
|
38
|
-
const [row,
|
|
39
|
-
const
|
|
40
|
-
|
|
45
|
+
const [row, setRowState] = useState(startRow);
|
|
46
|
+
const setRow = (next) => setRowState((r) => {
|
|
47
|
+
const value = typeof next === "function" ? next(r) : next;
|
|
48
|
+
onRow(value);
|
|
49
|
+
return value;
|
|
50
|
+
});
|
|
51
|
+
const ROWS = (onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action)).filter((item) => item.onlyWith !== "element" || element);
|
|
52
|
+
const values = { ...settings, language: settings.language ?? language(), dragonLook: element };
|
|
41
53
|
const labelWidth = Math.max(...ROWS.map((item) => label(item).length)) + 2;
|
|
42
54
|
|
|
43
55
|
useInput((input, key) => {
|
package/src/ui/Trash.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Fragment, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Box, useInput } from "ink";
|
|
3
|
+
import { t } from "../i18n.js";
|
|
4
|
+
import { dayKey } from "../dates.js";
|
|
5
|
+
import { TRASH_DAYS } from "../library.js";
|
|
6
|
+
import { formatDay } from "../vacation.js";
|
|
7
|
+
import { Choice } from "./Choice.js";
|
|
8
|
+
import { cutToWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
9
|
+
import { plainFront } from "../cardline.js";
|
|
10
|
+
|
|
11
|
+
// a deleted deck by its name, a card as "front = back", several cards by how many
|
|
12
|
+
const labelOf = (entry) => (entry.kind !== "cards" ? entry.name : entry.card ? cutToWidth(entry.card.cloze ? plainFront(entry.card.front) : `${entry.card.front} = ${entry.card.back.join("; ")}`, 34) : t("count.cards", { count: entry.cards }));
|
|
13
|
+
// /trash: decks and cards deleted in the last TRASH_DAYS, newest first; Enter brings one back with its
|
|
14
|
+
// progress (`onRestore`(id) → { deck, kind, cards, skipped }): a deck whole, cards into their deck.
|
|
15
|
+
export function Trash({ actions, onRestore, onClose }) {
|
|
16
|
+
const panel = usePanelWidth();
|
|
17
|
+
const [entries, setEntries] = useState(null);
|
|
18
|
+
const [selected, setSelected] = useState(0);
|
|
19
|
+
const [message, setMessage] = useState("");
|
|
20
|
+
const [error, setError] = useState("");
|
|
21
|
+
const busy = useRef(false);
|
|
22
|
+
|
|
23
|
+
const load = () => actions.trash().then(setEntries, (err) => setError(err.message));
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
load();
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
useInput((input, key) => {
|
|
29
|
+
if (entries && !entries.length && (key.escape || key.return || input === "q")) onClose();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
async function restore(i) {
|
|
33
|
+
if (busy.current) return;
|
|
34
|
+
busy.current = true;
|
|
35
|
+
try {
|
|
36
|
+
const back = await onRestore(entries[i].id);
|
|
37
|
+
setMessage(back.kind === "cards" ? t("trash.cardsRestored", { count: back.cards, deck: back.deck }) + (back.skipped ? ` ${t("trash.skipped", { count: back.skipped })}` : "") : t("trash.restored", { deck: back.deck }));
|
|
38
|
+
await load();
|
|
39
|
+
setSelected((s) => Math.max(0, Math.min(s, entries.length - 2)));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
setError(err.message);
|
|
42
|
+
} finally {
|
|
43
|
+
busy.current = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return html`
|
|
48
|
+
<${Fragment}>
|
|
49
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
50
|
+
<${Text} bold color=${theme.accent}>${t("trash.title")}<//>
|
|
51
|
+
<${Text} dimColor>${t("trash.note", { days: TRASH_DAYS })}<//>
|
|
52
|
+
<${Box} marginTop=${1}>
|
|
53
|
+
${entries?.length
|
|
54
|
+
? html`<${Choice} options=${entries.map((entry) => ({ label: labelOf(entry), note: t(entry.kind === "cards" ? "trash.cardsRow" : "trash.row", { cards: t("count.cards", { count: entry.cards }), deck: entry.name, deleted: formatDay(dayKey(entry.deletedAt)), until: formatDay(dayKey(entry.until)) }) }))} selected=${Math.min(selected, entries.length - 1)} onMove=${setSelected} onPick=${restore} onCancel=${onClose} />`
|
|
55
|
+
: entries && html`<${Text}>${t("trash.empty")}<//>`}
|
|
56
|
+
<//>
|
|
57
|
+
${message && html`<${Box} marginTop=${1}><${Text} color=${theme.good}>${message}<//><//>`}
|
|
58
|
+
${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
|
|
59
|
+
<//>
|
|
60
|
+
<${Box} paddingX=${1}><${KeyHints} text=${entries?.length ? t("keyHints.trash") : t("keyHints.back")} /><//>
|
|
61
|
+
<//>
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Fragment, useState } from "react";
|
|
2
|
+
import { Box, useInput } from "ink";
|
|
3
|
+
import { entry, language, LANGUAGES, t } from "../i18n.js";
|
|
4
|
+
import { FIRST_WORDS_LANGUAGES, hasFirstWords } from "../firstwords.js";
|
|
5
|
+
import { languageName, UNKNOWN } from "../language.js";
|
|
6
|
+
import { Choice, choiceHints } from "./Choice.js";
|
|
7
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
8
|
+
import { LanguageSearch } from "./Languages.js";
|
|
9
|
+
|
|
10
|
+
export const WELCOME_STEPS = ["language", "home", "learning", "start"];
|
|
11
|
+
const FIRST_WORDS_COUNT = 30;
|
|
12
|
+
|
|
13
|
+
// After the hatching, before the first question: the app's language, the one you speak, the one you're
|
|
14
|
+
// learning, and a way to start. Every answer is kept as it's given (onStep), so a welcome left halfway
|
|
15
|
+
// goes on from that step. `onPreviewLanguage` shows the texts in a language while it's only selected;
|
|
16
|
+
// onStart(how): "words" (the first words of the pair), "tour", "import" (cards you have, /import) or
|
|
17
|
+
// "own" (a deck of your own, in /add).
|
|
18
|
+
// `tour`: whether there's still a tour to show (a deck of your own may have taken its place).
|
|
19
|
+
export function Welcome({ step, settings, tour = true, onPreviewLanguage, onStep, onStart }) {
|
|
20
|
+
const panel = usePanelWidth();
|
|
21
|
+
const codes = Object.keys(LANGUAGES);
|
|
22
|
+
const [selected, setSelected] = useState(() => Math.max(0, codes.indexOf(settings.language ?? language())));
|
|
23
|
+
const [startAt, setStartAt] = useState(0);
|
|
24
|
+
const home = settings.homeLanguage ?? language();
|
|
25
|
+
const learning = settings.learningLanguage === UNKNOWN ? null : settings.learningLanguage; // "something else" is kept as UNKNOWN
|
|
26
|
+
const counter = `${WELCOME_STEPS.indexOf(step) + 1}/${WELCOME_STEPS.length}`;
|
|
27
|
+
const hints = (text) => `${counter} · ${text}`;
|
|
28
|
+
|
|
29
|
+
// ← goes back on the last step too, as it does in the language lists before it
|
|
30
|
+
useInput((input, key) => {
|
|
31
|
+
if (step === "start" && key.leftArrow) onStep("learning");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (step === "home")
|
|
35
|
+
return html`<${LanguageSearch} key="home" title=${t("welcome.homeTitle")} note=${t("welcome.homeNote")} current=${home} currentNote=${settings.homeLanguage ? t("languages.current") : t("welcome.suggested")} step=${counter} onBack=${() => onStep("language")} onPick=${(code) => onStep("learning", { homeLanguage: code, ...(code === learning && { learningLanguage: null }) })} />`;
|
|
36
|
+
if (step === "learning")
|
|
37
|
+
return html`<${LanguageSearch} key="learning" title=${t("welcome.learningTitle")} note=${t("welcome.learningNote")} current=${settings.learningLanguage !== home ? settings.learningLanguage : null} exclude=${[home]} other=${t("welcome.notLanguage")} step=${counter} onBack=${() => onStep("home")} onPick=${(code) => onStep("start", { learningLanguage: code })} />`;
|
|
38
|
+
|
|
39
|
+
if (step === "start") {
|
|
40
|
+
const words = learning && hasFirstWords(home, learning);
|
|
41
|
+
const options = [
|
|
42
|
+
words && { id: "words", label: t("welcome.start.words", { count: FIRST_WORDS_COUNT }), note: t("welcome.start.wordsNote", { language: languageName(learning), home: languageName(home) }) },
|
|
43
|
+
tour && { id: "tour", label: t("welcome.start.tour"), note: t("welcome.start.tourNote", { count: entry("tour.cards").length }) },
|
|
44
|
+
{ id: "import", label: t("welcome.start.import"), note: t("welcome.start.importNote") },
|
|
45
|
+
{ id: "own", label: t("welcome.start.own"), note: t("welcome.start.ownNote") }
|
|
46
|
+
].filter(Boolean);
|
|
47
|
+
// no ready-made words for this pair: said why, naming the language that has none
|
|
48
|
+
const names = () => new Intl.ListFormat(language(), { type: "conjunction" }).format(FIRST_WORDS_LANGUAGES.map((code) => languageName(code)));
|
|
49
|
+
const missing = !learning || words ? null : FIRST_WORDS_LANGUAGES.includes(learning) ? "home" : "learning";
|
|
50
|
+
const why = missing && (missing === "home" ? t("welcome.start.noWordsHome", { languages: names(), language: languageName(home) }) : t("welcome.start.noWords", { languages: names(), language: languageName(learning) }));
|
|
51
|
+
return html`
|
|
52
|
+
<${Fragment}>
|
|
53
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
54
|
+
<${Text} bold color=${theme.accent}>${t("welcome.startTitle")}<//>
|
|
55
|
+
<${Text} dimColor>${t("welcome.startNote")}<//>
|
|
56
|
+
<${Box} marginTop=${1}><${Choice} options=${options} selected=${Math.min(startAt, options.length - 1)} onMove=${setStartAt} onPick=${(i) => onStart(options[i].id)} onCancel=${() => onStep("learning")} /><//>
|
|
57
|
+
${why && html`<${Box} marginTop=${1}><${Text} dimColor>${why}<//><//>`}
|
|
58
|
+
<//>
|
|
59
|
+
<${Box} paddingX=${1}><${KeyHints} text=${hints(choiceHints("back"))} /><//>
|
|
60
|
+
<//>
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// the app's language: each named in itself, and the texts follow the one selected
|
|
65
|
+
const move = (i) => {
|
|
66
|
+
setSelected(i);
|
|
67
|
+
onPreviewLanguage(codes[i]);
|
|
68
|
+
};
|
|
69
|
+
return html`
|
|
70
|
+
<${Fragment}>
|
|
71
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
72
|
+
<${Text} bold color=${theme.accent}>${t("welcome.languageTitle")}<//>
|
|
73
|
+
<${Text} dimColor>${t("welcome.languageNote")}<//>
|
|
74
|
+
<${Box} marginTop=${1}><${Choice} options=${codes.map((code) => ({ label: LANGUAGES[code] }))} selected=${selected} onMove=${move} onPick=${(i) => onStep("home", { language: codes[i] })} /><//>
|
|
75
|
+
<//>
|
|
76
|
+
<${Box} paddingX=${1}><${KeyHints} text=${hints(t("choice.keys"))} /><//>
|
|
77
|
+
<//>
|
|
78
|
+
`;
|
|
79
|
+
}
|
package/src/words.js
CHANGED
|
@@ -11,15 +11,38 @@ export function missingDeck(library, deckRef) {
|
|
|
11
11
|
return new Error(deckRef ? t("errors.noDeck", { deck: deckRef, decks: names || t("errors.noDecksYet") }) : t("errors.emptyLibrary"));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// a deck as the quiz needs it: its name, languages, the one you're learning, which way it asks
|
|
15
|
+
function describe(library, deck, cards) {
|
|
16
|
+
// the tour is written in the UI's language on both sides: no pair to show or check by
|
|
17
|
+
const languages = deck.tour ? null : deckLanguages(deck, cards);
|
|
18
|
+
const home = homeLanguages({ others: library.decks.filter((d) => d !== deck && d.languages).map((d) => d.languages) });
|
|
19
|
+
return { name: deck.name, languages, learning: deck.tour ? null : learningSide(languages, deck, home), directions: deck.directions, tour: Boolean(deck.tour) };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DIRECTION_KEYS = { forward: ["en-pl"], backward: ["pl-en"], both: ["en-pl", "pl-en"] };
|
|
23
|
+
|
|
24
|
+
// `deckRef` may also be several decks practised together (a list of names or ids) or "all" of yours:
|
|
25
|
+
// their cards mixed, each card carrying its own deck (`word.deck`) and the way that deck asks. Decks of
|
|
26
|
+
// the list that are gone are left out; with none left, it's your first deck again.
|
|
14
27
|
export async function loadWords(deckRef) {
|
|
15
28
|
const library = await loadLibrary();
|
|
29
|
+
if (deckRef === "all" || Array.isArray(deckRef)) {
|
|
30
|
+
const own = library.decks.filter((d) => !d.tour);
|
|
31
|
+
const decks = deckRef === "all" ? own : [...new Set(deckRef.map((ref) => findDeck(library, ref)).filter((d) => d && !d.tour))];
|
|
32
|
+
if (decks.length >= 2 || (deckRef === "all" && decks.length)) {
|
|
33
|
+
const words = decks.flatMap((deck) => {
|
|
34
|
+
const cards = cardsOf(library, deck.id);
|
|
35
|
+
const info = describe(library, deck, cards);
|
|
36
|
+
return toWords(cards).map((word) => ({ ...word, deck: info, directions: word.directions ?? DIRECTION_KEYS[deck.directions] ?? DIRECTION_KEYS.both }));
|
|
37
|
+
});
|
|
38
|
+
return { words, deck: { name: decks.map((d) => d.name).join(" + "), mixed: decks.map((d) => d.name), all: deckRef === "all", languages: null, learning: null, directions: "both", tour: false } };
|
|
39
|
+
}
|
|
40
|
+
return loadWords(decks[0]?.id);
|
|
41
|
+
}
|
|
16
42
|
const deck = deckRef ? findDeck(library, deckRef) : (library.decks.find((d) => !d.tour) ?? library.decks[0]);
|
|
17
43
|
if (!deck) throw missingDeck(library, deckRef);
|
|
18
44
|
const cards = cardsOf(library, deck.id);
|
|
19
|
-
|
|
20
|
-
const languages = deck.tour ? null : deckLanguages(deck, cards);
|
|
21
|
-
const home = homeLanguages({ others: library.decks.filter((d) => d !== deck && d.languages).map((d) => d.languages) });
|
|
22
|
-
return { words: toWords(cards), deck: { name: deck.name, languages, learning: deck.tour ? null : learningSide(languages, deck, home), directions: deck.directions, tour: Boolean(deck.tour) } };
|
|
45
|
+
return { words: toWords(cards), deck: describe(library, deck, cards) };
|
|
23
46
|
}
|
|
24
47
|
|
|
25
48
|
// every deck of yours (not the tour), for "is anything still waiting today?"
|