Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/estonian-lesson/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ One file in `components/learn/lessons/` with a `SLUG` constant, its glossary, it
- Write every line to [the copy rules](references/copy.md) as you go; step 5 checks them.
- Write every quiz to [the quiz rules](references/checklists.md#quizzes). Reviews flagged a giveaway or a skipped item in six of the first seven lesson PRs.
- End with What to remember in three to five rules, then the words.
- Write the lesson's drill bank, `<File>.drills.ts`, to [the bank checklist](references/checklists.md#drill-banks). `LessonView` adds the drill, and later lessons' warm-ups and the review page pick it up.
- Write the lesson's drill bank, `<File>.drills.ts`, to [the bank checklist](references/checklists.md#drill-banks). Finishing the lesson puts its questions in review, and later lessons' warm-ups pick them up. When the bank asks a kind of question the lesson's quizzes don't, `lesson-checks.test.ts` prints the `LAST_EXERCISE` line to add, and `LessonView` ends the lesson with those questions.
- Fix a kit part in its own file in `components/learn`, never in a copy inside the lesson, and name the fix in the PR and the notes: every lesson uses it.
- Each `Quiz` gets a fixed `id` of lowercase letters, digits and hyphens, unique in the lesson: it is the `quiz` property of `learn_quiz_finished`.

Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/estonian-lesson/references/checklists.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Drive the lesson in Playwright at 1280 and 375 px, light and night (`colorScheme

- Every `Word` card, by resting on it and by tapping it.
- Every key, chip, switch, line and play button.
- The drill from Start to its result and Ten more, with a miss and its return; the warm-up and the review page with the clock moved a day.
- The last exercise, when `LAST_EXERCISE` lists the lesson, from Start to its result and Try again; the warm-up and the review page with the clock moved a day after the lesson is finished.
- Every quiz: the Listen-first nudge, right and wrong picks, Hear both, the score, and Try again.
- A conversation: play, pause, a tap on a speaker's line, the sentence before and after, five seconds back, both speeds, and a turn's button in the text. In exam mode: a play cut short by another sound, the last play, and Try again.
- What to remember, the words card opened, and the links to the previous and next lessons.
Expand Down
54 changes: 40 additions & 14 deletions apps/site/src/components/learn/Dialogue.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Trans, useLingui } from "@lingui/react/macro";
import { captureAnalytics } from "@lymi/client/analytics";
import { clsx } from "clsx";
import { ArrowRight, Check, Ear, MessageCircle, RotateCcw, X } from "lucide-react";
import { ArrowRight, Check, Ear, MessageCircle, Pause, Play, RotateCcw, X } from "lucide-react";
import {
type ReactNode,
type Ref,
Expand All @@ -19,7 +19,7 @@ import {
sayReply,
startDialogue,
} from "../../lib/learn/passage";
import { playInTurn, playSound, stopSound, usePlaying } from "../../lib/learn/player";
import { playInTurn, stopAll, toggleInTurn, toggleSound, usePlaying } from "../../lib/learn/player";
import { Button } from "../Button";
import { SectionContext, useLesson } from "./lesson-context";
import { Feedback, QuizCard, ResultDots } from "./Quiz";
Expand Down Expand Up @@ -81,6 +81,22 @@ export function Dialogue({ id, title, part, them, turns, text = "shown" }: Dialo
const src = (clip: string) => clipUrl(slug, clip);
// Keyed by the dialogue too, so two dialogues with the same lines don't light up together.
const key = (clip: string) => `dialogue:${slug}:${id}:${clip}`;
const wholeKey = `dialogue:${slug}:${id}`;
const playingWhole = usePlaying(wholeKey);
const [resumeAt, setResumeAt] = useState(0);
const wholeRun = useRef(0);
const hearWhole = () => {
const from = resumeAt;
const run = toggleInTurn(
turns.slice(from).map((turn) => ({ src: src(turn.clip), key: key(turn.clip) })),
wholeKey,
);
if (!run) return;
const mine = ++wholeRun.current;
void run.then(({ finished, at }) => {
if (wholeRun.current === mine) setResumeAt(finished ? 0 : from + at);
});
};
const rightLine = (turn: Extract<DialogueTurn, { who: "you" }>) =>
turn.replies.find((reply) => reply.right)?.line ?? "";
const yours = turns.filter((turn) => turn.who === "you").length;
Expand Down Expand Up @@ -257,19 +273,29 @@ export function Dialogue({ id, title, part, them, turns, text = "shown" }: Dialo
</Trans>
</p>
<div className="flex flex-wrap gap-2">
<Button
onClick={() =>
void playInTurn(
turns.map((turn) => ({ src: src(turn.clip), key: key(turn.clip) })),
)
}
>
<Ear aria-hidden="true" data-icon="inline-start" />
<Trans>Hear the whole conversation</Trans>
<Button onClick={hearWhole}>
{playingWhole ? (
<>
<Pause aria-hidden="true" data-icon="inline-start" />
<Trans context="dialogue: pause the whole conversation">Pause</Trans>
</>
) : resumeAt > 0 ? (
<>
<Play aria-hidden="true" data-icon="inline-start" />
<Trans context="dialogue: go on playing the whole conversation">Resume</Trans>
</>
) : (
<>
<Ear aria-hidden="true" data-icon="inline-start" />
<Trans>Hear the whole conversation</Trans>
</>
)}
</Button>
<Button
onClick={() => {
stopSound();
stopAll();
wholeRun.current += 1;
setResumeAt(0);
restarted.current = true;
dispatch({ type: "restart" });
}}
Expand Down Expand Up @@ -314,7 +340,7 @@ function TheirLine({
<button
type="button"
aria-label={shown ? t`Play ${name}: ${line}` : t`Play what ${name} said`}
onClick={() => void playSound(src, playKey)}
onClick={() => void toggleSound(src, playKey)}
className="flex cursor-pointer items-center gap-3 rounded-2xl rounded-ss-sm bg-plate-nested py-2 ps-2 pe-4 text-start"
>
<PlayMark playing={playing} />
Expand Down Expand Up @@ -365,7 +391,7 @@ function YourLine({ line, src, playKey }: { line: string; src: string; playKey:
type="button"
lang="et"
aria-label={t`Play your line: ${line}`}
onClick={() => void playSound(src, playKey)}
onClick={() => void toggleSound(src, playKey)}
className={clsx(
"max-w-[80%] cursor-pointer justify-self-end rounded-2xl rounded-se-sm bg-(--form-soft) px-4 py-2.5 text-start text-lg font-medium transition-shadow duration-150",
playing && "ring-2 ring-(--form)",
Expand Down
29 changes: 18 additions & 11 deletions apps/site/src/components/learn/Drill.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Trans } from "@lingui/react/macro";
import { Plural, Trans } from "@lingui/react/macro";
import { RotateCcw } from "lucide-react";
import { useCallback, useContext } from "react";
import { currentReview, drawDrill, localDay } from "../../lib/learn/review";
import { Button } from "../Button";
import { questionsOf } from "./drill-banks";
import { type DrillKind, LAST_EXERCISE_SIZE, questionsOf } from "./drill-banks";
import { useDrillSession } from "./drill-session";
import { DrillRunner } from "./DrillRunner";
import { SectionContext, useLesson } from "./lesson-context";
Expand All @@ -16,38 +17,44 @@ export function LoadProblem() {
);
}

export function Drill() {
export function LastExercise({ kinds }: { kinds: readonly DrillKind[] }) {
const { slug, finishSection } = useLesson();
const section = useContext(SectionContext);
const { session, open, more } = useDrillSession(
() => [slug],
(sources) => drawDrill(questionsOf(sources), currentReview(), localDay()),
(sources) =>
drawDrill(
questionsOf(sources).filter(({ item }) => kinds.includes(item.kind)),
currentReview(),
localDay(),
LAST_EXERCISE_SIZE,
),
);
const finish = useCallback(() => {
if (section) finishSection(section);
}, [section, finishSection]);

const title = <Trans>Ten questions</Trans>;
if (session.status === "open")
return (
<DrillRunner
key={session.set}
id="drill"
id="last"
lesson={slug}
title={title}
title={<Plural value={session.questions.length} one="# question" other="# questions" />}
questions={session.questions}
sources={session.sources}
repeats
repeats={false}
onFinish={finish}
end={
<Button variant="primary" onClick={more}>
<Trans>Ten more</Trans>
<Button onClick={more}>
<RotateCcw aria-hidden="true" data-icon="inline-start" />
<Trans>Try again</Trans>
</Button>
}
/>
);
return (
<QuizCard title={title}>
<QuizCard title={<Trans>A few questions</Trans>}>
<Button variant="primary" loading={session.status === "loading"} onClick={open}>
<Trans>Start</Trans>
</Button>
Expand Down
6 changes: 3 additions & 3 deletions apps/site/src/components/learn/DrillRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { KeepEndings } from "./endings";
import { QuizCard, ResultDots, Score } from "./Quiz";

interface Props {
id: "drill" | "warm-up" | "review" | "checkpoint" | "placement";
id: "last" | "warm-up" | "review" | "checkpoint" | "placement";
lesson: string;
title: ReactNode;
questions: readonly Question[];
Expand Down Expand Up @@ -91,8 +91,8 @@ export function DrillRunner(props: Props) {
<QuizCard
title={title}
aside={
<span className="flex flex-wrap items-center gap-2">
<span className="flex items-center rounded-full bg-plate">
<span className="flex min-w-0 flex-wrap items-center gap-2">
<span className="flex min-w-0 items-center rounded-full bg-plate">
<ResultDots
results={run.items.map((each) => run.first[each.id])}
now={position}
Expand Down
10 changes: 6 additions & 4 deletions apps/site/src/components/learn/Explore.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLingui } from "@lingui/react/macro";
import { clsx } from "clsx";
import { type ReactNode, useEffect, useState } from "react";
import { loudness, playSound, usePlaying } from "../../lib/learn/player";
import { loudness, playSound, toggleSound, usePlaying } from "../../lib/learn/player";
import { Playing, PlayMark } from "./Sound";

/** The stage's tray, where anything to play with sits. Nothing on it is marked right or wrong. */
Expand Down Expand Up @@ -105,7 +105,7 @@ function Key({
data-playing={playing ? "" : undefined}
onClick={() => {
onPress();
void playSound(item.src);
void toggleSound(item.src);
}}
className="learn-key relative grid cursor-pointer justify-items-center gap-0.5 rounded-tile bg-plate px-0.5 pt-3 pb-2.5 hoverable:hover:bg-plate-hover"
>
Expand Down Expand Up @@ -248,7 +248,7 @@ function Row({ item, lead }: { item: RowItem; lead: string | undefined }) {
<button
type="button"
aria-label={item.label}
onClick={() => void playSound(item.src as string)}
onClick={() => void toggleSound(item.src as string)}
style={grid}
className="grid w-full cursor-pointer items-center gap-x-3.5 py-3 ps-4 pe-3 text-start transition-colors duration-150 hoverable:hover:bg-plate-hover"
>
Expand Down Expand Up @@ -352,10 +352,12 @@ function CompareRow(props: {
type="button"
aria-label={t`Play ${word}`}
onClick={() => {
if (playing) return void toggleSound(src, key);
if (!clip) return void playSound(src, key);
void playSound(src, key, (time) =>
setLit(Math.min(1, Math.max(0, (time - clip.lead) / clip.seconds))),
).then(() => {
).then((end) => {
if (end !== "ended") return setLit(0);
setLit(1);
setTimeout(() => setLit(0), 900);
});
Expand Down
4 changes: 2 additions & 2 deletions apps/site/src/components/learn/FormRound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ export function FormRound({ item, state, heard, answer, autoplay }: RoundProps<F

return (
<>
<div className="flex flex-wrap items-end gap-x-4 gap-y-2">
<div className="flex flex-wrap items-start gap-x-4 gap-y-2">
<p className="grid gap-0.5">
<b lang="et" className="text-4xl/none font-semibold tracking-tight">
{item.base}
</b>
{item.gloss && <span className="text-sm text-ink-muted">{item.gloss}</span>}
</p>
<p className="inline-flex items-center gap-2 pb-0.5">
<p className="inline-flex h-[1em] items-center gap-2 text-4xl/none">
<ArrowRight aria-hidden="true" className="size-4 text-ink-muted" strokeWidth={2.25} />
<span
lang={item.cueLang}
Expand Down
4 changes: 2 additions & 2 deletions apps/site/src/components/learn/HubView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function Row({ lesson, status }: { lesson: PlacedLesson; status: Status }) {
<span
aria-hidden="true"
className={clsx(
"text-md font-semibold tabular-nums",
"min-w-[2.5ch] text-md font-semibold tabular-nums",
open ? "text-(--form)" : "text-ink-muted",
)}
>
Expand All @@ -254,7 +254,7 @@ function Row({ lesson, status }: { lesson: PlacedLesson; status: Status }) {
</>
);
const row =
"-mx-3 grid grid-cols-[40px_minmax(0,1fr)_auto] items-center gap-3.5 rounded-tile px-3 py-3.5 max-@3xl:grid-cols-[32px_minmax(0,1fr)_auto] max-@3xl:gap-2.5";
"-mx-3 grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-tile px-3 py-3.5 max-@3xl:gap-2.5";
return (
<li className="border-t border-edge first:border-t-0">
{lesson.slug ? (
Expand Down
54 changes: 40 additions & 14 deletions apps/site/src/components/learn/LessonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import { clsx } from "clsx";
import { ArrowLeft, ArrowRight, Info } from "lucide-react";
import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
import { lessonBySlug, lessonPath, nextLesson, previousLesson } from "../../lib/learn/catalogue";
import { finishSection as saveSection, startLesson } from "../../lib/learn/progress";
import { progressStore, finishSection as saveSection, startLesson } from "../../lib/learn/progress";
import { localizedPath } from "../../lib/routes";
import { buttonClass } from "../Button";
import { Drill } from "./Drill";
import { drillSlugs } from "./drill-banks";
import { LastExercise } from "./Drill";
import {
type DrillKind,
LAST_EXERCISE,
scheduleFinishedLesson,
scheduleLesson,
} from "./drill-banks";
import { Endings } from "./endings";
import { LearnLayout } from "./LearnLayout";
import { type Glossary, LessonContext, SectionContext, useLesson } from "./lesson-context";
Expand Down Expand Up @@ -42,21 +47,42 @@ interface Props {
/** A lesson page: its head, a read bar, its sections, what to remember, its words and the next lesson. */
export function LessonView({ slug, sub, facts, glossary, sections: taught, recap, words }: Props) {
const { t, i18n } = useLingui();
const sections = drillSlugs.has(slug) ? [...taught, drillSection(t`Drill`)] : taught;
const last = LAST_EXERCISE[slug];
const kindTitles: Record<DrillKind, string> = {
dictation: t`Write what you hear`,
rewrite: t`Change the sentence`,
form: t`Make the form`,
ask: t`Ask the question`,
build: t`Build the sentence`,
translate: t`Write it in Estonian`,
fix: t`Fix the sentence`,
gap: t`Fill the gap`,
choice: t`Pick the answer`,
};
const sections = last
? [
...taught,
lastSection(last, last.length === 1 ? kindTitles[last[0] as DrillKind] : t`Last exercise`),
]
: taught;
const lesson = lessonBySlug(slug);
if (!lesson) throw new Error(`No lesson ${slug}`);
const hasRecap = recap.length > 0 || words.length > 0;
const all = hasRecap ? [...sections.map((s) => s.id), "recap"] : sections.map((s) => s.id);
const number = lesson.n;
const level = lesson.stage.level;

useEffect(() => startLesson(slug), [slug]);
useEffect(() => {
scheduleFinishedLesson(slug, progressStore.current().lessons[slug]?.state === "done");
startLesson(slug);
}, [slug]);
// The lesson's sections never change, so the callback reads them from a ref and stays stable.
const sectionIds = useRef(all);
const finishSection = useCallback(
(section: string) => {
if (saveSection(slug, section, sectionIds.current).lessonFinished)
captureAnalytics("learn_lesson_finished", { lesson: slug });
if (!saveSection(slug, section, sectionIds.current).lessonFinished) return;
captureAnalytics("learn_lesson_finished", { lesson: slug });
scheduleLesson(slug).catch(() => {});
Comment thread
krambertech marked this conversation as resolved.
Resolved
},
[slug],
);
Expand Down Expand Up @@ -151,21 +177,21 @@ export function LessonView({ slug, sub, facts, glossary, sections: taught, recap
);
}

const drillSection = (title: string): LessonSection => ({
id: "drill",
const lastSection = (kinds: readonly DrillKind[], title: string): LessonSection => ({
id: "last-exercise",
title,
quiz: true,
children: (
<>
<Prose>
<p>
<Trans>
Ten questions on this lesson’s rules, mixed. One you miss comes back until you answer it
right twice, and they all return on later days.
A kind of question the sections above didn’t ask, on this lesson’s rules. Once the
lesson is done, its questions come back in Review on later days.
</Trans>
</p>
</Prose>
<Drill />
<LastExercise kinds={kinds} />
</>
),
});
Expand Down Expand Up @@ -222,8 +248,8 @@ export function Prose({ children }: { children: ReactNode }) {
/** A short note beside the lesson's main line, one that can be skipped: an exception, a comparison. */
export function Aside({ children }: { children: ReactNode }) {
return (
<p className="flex max-w-[62ch] gap-3 rounded-lg border border-edge px-4 py-3 text-md text-pretty text-ink-secondary">
<Info aria-hidden="true" className="mt-[0.2em] size-4.5 shrink-0 text-(--form)" />
<p className="flex max-w-[62ch] gap-3.5 rounded-xl bg-(--tray) px-5.5 py-4.5 text-[1.1875rem] leading-[1.62] text-pretty text-ink-secondary max-sm:-mx-1 max-sm:gap-3 max-sm:px-4 max-sm:text-lg [&_b]:font-medium [&_b]:text-ink">
<Info aria-hidden="true" className="mt-[0.3em] size-5 shrink-0 text-(--form)" />
<span className="min-w-0">{children}</span>
</p>
);
Expand Down
Loading
Loading