Class share links: visitors choose the exam for a generated set
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 24s

On a class link with exams, the visitor's Generate dialog asks which exam the
set is for (opening on the latest exam with materials, with "Not in an exam"
when there is loose material). Only that exam's class materials are offered,
and the set is saved into it. The server requires the choice and refuses
materials from another exam.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-15 22:13:11 -07:00
parent 76112cb4ae
commit d8df5edf30
4 changed files with 98 additions and 9 deletions

View file

@ -108,7 +108,8 @@ export function SharedGenerate({ token, data }: { token: string; data: PublicCol
onClose={() => setOpen(false)}
token={token}
info={info}
documents={data.items.filter((i) => i.kind === 'document')}
allDocuments={data.items.filter((i) => i.kind === 'document')}
exams={data.folders}
onStarted={(next) => qc.setQueryData(key, next)}
/>
</section>
@ -120,17 +121,25 @@ function GenerateDialog({
onClose,
token,
info,
documents,
allDocuments,
exams,
onStarted,
}: {
open: boolean;
onClose: () => void;
token: string;
info: SharedGenerated;
documents: PublicCollection['items'];
allDocuments: PublicCollection['items'];
/** A class link's exams (empty on an exam link, which is one exam already). */
exams: PublicCollection['folders'];
onStarted: (next: SharedGenerated) => void;
}) {
const left = (k: Kind) => Math.max(0, info.usage[k].limit - info.usage[k].used);
// On a class link the visitor picks the exam: its materials are offered, and the set is saved into it.
const inExam = (examId: string) => allDocuments.filter((d) => (examId ? d.folderId === examId : !d.folderId || !exams.some((e) => e.id === d.folderId)));
const looseCount = exams.length ? inExam('').length : 0;
const [examId, setExamId] = useState('');
const documents = exams.length ? inExam(examId) : allDocuments;
const [kind, setKind] = useState<Kind>('quiz');
const [count, setCount] = useState(info.limits.quizMax);
const [difficulty, setDifficulty] = useState<'mixed' | 'easy' | 'medium' | 'hard'>('mixed');
@ -145,7 +154,10 @@ function GenerateDialog({
const k: Kind = left('quiz') > 0 || left('deck') === 0 ? 'quiz' : 'deck';
setKind(k);
setCount(k === 'quiz' ? info.limits.quizMax : 30);
setDocIds(documents.map((d) => d.id));
// Start on the latest exam that has materials.
const start = exams.length ? ([...exams].reverse().find((e) => inExam(e.id).length > 0)?.id ?? '') : '';
setExamId(start);
setDocIds((exams.length ? inExam(start) : allDocuments).map((d) => d.id));
setError('');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
@ -158,6 +170,7 @@ function GenerateDialog({
kind,
count,
difficulty,
...(exams.length ? { examId: examId || null } : {}),
documentIds: docIds.length === documents.length ? [] : docIds,
math: kind === 'quiz' && math,
});
@ -203,6 +216,28 @@ function GenerateDialog({
className="w-full"
/>
{none && <Callout tone="warn">This link has made all its {kind === 'quiz' ? 'quizzes' : 'flashcard sets'} for today. Try again tomorrow.</Callout>}
{exams.length > 0 && (
<Field label="Exam" hint="The set uses only this exam's class materials and is added to it.">
<Select
value={examId}
onChange={(e) => {
setExamId(e.target.value);
setDocIds(inExam(e.target.value).map((d) => d.id));
}}
>
{exams.map((e) => {
const n = inExam(e.id).length;
return (
<option key={e.id} value={e.id} disabled={n === 0}>
{e.name}
{n === 0 ? ' (no class materials)' : ''}
</option>
);
})}
{looseCount > 0 && <option value="">Not in an exam</option>}
</Select>
</Field>
)}
<div className="grid gap-4 sm:grid-cols-2">
<Field label={kind === 'quiz' ? 'Questions' : 'Cards'} hint={`Up to ${max}.`}>
<Input type="number" min={1} max={max} value={count} onChange={(e) => setCount(Math.max(1, Math.min(max, Number(e.target.value) || 1)))} />