Add drag reordering, exam deadlines, frozen shared quizzes, batched OCR and semantic search
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
- Drag-to-reorder for class materials, folders, quiz questions and deck cards. Pointer-based so touch works, plus keyboard (arrows/Home/End) with screen-reader announcements. - Timed exams get a wall-clock deadline. The server refuses late answers, submits overdue exams with what was saved, and the countdown keeps running while the page is closed. - Shared quiz sessions keep a frozen copy of their questions and flag later owner edits. - Scanned PDFs are read in cached 8-page batches with real page numbers (pdf-lib), removing the 30 MB whole-file limit. Compatible providers now receive PDFs as file parts. - Semantic search: embeddings for OpenAI, Gemini, Ollama and compatible servers, background indexing into chunk_vectors (migration 2), hybrid keyword + vector ranking for search, the assistant and focused generation, and a Settings -> AI section. 181 tests pass locally and in the Docker test stage on Node 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3046e46d1c
commit
ccdad9728b
39 changed files with 1772 additions and 121 deletions
|
|
@ -62,6 +62,27 @@ interface QuizState {
|
|||
elapsed: number;
|
||||
done: boolean;
|
||||
timeLimitSec?: number | null;
|
||||
/** End of a timed exam (epoch ms). The clock keeps running while the page is closed. */
|
||||
deadlineAt?: number | null;
|
||||
/**
|
||||
* The questions exactly as they were when the session began (options in display order).
|
||||
* Edits the owner makes later never change an in-progress session or a finished score.
|
||||
* Sessions saved before this existed are rebuilt from the live quiz.
|
||||
*/
|
||||
questions?: SnapshotQuestion[];
|
||||
/** Fingerprint of the quiz content at the start, to notice later edits. */
|
||||
version?: string;
|
||||
}
|
||||
|
||||
/** Short, stable fingerprint of a quiz's questions (FNV-1a over its JSON). */
|
||||
function quizVersion(quiz: PublicQuiz): string {
|
||||
const text = JSON.stringify(quiz.questions);
|
||||
let h = 0x811c9dc5;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
h ^= text.charCodeAt(i);
|
||||
h = Math.imul(h, 0x01000193) >>> 0;
|
||||
}
|
||||
return h.toString(36);
|
||||
}
|
||||
|
||||
function buildQuizState(quiz: PublicQuiz, mode: QuizState['mode'], shuffleQ: boolean, shuffleO: boolean, timeLimitSec: number | null, only?: string[]): QuizState {
|
||||
|
|
@ -73,7 +94,26 @@ function buildQuizState(quiz: PublicQuiz, mode: QuizState['mode'], shuffleQ: boo
|
|||
const optionIds = q.options.map((o) => o.id);
|
||||
optionOrder[q.id] = shuffleO ? seededShuffle(optionIds, seed + i + 1) : optionIds;
|
||||
});
|
||||
return { mode, order: ids, optionOrder, answers: {}, flags: [], index: 0, elapsed: 0, done: false, timeLimitSec };
|
||||
const byId = new Map(quiz.questions.map((q) => [q.id, q]));
|
||||
const questions = ids.map((id) => {
|
||||
const q = byId.get(id)!;
|
||||
const order = optionOrder[id];
|
||||
return { ...q, options: order.map((oid) => q.options.find((o) => o.id === oid)!).filter(Boolean) };
|
||||
});
|
||||
return {
|
||||
mode,
|
||||
order: ids,
|
||||
optionOrder,
|
||||
answers: {},
|
||||
flags: [],
|
||||
index: 0,
|
||||
elapsed: 0,
|
||||
done: false,
|
||||
timeLimitSec,
|
||||
deadlineAt: timeLimitSec ? Date.now() + timeLimitSec * 1000 : null,
|
||||
questions,
|
||||
version: quizVersion(quiz),
|
||||
};
|
||||
}
|
||||
|
||||
function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey: string; back?: { to: string; label: string } }) {
|
||||
|
|
@ -82,9 +122,11 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
const minutes = prefs.minutes > 0 ? prefs.minutes : Math.max(5, Math.round(quiz.questions.length * 1.2));
|
||||
const [running, setRunning] = useState(false);
|
||||
|
||||
// Rebuild the session's questions from the saved order; drop anything the owner has since removed.
|
||||
// Frozen sessions keep their own copy. Older saved sessions are rebuilt from the saved order,
|
||||
// dropping anything the owner has since removed.
|
||||
const questions = useMemo<SnapshotQuestion[]>(() => {
|
||||
if (!state) return [];
|
||||
if (state.questions?.length) return state.questions;
|
||||
const byId = new Map(quiz.questions.map((q) => [q.id, q]));
|
||||
return state.order
|
||||
.map((id) => byId.get(id))
|
||||
|
|
@ -96,6 +138,17 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
});
|
||||
}, [quiz, state]);
|
||||
|
||||
const changed = Boolean(state?.version && state.version !== quizVersion(quiz));
|
||||
const expired = Boolean(state && !state.done && state.deadlineAt && Date.now() > state.deadlineAt);
|
||||
|
||||
// A timed exam whose deadline passed while the page was closed is submitted as it stands.
|
||||
useEffect(() => {
|
||||
if (expired) {
|
||||
setState((s) => (s && !s.done ? { ...s, done: true, elapsed: s.timeLimitSec ?? s.elapsed } : s));
|
||||
setRunning(false);
|
||||
}
|
||||
}, [expired, setState]);
|
||||
|
||||
const begin = (only?: string[]) => {
|
||||
setState(buildQuizState(quiz, prefs.mode, prefs.shuffleQ, prefs.shuffleO, prefs.mode === 'exam' && prefs.timed ? minutes * 60 : null, only));
|
||||
setRunning(true);
|
||||
|
|
@ -143,8 +196,9 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
index={state.index}
|
||||
elapsedSec={state.elapsed}
|
||||
timeLimitSec={state.timeLimitSec ?? null}
|
||||
deadlineAt={state.deadlineAt ?? null}
|
||||
sataScoring="partial"
|
||||
exitLabel="Pause"
|
||||
exitLabel={state.deadlineAt ? 'Leave (the clock keeps running)' : 'Pause'}
|
||||
onAnswer={(qid, selected, checked) => setState((s) => (s ? { ...s, answers: { ...s.answers, [qid]: { selected, checked } } } : s))}
|
||||
onFlags={(flags) => setState((s) => (s ? { ...s, flags } : s))}
|
||||
onIndex={(index) => setState((s) => (s ? { ...s, index } : s))}
|
||||
|
|
@ -179,7 +233,9 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
<div className="text-sm font-semibold">You have a session in progress</div>
|
||||
<div className="text-[13px] text-ink-2">
|
||||
{answered} of {questions.length} answered
|
||||
{state.deadlineAt ? ` · ${Math.max(0, Math.ceil((state.deadlineAt - Date.now()) / 60000))} min left` : ''}
|
||||
</div>
|
||||
{changed && <div className="mt-1 text-[13px] text-ink-2">This quiz has been updated since you started. Your session keeps the version you began with; start over for the latest.</div>}
|
||||
</div>
|
||||
<Button variant="primary" icon={<Play className="fill-current" />} onClick={() => setRunning(true)}>
|
||||
Resume
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue