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>
617 lines
25 KiB
TypeScript
617 lines
25 KiB
TypeScript
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { BookOpen, ChartColumn, FileText, GraduationCap, Layers, Library, LogOut, Monitor, Moon, MoreHorizontal, NotebookPen, Plus, Search, Settings, Sparkles, Sun, X } from 'lucide-react';
|
|
import { lazy, Suspense, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
import { Link, NavLink, Outlet, useLocation, useNavigate } from 'react-router';
|
|
import { toast } from 'sonner';
|
|
import { CLASS_COLORS, type ClassColor } from '@shared/content';
|
|
import { api, errorMessage } from '@/lib/api';
|
|
import { assistant, useAssistantState } from '@/lib/assistantStore';
|
|
import { qk, useClasses, useOverview, useRefresh } from '@/lib/queries';
|
|
import type { ClassInfo, SearchHit } from '@/lib/types';
|
|
import { cx, modKey, useDebounced, useHotkeys, useIsDesktop, useTheme, type ThemeChoice } from '@/lib/util';
|
|
import { Brand } from '@/pages/Auth';
|
|
import { Button, ClassDot, Dialog, Field, IconButton, Input, Kbd, Menu, MenuItem, MenuLabel, MenuSeparator, Spinner, Textarea } from '@/ui';
|
|
|
|
const AssistantPanel = lazy(() => import('@/features/AssistantPanel'));
|
|
|
|
/* ------------------------------ class dialog ------------------------------ */
|
|
|
|
export function ClassDialog({ open, onOpenChange, existing }: { open: boolean; onOpenChange: (o: boolean) => void; existing?: ClassInfo }) {
|
|
const refresh = useRefresh();
|
|
const navigate = useNavigate();
|
|
const [name, setName] = useState('');
|
|
const [code, setCode] = useState('');
|
|
const [description, setDescription] = useState('');
|
|
const [color, setColor] = useState<ClassColor | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
setName(existing?.name ?? '');
|
|
setCode(existing?.code ?? '');
|
|
setDescription(existing?.description ?? '');
|
|
setColor(existing?.color ?? null);
|
|
}, [open, existing]);
|
|
|
|
const save = async () => {
|
|
if (!name.trim()) return;
|
|
setBusy(true);
|
|
try {
|
|
if (existing) {
|
|
await api.patch(`/api/classes/${existing.id}`, { name, code, description, color: color ?? existing.color });
|
|
toast.success('Class updated');
|
|
} else {
|
|
const res = await api.post<{ class: ClassInfo }>('/api/classes', { name, code, description, color: color ?? undefined });
|
|
navigate(`/classes/${res.class.id}`);
|
|
}
|
|
await refresh();
|
|
onOpenChange(false);
|
|
} catch (e) {
|
|
toast.error(errorMessage(e));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog
|
|
open={open}
|
|
onOpenChange={onOpenChange}
|
|
title={existing ? 'Edit class' : 'New class'}
|
|
description={existing ? undefined : 'A class holds the quizzes, flashcards, documents and notes for one course.'}
|
|
footer={
|
|
<>
|
|
<Button variant="ghost" onClick={() => onOpenChange(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button variant="primary" onClick={save} loading={busy} disabled={!name.trim()}>
|
|
{existing ? 'Save' : 'Create class'}
|
|
</Button>
|
|
</>
|
|
}
|
|
>
|
|
<form
|
|
className="space-y-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
void save();
|
|
}}
|
|
>
|
|
<div className="grid gap-4 sm:grid-cols-[1fr_140px]">
|
|
<Field label="Name">
|
|
<Input autoFocus value={name} onChange={(e) => setName(e.target.value)} placeholder="Pharmacology" maxLength={120} />
|
|
</Field>
|
|
<Field label="Course code" optional>
|
|
<Input value={code} onChange={(e) => setCode(e.target.value)} placeholder="NUR 356" maxLength={40} />
|
|
</Field>
|
|
</div>
|
|
<Field label="Description" optional>
|
|
<Textarea value={description} onChange={(e) => setDescription(e.target.value)} rows={2} maxLength={2000} />
|
|
</Field>
|
|
<div>
|
|
<div className="mb-2 text-[13px] font-medium">Colour</div>
|
|
<div className="flex flex-wrap gap-2" role="radiogroup" aria-label="Class colour">
|
|
{CLASS_COLORS.map((c) => (
|
|
<button
|
|
key={c}
|
|
type="button"
|
|
role="radio"
|
|
aria-checked={(color ?? existing?.color) === c}
|
|
aria-label={c}
|
|
onClick={() => setColor(c)}
|
|
className={cx('size-8 rounded-full bg-tab ring-offset-2 ring-offset-surface transition-shadow', `tab-${c}`, (color ?? existing?.color) === c ? 'ring-2 ring-ink' : 'hover:ring-2 hover:ring-line-strong')}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
<button type="submit" hidden />
|
|
</form>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
/* ------------------------------ command palette ------------------------------ */
|
|
|
|
const HIT_ICON: Record<SearchHit['kind'], ReactNode> = {
|
|
class: <GraduationCap />,
|
|
quiz: <BookOpen />,
|
|
deck: <Layers />,
|
|
note: <NotebookPen />,
|
|
document: <FileText />,
|
|
question: <BookOpen />,
|
|
card: <Layers />,
|
|
passage: <FileText />,
|
|
};
|
|
const HIT_LABEL: Record<SearchHit['kind'], string> = { class: 'Class', quiz: 'Quiz', deck: 'Deck', note: 'Note', document: 'Document', question: 'Question', card: 'Card', passage: 'Passage' };
|
|
|
|
function hitUrl(hit: SearchHit): string {
|
|
switch (hit.kind) {
|
|
case 'class':
|
|
return `/classes/${hit.id}`;
|
|
case 'quiz':
|
|
return `/quizzes/${hit.id}`;
|
|
case 'deck':
|
|
return `/decks/${hit.id}`;
|
|
case 'note':
|
|
return `/notes/${hit.id}`;
|
|
case 'document':
|
|
return `/documents/${hit.id}`;
|
|
case 'question':
|
|
return `/quizzes/${hit.parentId}?q=${hit.id}`;
|
|
case 'card':
|
|
return `/decks/${hit.parentId}?card=${hit.id}`;
|
|
case 'passage':
|
|
return `/documents/${hit.parentId}?chunk=${hit.id}`;
|
|
}
|
|
}
|
|
|
|
function CommandPalette({ open, onOpenChange, onNewClass }: { open: boolean; onOpenChange: (o: boolean) => void; onNewClass: () => void }) {
|
|
const navigate = useNavigate();
|
|
const [query, setQuery] = useState('');
|
|
const [index, setIndex] = useState(0);
|
|
const debounced = useDebounced(query.trim(), 160);
|
|
const classes = useClasses();
|
|
const search = useQuery({
|
|
queryKey: ['search', debounced],
|
|
queryFn: ({ signal }) => api.get<{ results: SearchHit[] }>(`/api/search?q=${encodeURIComponent(debounced)}`, signal).then((r) => r.results),
|
|
enabled: open && debounced.length >= 2,
|
|
staleTime: 10_000,
|
|
});
|
|
const listRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
setQuery('');
|
|
setIndex(0);
|
|
}
|
|
}, [open]);
|
|
|
|
type Row = { key: string; icon: ReactNode; title: string; meta?: string; sub?: string; color?: string; run: () => void };
|
|
const rows = useMemo<Row[]>(() => {
|
|
const go = (url: string) => () => {
|
|
onOpenChange(false);
|
|
navigate(url);
|
|
};
|
|
if (debounced.length >= 2) {
|
|
return (search.data ?? []).map((h) => ({
|
|
key: `${h.kind}:${h.id}`,
|
|
icon: HIT_ICON[h.kind],
|
|
title: h.title,
|
|
meta: h.semantic ? 'Related passage' : HIT_LABEL[h.kind],
|
|
sub: [h.snippet, h.kind !== 'class' ? h.className : ''].filter(Boolean).join(' · '),
|
|
color: h.classColor,
|
|
run: go(hitUrl(h)),
|
|
}));
|
|
}
|
|
const q = query.trim().toLowerCase();
|
|
const base: Row[] = [
|
|
{ key: 'home', icon: <Library />, title: 'Today', run: go('/') },
|
|
{ key: 'review', icon: <Layers />, title: 'Review due flashcards', run: go('/review') },
|
|
{ key: 'assistant', icon: <Sparkles />, title: 'Ask the assistant', run: () => (onOpenChange(false), assistant.open({ newChat: true })) },
|
|
{ key: 'insights', icon: <ChartColumn />, title: 'Insights', run: go('/insights') },
|
|
{ key: 'new-class', icon: <Plus />, title: 'New class', run: () => (onOpenChange(false), onNewClass()) },
|
|
{ key: 'settings', icon: <Settings />, title: 'Settings', run: go('/settings') },
|
|
...(classes.data ?? []).filter((c) => !c.archived).map((c) => ({ key: `class:${c.id}`, icon: <GraduationCap />, title: c.name, meta: 'Class', color: c.color, run: go(`/classes/${c.id}`) })),
|
|
];
|
|
return q ? base.filter((r) => r.title.toLowerCase().includes(q)) : base;
|
|
}, [debounced, query, search.data, classes.data, navigate, onOpenChange, onNewClass]);
|
|
|
|
useEffect(() => setIndex(0), [rows.length, debounced]);
|
|
useEffect(() => {
|
|
listRef.current?.querySelector(`[data-index="${index}"]`)?.scrollIntoView({ block: 'nearest' });
|
|
}, [index]);
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange} title="Search" bare size="lg">
|
|
<div data-hotkeys="allow">
|
|
<div className="relative border-y border-line">
|
|
<Search className="pointer-events-none absolute top-1/2 left-5 size-[18px] -translate-y-1/2 text-ink-3" aria-hidden />
|
|
<input
|
|
autoFocus
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'ArrowDown') {
|
|
e.preventDefault();
|
|
setIndex((i) => Math.min(rows.length - 1, i + 1));
|
|
} else if (e.key === 'ArrowUp') {
|
|
e.preventDefault();
|
|
setIndex((i) => Math.max(0, i - 1));
|
|
} else if (e.key === 'Enter') {
|
|
e.preventDefault();
|
|
rows[index]?.run();
|
|
}
|
|
}}
|
|
placeholder="Search questions, cards, documents, classes…"
|
|
aria-label="Search"
|
|
role="combobox"
|
|
aria-expanded
|
|
aria-controls="palette-list"
|
|
className="h-13 w-full bg-transparent pr-5 pl-12 text-[15px] outline-none placeholder:text-ink-3"
|
|
/>
|
|
</div>
|
|
<div ref={listRef} id="palette-list" role="listbox" className="max-h-[52vh] min-h-[180px] overflow-y-auto p-2">
|
|
{search.isFetching && debounced.length >= 2 && rows.length === 0 ? (
|
|
<div className="grid h-40 place-items-center">
|
|
<Spinner />
|
|
</div>
|
|
) : rows.length === 0 ? (
|
|
<div className="grid h-40 place-items-center px-6 text-center text-sm text-ink-3">{debounced.length >= 2 ? `Nothing matches "${debounced}".` : 'Type at least two characters to search everything.'}</div>
|
|
) : (
|
|
rows.map((r, i) => (
|
|
<button
|
|
key={r.key}
|
|
type="button"
|
|
role="option"
|
|
aria-selected={i === index}
|
|
data-index={i}
|
|
onMouseMove={() => setIndex(i)}
|
|
onClick={r.run}
|
|
className={cx('flex w-full items-center gap-3 rounded-[10px] px-3 py-2 text-left', i === index && 'bg-ink/7')}
|
|
>
|
|
<span className="grid size-8 shrink-0 place-items-center rounded-lg bg-sunken text-ink-2 [&>svg]:size-4">{r.icon}</span>
|
|
<span className="min-w-0 flex-1">
|
|
<span className="block truncate text-sm font-medium">{r.title}</span>
|
|
{r.sub && <span className="block truncate text-xs text-ink-3">{r.sub}</span>}
|
|
</span>
|
|
{r.color && <ClassDot color={r.color} />}
|
|
{r.meta && <span className="shrink-0 text-xs text-ink-3">{r.meta}</span>}
|
|
</button>
|
|
))
|
|
)}
|
|
</div>
|
|
<div className="hidden items-center gap-4 border-t border-line px-5 py-2.5 text-xs text-ink-3 sm:flex">
|
|
<span className="flex items-center gap-1.5">
|
|
<Kbd>↑</Kbd>
|
|
<Kbd>↓</Kbd> to move
|
|
</span>
|
|
<span className="flex items-center gap-1.5">
|
|
<Kbd>Enter</Kbd> to open
|
|
</span>
|
|
<span className="flex items-center gap-1.5">
|
|
<Kbd>Esc</Kbd> to close
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
/* ------------------------------ navigation ------------------------------ */
|
|
|
|
function ThemeMenu({ children }: { children: ReactNode }) {
|
|
const [theme, setTheme] = useTheme();
|
|
const opts: { value: ThemeChoice; label: string; icon: ReactNode }[] = [
|
|
{ value: 'light', label: 'Light', icon: <Sun /> },
|
|
{ value: 'dark', label: 'Dark', icon: <Moon /> },
|
|
{ value: 'system', label: 'Match system', icon: <Monitor /> },
|
|
];
|
|
return (
|
|
<Menu trigger={children} side="top" align="start">
|
|
<MenuLabel>Appearance</MenuLabel>
|
|
{opts.map((o) => (
|
|
<MenuItem key={o.value} icon={o.icon} onSelect={() => setTheme(o.value)} hint={theme === o.value ? '✓' : undefined}>
|
|
{o.label}
|
|
</MenuItem>
|
|
))}
|
|
</Menu>
|
|
);
|
|
}
|
|
|
|
function useLogout() {
|
|
const qc = useQueryClient();
|
|
return async () => {
|
|
try {
|
|
await api.post('/api/auth/logout');
|
|
} finally {
|
|
qc.setQueryData(qk.auth, { configured: true, authenticated: false });
|
|
qc.removeQueries({ predicate: (q) => q.queryKey[0] !== 'auth' });
|
|
}
|
|
};
|
|
}
|
|
|
|
function NavItem({ to, icon, children, badge, end }: { to: string; icon: ReactNode; children: ReactNode; badge?: ReactNode; end?: boolean }) {
|
|
return (
|
|
<NavLink
|
|
to={to}
|
|
end={end}
|
|
className={({ isActive }) =>
|
|
cx('group flex h-9 items-center gap-2.5 rounded-[9px] px-2.5 text-sm font-medium transition-colors [&>svg]:size-[18px] [&>svg]:shrink-0', isActive ? 'bg-ink/8 text-ink' : 'text-ink-2 hover:bg-ink/5 hover:text-ink')
|
|
}
|
|
>
|
|
{icon}
|
|
<span className="flex-1 truncate">{children}</span>
|
|
{badge}
|
|
</NavLink>
|
|
);
|
|
}
|
|
|
|
function DueBadge({ n }: { n: number }) {
|
|
if (!n) return null;
|
|
return <span className="num rounded-full bg-marker px-1.5 py-px text-[11px] font-semibold text-marker-ink">{n > 999 ? '999+' : n}</span>;
|
|
}
|
|
|
|
function Sidebar({ onSearch, onNewClass }: { onSearch: () => void; onNewClass: () => void }) {
|
|
const classes = useClasses();
|
|
const overview = useOverview();
|
|
const logout = useLogout();
|
|
const [theme] = useTheme();
|
|
const active = (classes.data ?? []).filter((c) => !c.archived);
|
|
const archived = (classes.data ?? []).filter((c) => c.archived);
|
|
|
|
return (
|
|
<aside className="sticky top-0 hidden h-dvh w-[252px] shrink-0 flex-col border-r border-line bg-paper lg:flex">
|
|
<div className="px-4 pt-5 pb-3">
|
|
<Link to="/" className="inline-flex rounded-lg">
|
|
<Brand />
|
|
</Link>
|
|
</div>
|
|
<div className="px-3 pb-2">
|
|
<button type="button" onClick={onSearch} className="flex h-9 w-full items-center gap-2 rounded-[10px] border border-line-strong bg-surface px-2.5 text-sm text-ink-3 shadow-1 hover:border-ink-3">
|
|
<Search className="size-4" aria-hidden />
|
|
<span className="flex-1 text-left">Search</span>
|
|
<Kbd>{modKey} K</Kbd>
|
|
</button>
|
|
</div>
|
|
<nav aria-label="Main" className="space-y-0.5 px-3">
|
|
<NavItem to="/" end icon={<Library />}>
|
|
Today
|
|
</NavItem>
|
|
<NavItem to="/review" icon={<Layers />} badge={<DueBadge n={overview.data?.due.total ?? 0} />}>
|
|
Review
|
|
</NavItem>
|
|
<NavItem to="/assistant" icon={<Sparkles />}>
|
|
Assistant
|
|
</NavItem>
|
|
<NavItem to="/insights" icon={<ChartColumn />}>
|
|
Insights
|
|
</NavItem>
|
|
</nav>
|
|
|
|
<div className="mt-5 flex items-center justify-between px-5 pb-1.5">
|
|
<span className="eyebrow">Classes</span>
|
|
<IconButton label="New class" size="sm" onClick={onNewClass} className="-mr-2 size-7">
|
|
<Plus />
|
|
</IconButton>
|
|
</div>
|
|
<nav aria-label="Classes" className="min-h-0 flex-1 space-y-0.5 overflow-y-auto px-3 pb-3">
|
|
{classes.isLoading && <div className="space-y-2 px-2 pt-1">{[0, 1, 2].map((i) => <div key={i} className="skeleton h-6" />)}</div>}
|
|
{active.map((c) => (
|
|
<NavLink
|
|
key={c.id}
|
|
to={`/classes/${c.id}`}
|
|
className={({ isActive }) => cx('flex h-9 items-center gap-2.5 rounded-[9px] px-2.5 text-sm transition-colors', isActive ? 'bg-ink/8 font-medium text-ink' : 'text-ink-2 hover:bg-ink/5 hover:text-ink')}
|
|
>
|
|
<ClassDot color={c.color} />
|
|
<span className="flex-1 truncate">{c.name}</span>
|
|
<DueBadge n={c.due} />
|
|
</NavLink>
|
|
))}
|
|
{!classes.isLoading && active.length === 0 && (
|
|
<button type="button" onClick={onNewClass} className="mt-1 w-full rounded-[10px] border border-dashed border-line-strong px-3 py-3 text-left text-[13px] text-ink-3 hover:border-ink-3 hover:text-ink-2">
|
|
Create your first class to get started.
|
|
</button>
|
|
)}
|
|
{archived.length > 0 && (
|
|
<details className="pt-2">
|
|
<summary className="px-2.5 py-1 text-xs text-ink-3 hover:text-ink-2">Archived ({archived.length})</summary>
|
|
{archived.map((c) => (
|
|
<NavLink key={c.id} to={`/classes/${c.id}`} className="flex h-8 items-center gap-2.5 rounded-[9px] px-2.5 text-sm text-ink-3 hover:bg-ink/5">
|
|
<ClassDot color={c.color} className="opacity-50" />
|
|
<span className="truncate">{c.name}</span>
|
|
</NavLink>
|
|
))}
|
|
</details>
|
|
)}
|
|
</nav>
|
|
|
|
<div className="flex items-center gap-1 border-t border-line px-3 py-2.5">
|
|
<NavLink to="/settings" className={({ isActive }) => cx('flex h-9 flex-1 items-center gap-2.5 rounded-[9px] px-2.5 text-sm font-medium', isActive ? 'bg-ink/8 text-ink' : 'text-ink-2 hover:bg-ink/5 hover:text-ink')}>
|
|
<Settings className="size-[18px]" />
|
|
Settings
|
|
</NavLink>
|
|
<ThemeMenu>
|
|
<IconButton label="Appearance" size="sm" tooltip={false}>
|
|
{theme === 'dark' ? <Moon /> : theme === 'light' ? <Sun /> : <Monitor />}
|
|
</IconButton>
|
|
</ThemeMenu>
|
|
<IconButton label="Sign out" size="sm" onClick={logout}>
|
|
<LogOut />
|
|
</IconButton>
|
|
</div>
|
|
</aside>
|
|
);
|
|
}
|
|
|
|
function MobileNav({ onSearch, onNewClass }: { onSearch: () => void; onNewClass: () => void }) {
|
|
const classes = useClasses();
|
|
const overview = useOverview();
|
|
const logout = useLogout();
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
const [, setTheme] = useTheme();
|
|
const [classesOpen, setClassesOpen] = useState(false);
|
|
const tab = (active: boolean) => cx('flex flex-1 flex-col items-center justify-center gap-0.5 text-[11px] font-medium [&>svg]:size-[21px]', active ? 'text-ink' : 'text-ink-3');
|
|
const onClass = location.pathname.startsWith('/classes');
|
|
|
|
return (
|
|
<>
|
|
<header className="sticky top-0 z-30 flex h-13 items-center justify-between border-b border-line bg-paper/92 px-4 backdrop-blur lg:hidden">
|
|
<Link to="/" className="rounded-lg">
|
|
<Brand />
|
|
</Link>
|
|
<IconButton label="Search" onClick={onSearch} tooltip={false}>
|
|
<Search />
|
|
</IconButton>
|
|
</header>
|
|
<nav aria-label="Main" className="safe-bottom fixed inset-x-0 bottom-0 z-30 border-t border-line bg-paper/95 backdrop-blur lg:hidden">
|
|
<div className="flex h-14">
|
|
<NavLink to="/" end className={({ isActive }) => tab(isActive)}>
|
|
<Library />
|
|
Today
|
|
</NavLink>
|
|
<button type="button" className={tab(onClass)} onClick={() => setClassesOpen(true)}>
|
|
<GraduationCap />
|
|
Classes
|
|
</button>
|
|
<NavLink to="/review" className={({ isActive }) => cx(tab(isActive), 'relative')}>
|
|
<Layers />
|
|
Review
|
|
{(overview.data?.due.total ?? 0) > 0 && <span className="absolute top-1.5 left-1/2 ml-2 size-2 rounded-full bg-marker ring-2 ring-paper" />}
|
|
</NavLink>
|
|
<NavLink to="/assistant" className={({ isActive }) => tab(isActive)}>
|
|
<Sparkles />
|
|
Assistant
|
|
</NavLink>
|
|
<Menu
|
|
side="top"
|
|
trigger={
|
|
<button type="button" className={tab(location.pathname.startsWith('/settings') || location.pathname.startsWith('/insights'))}>
|
|
<MoreHorizontal />
|
|
More
|
|
</button>
|
|
}
|
|
>
|
|
<MenuItem icon={<ChartColumn />} onSelect={() => navigate('/insights')}>
|
|
Insights
|
|
</MenuItem>
|
|
<MenuItem icon={<Settings />} onSelect={() => navigate('/settings')}>
|
|
Settings
|
|
</MenuItem>
|
|
<MenuSeparator />
|
|
<MenuLabel>Appearance</MenuLabel>
|
|
<MenuItem icon={<Sun />} onSelect={() => setTheme('light')}>
|
|
Light
|
|
</MenuItem>
|
|
<MenuItem icon={<Moon />} onSelect={() => setTheme('dark')}>
|
|
Dark
|
|
</MenuItem>
|
|
<MenuItem icon={<Monitor />} onSelect={() => setTheme('system')}>
|
|
Match system
|
|
</MenuItem>
|
|
<MenuSeparator />
|
|
<MenuItem icon={<LogOut />} onSelect={logout}>
|
|
Sign out
|
|
</MenuItem>
|
|
</Menu>
|
|
</div>
|
|
</nav>
|
|
<Dialog open={classesOpen} onOpenChange={setClassesOpen} title="Classes" bare>
|
|
<div className="px-3 pb-4">
|
|
{(classes.data ?? []).map((c) => (
|
|
<button
|
|
key={c.id}
|
|
type="button"
|
|
onClick={() => {
|
|
setClassesOpen(false);
|
|
navigate(`/classes/${c.id}`);
|
|
}}
|
|
className={cx('flex h-12 w-full items-center gap-3 rounded-xl px-3 text-left text-[15px] hover:bg-ink/5', c.archived && 'opacity-60')}
|
|
>
|
|
<ClassDot color={c.color} className="size-3" />
|
|
<span className="flex-1 truncate font-medium">{c.name}</span>
|
|
<DueBadge n={c.due} />
|
|
</button>
|
|
))}
|
|
<Button
|
|
block
|
|
className="mt-2"
|
|
icon={<Plus />}
|
|
onClick={() => {
|
|
setClassesOpen(false);
|
|
onNewClass();
|
|
}}
|
|
>
|
|
New class
|
|
</Button>
|
|
</div>
|
|
</Dialog>
|
|
</>
|
|
);
|
|
}
|
|
|
|
/* ------------------------------ shell ------------------------------ */
|
|
|
|
export function Shell() {
|
|
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
const [classDialog, setClassDialog] = useState(false);
|
|
const isDesktop = useIsDesktop();
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
const { open: assistantOpen, seed } = useAssistantState();
|
|
const onAssistantPage = location.pathname.startsWith('/assistant');
|
|
// Study screens lay themselves out edge to edge and bring their own header and footer.
|
|
const immersive = location.pathname === '/review' || /^\/decks\/[^/]+\/cram$/.test(location.pathname);
|
|
|
|
useHotkeys({
|
|
'mod+k': (e) => {
|
|
e.preventDefault();
|
|
setPaletteOpen((v) => !v);
|
|
},
|
|
'mod+j': (e) => {
|
|
e.preventDefault();
|
|
if (onAssistantPage) return;
|
|
assistant.toggle();
|
|
},
|
|
'/': (e) => {
|
|
e.preventDefault();
|
|
setPaletteOpen(true);
|
|
},
|
|
});
|
|
|
|
// On phones the assistant is a full page rather than a drawer.
|
|
useEffect(() => {
|
|
if (assistantOpen && !isDesktop && !onAssistantPage) {
|
|
assistant.close();
|
|
navigate('/assistant', { state: { seed } });
|
|
}
|
|
}, [assistantOpen, isDesktop, onAssistantPage, navigate, seed]);
|
|
|
|
useEffect(() => {
|
|
if (onAssistantPage && assistantOpen) assistant.close();
|
|
}, [onAssistantPage, assistantOpen]);
|
|
|
|
const showDrawer = assistantOpen && isDesktop && !onAssistantPage;
|
|
|
|
return (
|
|
<div className="flex min-h-dvh">
|
|
<a href="#main" className="sr-only focus:not-sr-only focus:fixed focus:top-3 focus:left-3 focus:z-[90] focus:rounded-lg focus:bg-ink focus:px-3 focus:py-2 focus:text-paper">
|
|
Skip to content
|
|
</a>
|
|
<Sidebar onSearch={() => setPaletteOpen(true)} onNewClass={() => setClassDialog(true)} />
|
|
<div className="flex min-w-0 flex-1 flex-col">
|
|
{!immersive && <MobileNav onSearch={() => setPaletteOpen(true)} onNewClass={() => setClassDialog(true)} />}
|
|
<main id="main" tabIndex={-1} className={cx('w-full flex-1 outline-none', !immersive && 'mx-auto max-w-[1080px] px-4 pt-6 pb-28 sm:px-8 lg:pt-10 lg:pb-16')}>
|
|
<Outlet />
|
|
</main>
|
|
</div>
|
|
{showDrawer && (
|
|
<aside aria-label="Assistant" className="fixed top-0 right-0 z-40 hidden h-dvh w-[420px] shrink-0 animate-drawer flex-col border-l border-line bg-surface shadow-3 lg:flex min-[1360px]:sticky min-[1360px]:z-20 min-[1360px]:w-[440px] min-[1360px]:shadow-none">
|
|
<Suspense fallback={<div className="grid flex-1 place-items-center"><Spinner /></div>}>
|
|
<AssistantPanel
|
|
variant="drawer"
|
|
headerAction={
|
|
<IconButton label="Close assistant" size="sm" onClick={() => assistant.close()}>
|
|
<X />
|
|
</IconButton>
|
|
}
|
|
/>
|
|
</Suspense>
|
|
</aside>
|
|
)}
|
|
{!showDrawer && !onAssistantPage && !immersive && isDesktop && (
|
|
<button
|
|
type="button"
|
|
onClick={() => assistant.open()}
|
|
className="fixed right-6 bottom-6 z-20 flex h-11 items-center gap-2 rounded-full bg-ink pr-4 pl-3.5 text-sm font-medium text-paper shadow-2 transition-transform hover:-translate-y-0.5"
|
|
>
|
|
<Sparkles className="size-4 text-marker" />
|
|
Assistant
|
|
<span className="ml-1 rounded border border-paper/25 px-1 py-px font-mono text-[10px] text-paper/70">{modKey} J</span>
|
|
</button>
|
|
)}
|
|
<CommandPalette open={paletteOpen} onOpenChange={setPaletteOpen} onNewClass={() => setClassDialog(true)} />
|
|
<ClassDialog open={classDialog} onOpenChange={setClassDialog} />
|
|
</div>
|
|
);
|
|
}
|