Study cards: from-your-notes, read aloud, timed runs
From your notes: the generator now stores a verbatim source quote with every activity (schema + prompt + a server-side clamp so a chatty model cannot drop a card), and the feedback panel shows the sentence that carries it with the quote highlighted green. Decks made before the change, and quotes the model trimmed, fall back to a local IDF-weighted match over the saved notes text (lib/notes-source.ts): nothing is shown unless at least two distinct terms land. The passage hides in exam mode with the other reveals. Read aloud: a Web Speech API speaker control on the text a learner reads (flashcard faces, questions, statements, sentences, instructions) via lib/speech.ts and components/SpeakButton.tsx — one utterance app-wide, a voice matched to the deck's language, and no button at all where the browser has no speech synthesis. It used to sit inside the flashcard's flip button (nested buttons, tapping it flipped the card); it now lives next to the hint row. Timed runs: the feed chrome carries a timer chip (off by default) that gives each card 30 seconds; a card that runs out is recorded as a miss through the same path as a wrong answer (history + SRS agree), shows a toast, and the feed moves straight on with a fresh budget. handleAnswered ignores a second result per card, so a timeout plus a manual answer cannot record twice. The generator's type spec now names what each type suits (language decks lean on flashcards/matching/fill blank, ordering needs a real sequence, short answer reasoning), so the deck-aware guidance covers all seven types. New activities-test suite (24 checks: quote path, local path, the green mark, the speech stub, the timed run on Playwright's fake clock), registered in run-all; phase2 pins that the notes passage stays hidden in exam mode; en+cs keys for every new string; no new dependencies. Version 0.6.1, SW v83.
This commit is contained in:
parent
786d6cf1ae
commit
796e2e9fe9
26 changed files with 1068 additions and 51 deletions
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
import { motion } from "framer-motion";
|
||||
import { useAppReducedMotion as useReducedMotion } from "@/lib/motion-pref";
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import type { Activity } from "@/lib/schemas";
|
||||
import { useIsPhone } from "@/lib/use-phone";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui";
|
||||
import { useNoHints } from "./context";
|
||||
import { NotesSource } from "./NotesSource";
|
||||
|
||||
export { NoHintsProvider, useNoHints, NotesTextProvider, useNotesText } from "./context";
|
||||
export { NotesSource } from "./NotesSource";
|
||||
|
||||
export type ActivityComponentProps<A extends Activity = Activity> = {
|
||||
activity: A;
|
||||
|
|
@ -150,6 +154,7 @@ export function FeedbackPanel({
|
|||
nextLabel,
|
||||
headline,
|
||||
detail,
|
||||
activity,
|
||||
children,
|
||||
}: {
|
||||
correct: boolean;
|
||||
|
|
@ -161,6 +166,8 @@ export function FeedbackPanel({
|
|||
nextLabel?: string;
|
||||
headline?: string;
|
||||
detail?: React.ReactNode;
|
||||
/** The card being answered, so the panel can point back into the notes. */
|
||||
activity?: Activity;
|
||||
children?: React.ReactNode;
|
||||
}) {
|
||||
const { t } = useI18n();
|
||||
|
|
@ -210,6 +217,8 @@ export function FeedbackPanel({
|
|||
{explanation}
|
||||
</p>
|
||||
|
||||
{activity ? <NotesSource activity={activity} /> : null}
|
||||
|
||||
{children}
|
||||
|
||||
<div className="mt-4 flex items-center justify-end">
|
||||
|
|
@ -230,17 +239,5 @@ export function Hint({ children }: { children: React.ReactNode }) {
|
|||
return <p className="hint-line text-sm text-frost-600 dark:text-frost-300">{children}</p>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exam mode sets this through ActivityRenderer's `noHints` prop so the
|
||||
* affordances that give the answer away disappear without touching every
|
||||
* activity component.
|
||||
*/
|
||||
const NoHintsContext = createContext(false);
|
||||
|
||||
export function NoHintsProvider({ value, children }: { value: boolean; children: React.ReactNode }) {
|
||||
return <NoHintsContext.Provider value={value}>{children}</NoHintsContext.Provider>;
|
||||
}
|
||||
|
||||
export function useNoHints(): boolean {
|
||||
return useContext(NoHintsContext);
|
||||
}
|
||||
/* The no-hints / notes-text contexts live in ./context: NotesSource reads them
|
||||
while this file renders NotesSource, so keeping them apart avoids a cycle. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue