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:
Elijah 2026-11-11 18:30:07 -07:00
parent c59591ccb9
commit aed14cd04f
13 changed files with 769 additions and 216 deletions

View file

@ -377,6 +377,31 @@ export default function ClassPage() {
);
};
// Inside each section, items are grouped under a subheading per type.
const KIND_ORDER = ['quiz', 'deck', 'document', 'note'] as const;
const KIND_HEADING = { quiz: 'Quizzes', deck: 'Flashcards', document: 'Documents', note: 'Notes' } as const;
const KIND_HEADING_ICON = { quiz: <BookOpen />, deck: <Layers />, document: <FileText />, note: <NotebookPen /> } as const;
const section = (items: Item[]) => {
if (filter !== 'all') return <ul className="card divide-y divide-line overflow-hidden">{items.map(row)}</ul>;
return (
<div className="card overflow-hidden">
{KIND_ORDER.filter((k) => items.some((i) => i.kind === k)).map((k, n) => {
const list = items.filter((i) => i.kind === k);
return (
<section key={k} aria-label={KIND_HEADING[k]}>
<h3 className={cx('eyebrow flex items-center gap-2 border-b border-line bg-sunken/60 px-4 py-2 [&>svg]:size-3.5', n > 0 && 'border-t')}>
{KIND_HEADING_ICON[k]}
{KIND_HEADING[k]}
<span className="num font-normal">{list.length}</span>
</h3>
<ul className="divide-y divide-line">{list.map(row)}</ul>
</section>
);
})}
</div>
);
};
const loose = visible.filter((i) => !i.folderId || !data.folders.some((f) => f.id === i.folderId));
const searching = query.trim().length > 0 || filter !== 'all';
const isEmpty = data.items.length === 0 && uploads.length === 0;
@ -593,7 +618,7 @@ export default function ClassPage() {
</div>
) : (
<div className="space-y-4">
{loose.length > 0 && <ul className="card divide-y divide-line overflow-hidden">{loose.map(row)}</ul>}
{loose.length > 0 && section(loose)}
{data.folders.map((f) => {
const items = visible.filter((i) => i.folderId === f.id);
if (items.length === 0 && searching) return null;
@ -640,7 +665,7 @@ export default function ClassPage() {
</div>
{!isCollapsed &&
(items.length > 0 ? (
<ul className="card divide-y divide-line overflow-hidden">{items.map(row)}</ul>
section(items)
) : (
<div className="rounded-[14px] border border-dashed border-line-strong px-4 py-4 text-[13px] text-ink-3">Empty. Use "Move" on any item to put it here.</div>
))}

View file

@ -5,7 +5,7 @@ import { useNavigate, useSearchParams } from 'react-router';
import { toast } from 'sonner';
import { CardEditor } from '@/features/editors';
import { Explain } from '@/features/Explain';
import { FlipCard, StudyTopBar } from '@/features/flashcards';
import { FlipCard, KeyHints, StreakChip, StudyFooter, StudyTopBar, useStreak } from '@/features/flashcards';
import { api, errorMessage } from '@/lib/api';
import { useAiStatus, useRefresh } from '@/lib/queries';
import type { DueCounts, QueueCard } from '@/lib/types';
@ -46,9 +46,12 @@ export default function ReviewPage() {
const [queue, setQueue] = useState<QueueCard[] | null>(null);
const [flipped, setFlipped] = useState(false);
const [seenAnswer, setSeenAnswer] = useState(false);
const [leaving, setLeaving] = useState<'left' | 'right' | null>(null);
const { streak, burst, record, reset: resetStreak, hot } = useStreak();
const [busy, setBusy] = useState(false);
const [done, setDone] = useState({ reviewed: 0, again: 0 });
const [last, setLast] = useState<{ cardId: string; snapshot: QueueCard[]; wasAgain: boolean } | null>(null);
const [last, setLast] = useState<{ cardId: string; snapshot: QueueCard[]; wasAgain: boolean; streakBefore: number } | null>(null);
const [editing, setEditing] = useState<QueueCard | null>(null);
const [draft, setDraft] = useState({ front: '', back: '', hint: '', tags: [] as string[] });
const startedAt = useRef(Date.now());
@ -63,15 +66,29 @@ export default function ReviewPage() {
}, [query.data, queue, deckId, classId]);
const current = queue?.[0];
useEffect(() => setFlipped(false), [current?.card.id]);
useEffect(() => {
setFlipped(false);
setSeenAnswer(false);
setLeaving(null);
}, [current?.card.id, current?.card.reps]);
const flip = useCallback(() => {
if (!current || busy) return;
setFlipped((f) => !f);
setSeenAnswer(true);
}, [current, busy]);
const rate = useCallback(
async (rating: 1 | 2 | 3 | 4) => {
if (!current || !queue || busy) return;
if (!current || !queue || busy || !seenAnswer) return;
setBusy(true);
const snapshot = queue;
const streakBefore = streak;
// The card swipes away while the new schedule is being saved.
setLeaving(rating === 1 ? 'left' : 'right');
try {
const res = await api.post<{ result: QueueCard }>('/api/review/answer', { cardId: current.card.id, rating });
const [res] = await Promise.all([api.post<{ result: QueueCard }>('/api/review/answer', { cardId: current.card.id, rating }), new Promise((r) => setTimeout(r, 230))]);
record(rating > 1);
const updated = res.result;
const rest = queue.slice(1);
const dueSoon = (updated.card.state === 1 || updated.card.state === 3) && (updated.card.due ?? 0) - Date.now() < LEARN_AHEAD_MS;
@ -82,19 +99,20 @@ export default function ReviewPage() {
}
setQueue(rest);
setDone((d) => ({ reviewed: d.reviewed + 1, again: d.again + (rating === 1 ? 1 : 0) }));
setLast({ cardId: current.card.id, snapshot, wasAgain: rating === 1 });
setLast({ cardId: current.card.id, snapshot, wasAgain: rating === 1, streakBefore });
if (rest.length === 0) {
// The first load is capped; fetch anything that is still due.
const more = await api.get<QueueResponse>(`/api/review/queue?${scope}`).catch(() => null);
if (more && more.cards.length > 0) setQueue(more.cards);
}
} catch (e) {
setLeaving(null);
toast.error(errorMessage(e));
} finally {
setBusy(false);
}
},
[current, queue, busy, scope],
[current, queue, busy, scope, seenAnswer, streak, record],
);
const undo = useCallback(async () => {
@ -104,13 +122,14 @@ export default function ReviewPage() {
const res = await api.post<{ result: QueueCard }>('/api/review/undo', { cardId: last.cardId });
setQueue(last.snapshot.map((c) => (c.card.id === last.cardId ? res.result : c)));
setDone((d) => ({ reviewed: Math.max(0, d.reviewed - 1), again: Math.max(0, d.again - (last.wasAgain ? 1 : 0)) }));
resetStreak(last.streakBefore);
setLast(null);
} catch (e) {
toast.error(errorMessage(e));
} finally {
setBusy(false);
}
}, [last, busy]);
}, [last, busy, resetStreak]);
const suspend = async () => {
if (!current || !queue) return;
@ -136,19 +155,17 @@ export default function ReviewPage() {
};
useHotkeys({
space: (e) => {
e.preventDefault();
if (current) setFlipped((f) => !f);
},
Enter: () => {
if (!current) return;
if (flipped) void rate(3);
else setFlipped(true);
},
'1': () => flipped && void rate(1),
'2': () => flipped && void rate(2),
'3': () => flipped && void rate(3),
'4': () => flipped && void rate(4),
space: (e) => (e.preventDefault(), flip()),
Enter: flip,
ArrowUp: (e) => (e.preventDefault(), flip()),
ArrowDown: (e) => (e.preventDefault(), flip()),
// Left = missed it, right = got it. The number keys give the finer four-way rating.
ArrowLeft: () => void rate(1),
ArrowRight: () => void rate(3),
'1': () => void rate(1),
'2': () => void rate(2),
'3': () => void rate(3),
'4': () => void rate(4),
u: () => void undo(),
'mod+z': (e) => {
e.preventDefault();
@ -180,8 +197,10 @@ export default function ReviewPage() {
subtitle={scopeTitle.current}
onExit={exit}
progress={totalPlanned ? done.reviewed / totalPlanned : 1}
hot={hot}
right={
<>
<StreakChip streak={streak} />
<div className="hidden items-center gap-1 sm:flex" aria-label="Cards remaining by type">
<Badge tone="accent">{counts.fresh} new</Badge>
<Badge tone="warn">{counts.learning} learning</Badge>
@ -218,9 +237,9 @@ export default function ReviewPage() {
}
/>
<main className="mx-auto flex w-full max-w-2xl flex-1 flex-col px-4 pt-6 pb-40 sm:px-5 sm:pt-10">
<main className="mx-auto flex w-full max-w-4xl flex-1 flex-col justify-center px-4 py-6 sm:px-6 sm:py-8">
{!current ? (
<div className="card m-auto w-full animate-in p-7 text-center sm:p-10">
<div className="card m-auto w-full max-w-xl animate-in p-7 text-center sm:p-10">
<CircleCheck className="mx-auto mb-3 size-12 text-good" strokeWidth={1.6} />
<h1 className="display text-[30px]">{done.reviewed > 0 ? 'Review complete' : 'Nothing due right now'}</h1>
<p className="mx-auto mt-2 max-w-sm text-[15px] text-ink-2">
@ -254,7 +273,9 @@ export default function ReviewPage() {
back={current.card.back}
hint={current.card.hint}
flipped={flipped}
onFlip={() => setFlipped((f) => !f)}
onFlip={flip}
leaving={leaving}
burst={burst}
footer={ai.data?.ready ? <Explain body={{ kind: 'card', front: current.card.front, back: current.card.back }} /> : undefined}
/>
</>
@ -262,47 +283,38 @@ export default function ReviewPage() {
</main>
{current && (
<footer className="safe-bottom fixed inset-x-0 bottom-0 z-20 border-t border-line bg-paper/95 backdrop-blur">
<div className="mx-auto max-w-2xl px-3 py-3 sm:px-5">
{flipped ? (
<div className="grid grid-cols-4 gap-2">
{current.previews.map((p) => (
<button
key={p.rating}
type="button"
disabled={busy}
onClick={() => rate(p.rating)}
className={cx('flex h-[58px] flex-col items-center justify-center rounded-[13px] border bg-surface shadow-1 transition-colors active:scale-[0.98] disabled:opacity-60', RATING_STYLE[p.rating])}
>
<span className="text-[15px] font-semibold">{p.label}</span>
<span className="num text-[11px] opacity-80">{p.interval}</span>
</button>
))}
</div>
) : (
<Button size="lg" variant="primary" block className="h-[58px]" onClick={() => setFlipped(true)}>
Show answer
<span className="hidden sm:inline">
<Kbd>Space</Kbd>
</span>
</Button>
)}
<div className="mt-2 hidden justify-center gap-4 text-[11px] text-ink-3 sm:flex">
<span>
<Kbd>1</Kbd>–<Kbd>4</Kbd> rate
</span>
<span>
<Kbd>Enter</Kbd> good
</span>
<span>
<Kbd>U</Kbd> undo
</span>
<span>
<Kbd>E</Kbd> edit
</span>
<StudyFooter>
{seenAnswer ? (
<div className="grid grid-cols-4 gap-2">
{current.previews.map((p) => (
<button
key={p.rating}
type="button"
disabled={busy}
onClick={() => rate(p.rating)}
className={cx('flex h-[60px] flex-col items-center justify-center rounded-[13px] border bg-surface shadow-1 transition-colors active:scale-[0.98] disabled:opacity-60', RATING_STYLE[p.rating])}
>
<span className="text-[15px] font-semibold">{p.label}</span>
<span className="num text-[11px] opacity-80">{p.interval}</span>
</button>
))}
</div>
</div>
</footer>
) : (
<Button size="lg" variant="primary" block className="h-[60px]" onClick={flip}>
Show answer
</Button>
)}
<KeyHints
items={[
[<><Kbd>Space</Kbd><Kbd>↑</Kbd><Kbd>↓</Kbd></>, 'flip'],
[<Kbd>←</Kbd>, 'again'],
[<Kbd>→</Kbd>, 'good'],
[<><Kbd>1</Kbd>–<Kbd>4</Kbd></>, 'rate'],
[<Kbd>U</Kbd>, 'undo'],
[<Kbd>E</Kbd>, 'edit'],
]}
/>
</StudyFooter>
)}
<Dialog

View file

@ -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>