"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 (

{t("activity.source")}

{pieces.map((piece, index) => piece.hit ? ( {piece.text} ) : ( {piece.text} ), )}

); }