Address first round of feedback
- Flashcards: whole card flips on click (both sides), 3D turn, swipe-away on grading, streak chip and flame bursts, bigger cards on desktop, arrow keys for everything - Review and browse keep the sidebar on desktop - Quizzes: live practice score, partial-credit explanation, time limit for shared exams - Class page: items grouped by type inside each folder - Import: copyable, editable instructions for outside chatbots - Assistant: reads notes and links to library items Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
c59591ccb9
commit
aed14cd04f
13 changed files with 769 additions and 216 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { ArrowLeft, BookOpen, ChevronRight, Download, FileText, Layers, Link2Off, Moon, NotebookPen, Play, RotateCcw, Sun } from 'lucide-react';
|
||||
import { ArrowLeft, BookOpen, ChevronRight, Download, FileText, Layers, Link2Off, Moon, NotebookPen, Play, RotateCcw, Sun, Timer } from 'lucide-react';
|
||||
import { useEffect, useMemo, useState, type ReactNode } from 'react';
|
||||
import { Link, useNavigate, useParams } from 'react-router';
|
||||
import { isFullyCorrect, scoreQuestion, seededShuffle } from '@shared/content';
|
||||
|
|
@ -9,7 +9,7 @@ import { api, ApiError } from '@/lib/api';
|
|||
import type { AnswerState, PublicCollection, PublicDeck, PublicDocument, PublicNote, PublicPayload, PublicQuiz, SnapshotQuestion } from '@/lib/types';
|
||||
import { cx, formatBytes, plural, useDocumentTitle, useLocalStorage, useTheme } from '@/lib/util';
|
||||
import { Markdown } from '@/ui/Markdown';
|
||||
import { Button, EmptyState, IconButton, PageLoading, Switch } from '@/ui';
|
||||
import { Button, EmptyState, IconButton, Input, PageLoading, Switch } from '@/ui';
|
||||
|
||||
/* ------------------------------ frame ------------------------------ */
|
||||
|
||||
|
|
@ -61,9 +61,10 @@ interface QuizState {
|
|||
index: number;
|
||||
elapsed: number;
|
||||
done: boolean;
|
||||
timeLimitSec?: number | null;
|
||||
}
|
||||
|
||||
function buildQuizState(quiz: PublicQuiz, mode: QuizState['mode'], shuffleQ: boolean, shuffleO: boolean, only?: string[]): QuizState {
|
||||
function buildQuizState(quiz: PublicQuiz, mode: QuizState['mode'], shuffleQ: boolean, shuffleO: boolean, timeLimitSec: number | null, only?: string[]): QuizState {
|
||||
const seed = (Math.random() * 2 ** 32) >>> 0;
|
||||
let ids = quiz.questions.map((q) => q.id).filter((id) => !only || only.includes(id));
|
||||
if (shuffleQ) ids = seededShuffle(ids, seed);
|
||||
|
|
@ -72,12 +73,13 @@ 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 };
|
||||
return { mode, order: ids, optionOrder, answers: {}, flags: [], index: 0, elapsed: 0, done: false, timeLimitSec };
|
||||
}
|
||||
|
||||
function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey: string; back?: { to: string; label: string } }) {
|
||||
const [state, setState] = useLocalStorage<QuizState | null>(storageKey, null);
|
||||
const [prefs, setPrefs] = useLocalStorage('sd.pub.prefs', { mode: 'practice' as 'practice' | 'exam', shuffleQ: true, shuffleO: true });
|
||||
const [prefs, setPrefs] = useLocalStorage('sd.pub.prefs2', { mode: 'practice' as 'practice' | 'exam', shuffleQ: true, shuffleO: true, timed: false, minutes: 0 });
|
||||
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.
|
||||
|
|
@ -95,7 +97,7 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
}, [quiz, state]);
|
||||
|
||||
const begin = (only?: string[]) => {
|
||||
setState(buildQuizState(quiz, prefs.mode, prefs.shuffleQ, prefs.shuffleO, only));
|
||||
setState(buildQuizState(quiz, prefs.mode, prefs.shuffleQ, prefs.shuffleO, prefs.mode === 'exam' && prefs.timed ? minutes * 60 : null, only));
|
||||
setRunning(true);
|
||||
window.scrollTo(0, 0);
|
||||
};
|
||||
|
|
@ -140,7 +142,7 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
flags={state.flags}
|
||||
index={state.index}
|
||||
elapsedSec={state.elapsed}
|
||||
timeLimitSec={null}
|
||||
timeLimitSec={state.timeLimitSec ?? null}
|
||||
sataScoring="partial"
|
||||
exitLabel="Pause"
|
||||
onAnswer={(qid, selected, checked) => setState((s) => (s ? { ...s, answers: { ...s.answers, [qid]: { selected, checked } } } : s))}
|
||||
|
|
@ -200,7 +202,20 @@ function SharedQuiz({ quiz, storageKey, back }: { quiz: PublicQuiz; storageKey:
|
|||
<div className="mt-4 space-y-3.5">
|
||||
<Switch checked={prefs.shuffleQ} onChange={(v) => setPrefs((p) => ({ ...p, shuffleQ: v }))} label="Shuffle questions" />
|
||||
<Switch checked={prefs.shuffleO} onChange={(v) => setPrefs((p) => ({ ...p, shuffleO: v }))} label="Shuffle answer choices" />
|
||||
{prefs.mode === 'exam' && (
|
||||
<>
|
||||
<Switch checked={prefs.timed} onChange={(v) => setPrefs((p) => ({ ...p, timed: v }))} label="Time limit" description="The exam submits itself when time runs out." />
|
||||
{prefs.timed && (
|
||||
<label className="flex items-center gap-2 text-sm text-ink-2">
|
||||
<Timer className="size-4 text-ink-3" />
|
||||
<Input type="number" min={1} max={600} value={minutes} onChange={(e) => setPrefs((p) => ({ ...p, minutes: Math.max(1, Math.min(600, Math.round(Number(e.target.value)) || 1)) }))} className="w-24" aria-label="Minutes" />
|
||||
minutes
|
||||
</label>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-4 text-[13px] text-ink-3">Select-all-that-apply questions give partial credit: a point for each correct choice, minus one for each incorrect choice, never below zero.</p>
|
||||
<Button variant={inProgress ? 'secondary' : 'primary'} size="lg" block className="mt-5" icon={<Play className="fill-current" />} onClick={() => begin()}>
|
||||
{inProgress ? 'Start over' : 'Start'}
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue