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.
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { createContext, useContext } from "react";
|
|
|
|
/**
|
|
* The two ambient facts an activity card needs from the screen around it:
|
|
*
|
|
* - the deck's own notes text, so the feedback panel can show the passage an
|
|
* answer came from (NotesSource). Absent on screens with no notes (the
|
|
* homework guide's checkpoints);
|
|
* - whether reveals are off (exam mode), which hides the hints *and* that
|
|
* passage — both give the answer away.
|
|
*
|
|
* Its own module (not shared.tsx) because NotesSource needs these hooks while
|
|
* shared.tsx renders NotesSource; a cycle there would be fragile.
|
|
*/
|
|
|
|
const NotesTextContext = createContext<string | undefined>(undefined);
|
|
|
|
export function NotesTextProvider({ value, children }: { value?: string; children: React.ReactNode }) {
|
|
return <NotesTextContext.Provider value={value}>{children}</NotesTextContext.Provider>;
|
|
}
|
|
|
|
export function useNotesText(): string | undefined {
|
|
return useContext(NotesTextContext);
|
|
}
|
|
|
|
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);
|
|
}
|