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.
55 lines
2 KiB
TypeScript
55 lines
2 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo } from "react";
|
|
|
|
import { NotesIcon } from "@/components/icons";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import { highlightSegments, notesSource } from "@/lib/notes-source";
|
|
import type { Activity } from "@/lib/schemas";
|
|
|
|
import { useNoHints, useNotesText } from "./context";
|
|
|
|
/**
|
|
* "From your notes": the passage an activity's answer comes from, with the
|
|
* matching words highlighted green.
|
|
*
|
|
* The quote is the one the generator stored with the activity (verbatim from
|
|
* the notes); decks made before that, or quotes the model trimmed, fall back
|
|
* to a local, IDF-weighted sentence match over the same notes text. It sits
|
|
* inside the feedback panel, so it only appears once the learner has answered,
|
|
* and it disappears in exam mode with the other reveals.
|
|
*/
|
|
export function NotesSource({ activity }: { activity: Activity }) {
|
|
const { t } = useI18n();
|
|
const notes = useNotesText();
|
|
const noHints = useNoHints();
|
|
const match = useMemo(() => (noHints ? null : notesSource(notes, activity)), [noHints, notes, activity]);
|
|
if (!match) return null;
|
|
const pieces = highlightSegments(match.text, match.spans);
|
|
return (
|
|
<div className="mt-3 rounded-[var(--radius-control)] border border-[var(--glass-border)] bg-[var(--surface-strong)] p-3">
|
|
<p className="mb-1 flex items-center gap-1.5 text-[10.5px] font-bold uppercase tracking-wider text-[var(--text-muted)]">
|
|
<NotesIcon className="size-3.5" />
|
|
{t("activity.source")}
|
|
</p>
|
|
<p
|
|
className="text-[13px] leading-relaxed text-[var(--text)]"
|
|
data-notes-source
|
|
data-notes-quote={match.quote ? "1" : "0"}
|
|
>
|
|
{pieces.map((piece, index) =>
|
|
piece.hit ? (
|
|
<mark
|
|
key={index}
|
|
className="rounded bg-emerald-200/85 px-0.5 text-emerald-950 dark:bg-emerald-400/35 dark:text-emerald-50"
|
|
>
|
|
{piece.text}
|
|
</mark>
|
|
) : (
|
|
<span key={index}>{piece.text}</span>
|
|
),
|
|
)}
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|