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

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