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
|
|
@ -12,6 +12,7 @@ import {
|
|||
Folder as FolderIcon,
|
||||
FolderInput,
|
||||
FolderPlus,
|
||||
GripVertical,
|
||||
Layers,
|
||||
MoreHorizontal,
|
||||
NotebookPen,
|
||||
|
|
@ -40,6 +41,7 @@ import { assistant, useAssistantContext } from '@/lib/assistantStore';
|
|||
import { useClass, useRefresh } from '@/lib/queries';
|
||||
import type { DeckItem, DocumentItem, Folder, Item, NoteItem, QuizItem } from '@/lib/types';
|
||||
import { cx, downloadFile, formatBytes, gradeTone, plural, timeAgo, useDocumentTitle, useLocalStorage } from '@/lib/util';
|
||||
import { SortableList, type SortableRenderProps } from '@/ui/Sortable';
|
||||
import { Badge, Button, Dialog, EmptyState, ErrorState, Field, IconButton, Input, Menu, MenuItem, MenuSeparator, ProgressBar, Segmented, Skeleton, Textarea, useConfirm } from '@/ui';
|
||||
|
||||
type Filter = 'all' | 'quiz' | 'deck' | 'document' | 'note';
|
||||
|
|
@ -117,7 +119,7 @@ export default function ClassPage() {
|
|||
|
||||
const [filter, setFilter] = useState<Filter>('all');
|
||||
const [query, setQuery] = useState('');
|
||||
const [sort, setSort] = useLocalStorage<'recent' | 'title'>('sd.classSort', 'recent');
|
||||
const [sort, setSort] = useLocalStorage<'manual' | 'recent' | 'title'>('sd.classSort', 'manual');
|
||||
const [collapsed, setCollapsed] = useLocalStorage<Record<string, boolean>>(`sd.folders.${classId}`, {});
|
||||
const [newKind, setNewKind] = useState<{ kind: 'quiz' | 'deck' | 'note' | 'folder'; folderId?: string | null } | null>(null);
|
||||
const [rename, setRename] = useState<Parameters<typeof RenameDialog>[0]['target']>(null);
|
||||
|
|
@ -169,7 +171,9 @@ export default function ClassPage() {
|
|||
const visible = useMemo(() => {
|
||||
const needle = query.trim().toLowerCase();
|
||||
const list = (data?.items ?? []).filter((i) => (filter === 'all' || i.kind === filter) && (!needle || i.title.toLowerCase().includes(needle) || i.description.toLowerCase().includes(needle)));
|
||||
return list.sort((a, b) => (sort === 'title' ? a.title.localeCompare(b.title, undefined, { numeric: true }) : b.updatedAt - a.updatedAt));
|
||||
return list.sort((a, b) =>
|
||||
sort === 'title' ? a.title.localeCompare(b.title, undefined, { numeric: true }) : sort === 'recent' ? b.updatedAt - a.updatedAt : a.sortOrder - b.sortOrder || a.createdAt - b.createdAt,
|
||||
);
|
||||
}, [data, filter, query, sort]);
|
||||
|
||||
if (q.isError) return <ErrorState title="Class not found" message={errorMessage(q.error)} onRetry={() => q.refetch()} />;
|
||||
|
|
@ -258,11 +262,17 @@ export default function ClassPage() {
|
|||
return null;
|
||||
};
|
||||
|
||||
const row = (item: Item) => {
|
||||
const row = (item: Item, sortable?: SortableRenderProps) => {
|
||||
const doc = item.kind === 'document' ? (item as DocumentItem) : null;
|
||||
const busy = doc && (doc.status === 'pending' || doc.status === 'processing');
|
||||
return (
|
||||
<li key={`${item.kind}:${item.id}`} className="group relative flex items-center gap-3 px-3 py-2.5 hover:bg-ink/[0.035] sm:px-4">
|
||||
<li
|
||||
key={`${item.kind}:${item.id}`}
|
||||
ref={sortable?.ref}
|
||||
style={sortable?.style}
|
||||
className={cx('group relative flex items-center gap-3 bg-surface px-3 py-2.5 hover:bg-ink/[0.035] sm:px-4', sortable && 'pl-1 sm:pl-1.5', sortable?.dragging && 'shadow-3')}
|
||||
>
|
||||
{sortable?.handle}
|
||||
<KindIcon item={item} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<Link to={`/${ITEM_URL[item.kind]}/${item.id}`} className="block truncate text-[15px] font-medium text-ink after:absolute after:inset-0">
|
||||
|
|
@ -373,20 +383,51 @@ export default function ClassPage() {
|
|||
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 canSort = sort === 'manual' && !query.trim();
|
||||
const persistOrder = (kind: Item['kind']) => async (ids: string[]) => {
|
||||
// Keys within one folder group; keep the rest of this kind in their current relative order.
|
||||
const all = (data?.items ?? []).filter((i) => i.kind === kind).sort((a, b) => a.sortOrder - b.sortOrder || a.createdAt - b.createdAt).map((i) => i.id);
|
||||
const moved = new Set(ids);
|
||||
let k = 0;
|
||||
const merged = all.map((id) => (moved.has(id) ? ids[k++] : id));
|
||||
try {
|
||||
await api.post(`/api/classes/${classId}/items/reorder`, { kind, ids: merged });
|
||||
await refresh();
|
||||
} catch (e) {
|
||||
toast.error(errorMessage(e));
|
||||
await refresh();
|
||||
}
|
||||
};
|
||||
const list = (items: Item[]) =>
|
||||
canSort && items.length > 1 ? (
|
||||
<SortableList
|
||||
items={items}
|
||||
getKey={(i) => i.id}
|
||||
getLabel={(i) => i.title}
|
||||
noun={items[0].kind === 'deck' ? 'deck' : items[0].kind}
|
||||
onReorder={(ids) => void persistOrder(items[0].kind)(ids)}
|
||||
render={(item, props) => row(item, props)}
|
||||
/>
|
||||
) : (
|
||||
items.map((i) => row(i))
|
||||
);
|
||||
const section = (items: Item[]) => {
|
||||
if (filter !== 'all') return <ul className="card divide-y divide-line overflow-hidden">{items.map(row)}</ul>;
|
||||
if (filter !== 'all') {
|
||||
// One kind only; group by kind anyway so ordering stays within a kind.
|
||||
return <ul className="card divide-y divide-line overflow-hidden">{list(items)}</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);
|
||||
const group = 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>
|
||||
<span className="num font-normal">{group.length}</span>
|
||||
</h3>
|
||||
<ul className="divide-y divide-line">{list.map(row)}</ul>
|
||||
<ul className="divide-y divide-line">{list(group)}</ul>
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
|
|
@ -574,6 +615,7 @@ export default function ClassPage() {
|
|||
value={sort}
|
||||
onChange={setSort}
|
||||
options={[
|
||||
{ value: 'manual', label: <span className="sr-only">Your order (drag to rearrange)</span>, icon: <GripVertical /> },
|
||||
{ value: 'recent', label: <span className="sr-only">Recent</span>, icon: <Clock /> },
|
||||
{ value: 'title', label: <span className="sr-only">A to Z</span>, icon: <ArrowDownAZ /> },
|
||||
]}
|
||||
|
|
@ -609,13 +651,25 @@ export default function ClassPage() {
|
|||
) : (
|
||||
<div className="space-y-4">
|
||||
{loose.length > 0 && section(loose)}
|
||||
{data.folders.map((f) => {
|
||||
<SortableList
|
||||
items={data.folders}
|
||||
getKey={(f) => f.id}
|
||||
getLabel={(f) => f.name}
|
||||
noun="folder"
|
||||
liveAs="div"
|
||||
disabled={!canSort || searching || data.folders.length < 2}
|
||||
onReorder={async (ids) => {
|
||||
await api.post(`/api/classes/${classId}/folders/reorder`, { ids }).catch((e) => toast.error(errorMessage(e)));
|
||||
await refresh();
|
||||
}}
|
||||
render={(f, sortable) => {
|
||||
const items = visible.filter((i) => i.folderId === f.id);
|
||||
if (items.length === 0 && searching) return null;
|
||||
const isCollapsed = collapsed[f.id] && !searching;
|
||||
return (
|
||||
<section key={f.id} aria-label={f.name}>
|
||||
<section key={f.id} aria-label={f.name} ref={sortable.ref} style={sortable.style} className={cx(sortable.dragging && 'rounded-[14px] bg-paper shadow-3')}>
|
||||
<div className="mb-1.5 flex items-center gap-1">
|
||||
{sortable.handle}
|
||||
<button type="button" aria-expanded={!isCollapsed} onClick={() => setCollapsed((c) => ({ ...c, [f.id]: !c[f.id] }))} className="flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg px-1.5 text-left hover:bg-ink/5">
|
||||
<ChevronDown className={cx('size-4 shrink-0 text-ink-3 transition-transform', isCollapsed && '-rotate-90')} />
|
||||
<FolderIcon className="size-4 shrink-0 text-tab" />
|
||||
|
|
@ -661,7 +715,8 @@ export default function ClassPage() {
|
|||
))}
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue