Skip to content
Merged
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 apps/site/lesson-isolation.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LESSON_MODULE = /\/apps\/site\/src\/(?:components\/learn|lib\/learn|locales\/learn)\//;
const LESSON_ENTRY =
/\/components\/islands\/(?:LearnHubPage|LearnLessonPage|LearnReload|LearnReviewPage|LessonKitPage|LessonKitReload)\.tsx$/;
/\/components\/islands\/(?:LearnHubPage|LearnLessonPage|LearnPlacementPage|LearnReload|LearnReviewPage|LessonKitPage|LessonKitReload)\.tsx$/;

/** @type {(bundle: Record<string, { type: string, fileName: string, moduleIds?: string[], imports?: string[], dynamicImports?: string[], isEntry?: boolean, facadeModuleId?: string | null }>) => string[]} */
export const leakedLessonChunks = (bundle) => {
Expand Down
9 changes: 9 additions & 0 deletions apps/site/src/components/islands/LearnPlacementPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { msg } from "@lingui/core/macro";
import { LearnPage } from "../learn/learn-page";

export const PLACEMENT_TITLE = msg`Estonian placement test · Lymi`;
export const PLACEMENT_BLURB = msg`Find where to start in the free Estonian grammar course: eighteen questions from A1 basics to B1 sentences, with a suggested starting stage and links to each rule.`;

export default function LearnPlacementPage({ locale }: { locale: string }) {
return <LearnPage target={{ kind: "placement" }} locale={locale} />;
}
60 changes: 60 additions & 0 deletions apps/site/src/components/learn/Checkpoint.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Trans } from "@lingui/react/macro";
import { useCallback, useContext } from "react";
import { STAGES } from "../../lib/learn/catalogue";
import { drawBalanced } from "../../lib/learn/placement";
import { Button } from "../Button";
import { LoadProblem } from "./Drill";
import { type DrillSource, drillSlugs, type Question, questionsOf } from "./drill-banks";
import { useDrillSession } from "./drill-session";
import { DrillRunner } from "./DrillRunner";
import { SectionContext, useLesson } from "./lesson-context";
import { QuizCard } from "./Quiz";

function drawStageQuestions(sources: readonly DrillSource[], count: number): Question[] {
return drawBalanced(questionsOf(sources), count, (question) => question.source.lesson);
}

export function Checkpoint({ stageIndex, count = 20 }: { stageIndex: number; count?: number }) {
const { slug, finishSection } = useLesson();
const section = useContext(SectionContext);
const stage = STAGES[stageIndex];
const slugs = (stage?.lessons ?? [])
.map((lesson) => lesson.slug)
.filter((item): item is string => !!item && item !== slug && drillSlugs.has(item));

const { session, open, more } = useDrillSession(
() => slugs,
(sources) => drawStageQuestions(sources, count),
);
const finish = useCallback(() => {
if (section) finishSection(section);
}, [section, finishSection]);

const title = <Trans>Stage checkpoint</Trans>;
if (session.status === "open")
return (
<DrillRunner
key={session.set}
id="checkpoint"
lesson={slug}
title={title}
questions={session.questions}
sources={session.sources}
repeats={false}
onFinish={finish}
Comment on lines +41 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Suppress drill explanations during checkpoint runs

Every answered checkpoint question currently shows its teaching explanation: DrillRunner delegates to DrillRound, which unconditionally supplies item.explain to the round components. Setting repeats={false} only disables retries; it does not disable that feedback. This contradicts the checkpoint contract in docs/design/estonian-lessons.md:94 (“No explanations”) and teaches rules while the assessment is still measuring them. Add an assessment mode that withholds explanations until the run has finished, while preserving the existing feedback for ordinary drills.

Useful? React with 👍 / 👎.

end={
<Button variant="primary" onClick={more}>
<Trans>Try a new set</Trans>
</Button>
}
/>
);
return (
<QuizCard title={title}>
<Button variant="primary" loading={session.status === "loading"} onClick={open}>
<Trans>Start checkpoint</Trans>
</Button>
{session.status === "idle" && session.failed && <LoadProblem />}
</QuizCard>
);
}
7 changes: 5 additions & 2 deletions apps/site/src/components/learn/DrillRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ import { KeepEndings } from "./endings";
import { QuizCard, ResultDots, Score } from "./Quiz";

interface Props {
id: "drill" | "warm-up" | "review";
id: "drill" | "warm-up" | "review" | "checkpoint" | "placement";
lesson: string;
title: ReactNode;
questions: readonly Question[];
sources: readonly DrillSource[];
repeats: boolean;
bandEnd?: ReactNode;
afterScore?: (scores: ReturnType<typeof ruleScores>) => ReactNode;
onFinish?: () => void;
end: ReactNode;
}

export function DrillRunner(props: Props) {
const { id, lesson, title, questions, sources, repeats, bandEnd, onFinish, end } = props;
const { id, lesson, title, questions, sources, repeats, bandEnd, afterScore, onFinish, end } =
props;
const { t } = useLingui();
const [run, dispatch] = useReducer(drillReducer, { items: questions, repeats }, startRun);
const [autoplay, setAutoplay] = useState(false);
Expand Down Expand Up @@ -135,6 +137,7 @@ export function DrillRunner(props: Props) {
src: clipUrl(source.lesson, clipId(item.say)),
}))}
/>
{afterScore?.(ruleScores(run))}
<RuleResults scores={ruleScores(run)} sources={sources} lesson={lesson} />
<div ref={endRef} className="flex w-full flex-wrap gap-2.5">
{end}
Expand Down
23 changes: 16 additions & 7 deletions apps/site/src/components/learn/HubView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "../../lib/learn/catalogue";
import { type Progress, useProgress } from "../../lib/learn/progress";
import { dueIds, localDay, useReview } from "../../lib/learn/review";
import { localizedPath } from "../../lib/routes";
import { buttonClass } from "../Button";
import { drillSlugs } from "./drill-banks";
import { LearnLayout } from "./LearnLayout";
Expand Down Expand Up @@ -93,13 +94,21 @@ function Resume() {
<span lang="et">{next.et}</span>
</span>
</p>
<a
href={lessonPath(next.slug as string, i18n.locale)}
className={buttonClass("primary", "lg", "justify-self-start")}
>
{begun ? <Trans>Continue</Trans> : <Trans>Start lesson 1</Trans>}
<ArrowRight aria-hidden="true" data-icon="inline-end" />
</a>
<div className="flex flex-wrap items-center gap-3">
<a
href={lessonPath(next.slug as string, i18n.locale)}
className={buttonClass("primary", "lg", "justify-self-start")}
>
{begun ? <Trans>Continue</Trans> : <Trans>Start lesson 1</Trans>}
<ArrowRight aria-hidden="true" data-icon="inline-end" />
</a>
<a
href={localizedPath("learnPlacement", i18n.locale)}
className={buttonClass("secondary", "md", "justify-self-start")}
>
<Trans>Find your level</Trans>
</a>
</div>
</>
) : (
<>
Expand Down
37 changes: 25 additions & 12 deletions apps/site/src/components/learn/LessonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function LessonView({ slug, sub, facts, glossary, sections: taught, recap
const sections = drillSlugs.has(slug) ? [...taught, drillSection(t`Drill`)] : taught;
const lesson = lessonBySlug(slug);
if (!lesson) throw new Error(`No lesson ${slug}`);
const all = [...sections.map((s) => s.id), "recap"];
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;

Expand Down Expand Up @@ -113,24 +114,36 @@ export function LessonView({ slug, sub, facts, glossary, sections: taught, recap
</div>
<ReadBar
title={i18n._(lesson.name)}
sections={[...sections, { id: "recap", title: t`What to remember`, children: null }]}
sections={
hasRecap
? [...sections, { id: "recap", title: t`What to remember`, children: null }]
: sections
}
/>
<div className="mx-auto max-w-[720px] px-5">
{sections.map((section) => (
<Section key={section.id} id={section.id} title={section.title} quiz={section.quiz}>
{section.children}
</Section>
))}
<Section id="recap" title={t`What to remember`}>
<ol className="m-0 grid list-decimal gap-2.5 rounded-xl bg-(--tray) py-5.5 ps-11 pe-5.5 text-lg marker:font-medium marker:text-(--form) max-sm:-mx-1">
{recap.map((line, i) => (
// oxlint-disable-next-line react/no-array-index-key -- the recap is fixed and numbered
<li key={i}>{line}</li>
))}
</ol>
<LessonWords words={words} />
</Section>
<NextLesson slug={slug} locale={i18n.locale} onFinish={() => finishSection("recap")} />
{hasRecap && (
<Section id="recap" title={t`What to remember`}>
<ol className="m-0 grid list-decimal gap-2.5 rounded-xl bg-(--tray) py-5.5 ps-11 pe-5.5 text-lg marker:font-medium marker:text-(--form) max-sm:-mx-1">
{recap.map((line, i) => (
// oxlint-disable-next-line react/no-array-index-key -- the recap is fixed and numbered
<li key={i}>{line}</li>
))}
</ol>
<LessonWords words={words} />
</Section>
)}
<NextLesson
slug={slug}
locale={i18n.locale}
onFinish={() => {
if (hasRecap) finishSection("recap");
}}
/>
</div>
</LearnLayout>
</WordCards>
Expand Down
167 changes: 167 additions & 0 deletions apps/site/src/components/learn/PlacementView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { Trans, useLingui } from "@lingui/react/macro";
import { ArrowLeft, ArrowRight } from "lucide-react";
import { lessonPath, STAGES } from "../../lib/learn/catalogue";
import type { ruleScores } from "../../lib/learn/drill";
import { drawPlacementStage, firstFailedStage, PER_STAGE } from "../../lib/learn/placement";
import { localizedPath } from "../../lib/routes";
import { Button, buttonClass } from "../Button";
import { LoadProblem } from "./Drill";
import { type DrillSource, drillSlugs, type Question, questionsOf } from "./drill-banks";
import { useDrillSession } from "./drill-session";
import { DrillRunner } from "./DrillRunner";
import { LearnLayout } from "./LearnLayout";
import { QuizCard } from "./Quiz";

function placementSlugs(): string[] {
return STAGES.flatMap((stage) => {
const drilled = stage.lessons
.map((lesson) => lesson.slug)
.filter((slug): slug is string => !!slug && drillSlugs.has(slug));
if (drilled.length <= PER_STAGE) return drilled;
const mid = Math.floor(drilled.length / 2);
return [drilled[0] as string, drilled[mid] as string, drilled[drilled.length - 1] as string];
});
}

function drawPlacement(sources: readonly DrillSource[]): Question[] {
const bySlug = new Map(sources.map((source) => [source.lesson, source]));
return STAGES.flatMap((stage) => {
const stageSources = stage.lessons
.map((lesson) => (lesson.slug ? bySlug.get(lesson.slug) : undefined))
.filter((source): source is DrillSource => !!source);
return drawPlacementStage(questionsOf(stageSources), (question) => question.source.lesson);
});
}

function PlacementResult({ scores }: { scores: ReturnType<typeof ruleScores> }) {
const { i18n } = useLingui();
const stageOfLesson = new Map<string, number>();
STAGES.forEach((stage, index) => {
for (const lesson of stage.lessons) {
if (lesson.slug) stageOfLesson.set(lesson.slug, index);
}
});

const totals = STAGES.map((stage, index) => ({ index, stage, right: 0, total: 0 }));
for (const score of scores) {
const slug = score.rule.split("/")[0] ?? "";
const idx = stageOfLesson.get(slug);
if (idx !== undefined && totals[idx]) {
totals[idx].right += score.right;
totals[idx].total += score.total;
}
}
const active = totals.filter((entry) => entry.total > 0);
const failed = firstFailedStage(totals);
const weak = failed === undefined ? undefined : totals[failed];
const targetStage = weak?.stage ?? STAGES[STAGES.length - 1];
const targetNumber = (weak?.index ?? STAGES.length - 1) + 1;
const startLesson = weak
? targetStage?.lessons.find((lesson) => lesson.slug)
: targetStage?.lessons.findLast((lesson) => lesson.slug);

return (
<div className="grid w-full gap-4 rounded-xl bg-(--tray) p-4.5">
<div className="grid gap-1">
<span className="text-sm font-medium text-(--form)">
{weak ? (
<Trans>
Recommended start · Stage {targetNumber} ({targetStage?.level})
</Trans>
) : (
<Trans>At least two of three right in every stage</Trans>
)}
</span>
<p className="text-xl/snug font-semibold tracking-tight">
{weak && targetStage ? (
<Trans>Start with {i18n._(targetStage.name)}</Trans>
) : (
<Trans>You can start at the end of the course.</Trans>
)}
</p>
{startLesson?.slug && (
<a
href={lessonPath(startLesson.slug, i18n.locale)}
className={buttonClass("primary", "md", "mt-2 justify-self-start")}
>
<Trans>Open {i18n._(startLesson.name)}</Trans>
<ArrowRight aria-hidden="true" data-icon="inline-end" />
</a>
)}
</div>
<ul className="m-0 grid list-none gap-1.5 border-t border-edge pt-3 p-0 text-sm">
{active.map(({ index, stage, right, total }) => (
<li key={stage.hue} className="flex items-center justify-between gap-3">
<span className="text-ink-secondary">
<Trans>
Stage {index + 1} · {stage.level} · {i18n._(stage.name)}
</Trans>
</span>
<span className="font-medium tabular-nums">
<Trans>
{right} of {total}
</Trans>
</span>
</li>
))}
</ul>
</div>
);
}

export function PlacementView() {
const { i18n } = useLingui();
const { session, open, more } = useDrillSession(placementSlugs, drawPlacement);

return (
<LearnLayout languages={{ page: "learnPlacement" }}>
<div className="mx-auto grid max-w-[720px] gap-6 px-5 pt-5 pb-24">
<header className="grid gap-3">
<a
href={localizedPath("learn", i18n.locale)}
className="relative inline-flex items-center gap-1.5 justify-self-start rounded-xs text-sm font-medium text-ink-secondary before:absolute before:inset-x-0 before:-inset-y-3 hoverable:hover:text-ink"
>
<ArrowLeft aria-hidden="true" className="size-4 rtl:-scale-x-100" />
<Trans>All lessons</Trans>
</a>
<h1 className="mt-3 text-[clamp(2.75rem,7vw,4.25rem)] leading-none font-semibold tracking-[-0.035em] text-balance">
<Trans>Find your level</Trans>
</h1>
<p className="max-w-[44ch] text-[clamp(1.125rem,2vw,1.3125rem)] text-pretty text-ink-secondary">
<Trans>
Eighteen short questions from A1 basics to B1 sentences. No hints beforehand — at the
end we suggest where in the course to start.
</Trans>
</p>
</header>
{session.status === "open" ? (
<DrillRunner
key={session.set}
id="placement"
lesson="tasemetest"
title={<Trans>Placement test</Trans>}
questions={session.questions}
sources={session.sources}
repeats={false}
afterScore={(scores) => <PlacementResult scores={scores} />}
end={
<Button variant="secondary" onClick={more}>
<Trans>Take again</Trans>
</Button>
}
/>
) : (
<QuizCard title={<Trans>Placement test</Trans>}>
<p className="text-md text-ink-secondary">
<Trans>Takes about 10 minutes. Includes audio and short typed answers.</Trans>
</p>
<Button variant="primary" loading={session.status === "loading"} onClick={open}>
<Trans>Start placement test</Trans>
</Button>
{session.status === "idle" && session.failed && <LoadProblem />}
</QuizCard>
)}
</div>
</LearnLayout>
);
}
Loading
Loading