From 74a98ac1f1ce417078114b760e6ae638f9b93bb9 Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 11 Nov 2026 08:53:01 -0700 Subject: [PATCH] Add the V2 web app: design system, shell, study flows, AI, settings, sharing Co-Authored-By: Claude Fable 5.2 --- .env.example | 36 ++ .gitignore | 1 + scripts/build-server.mjs | 14 + scripts/make-icons.mjs | 60 +++ server/main.ts | 6 + server/routes/documents.ts | 9 +- vite.config.ts | 31 ++ web/index.html | 20 + web/public/icon-180.png | Bin 0 -> 2418 bytes web/public/icon-192.png | Bin 0 -> 2465 bytes web/public/icon-512.png | Bin 0 -> 7224 bytes web/public/icon.svg | 8 + web/public/manifest.webmanifest | 15 + web/public/robots.txt | 2 + web/public/sw.js | 50 ++ web/public/theme.js | 10 + web/src/app/Shell.tsx | 615 +++++++++++++++++++++++ web/src/features/AiSettings.tsx | 706 +++++++++++++++++++++++++++ web/src/features/AssistantPanel.tsx | 496 +++++++++++++++++++ web/src/features/Explain.tsx | 110 +++++ web/src/features/GenerateDialog.tsx | 321 ++++++++++++ web/src/features/ImportDialog.tsx | 242 +++++++++ web/src/features/charts.tsx | 162 +++++++ web/src/features/dialogs.tsx | 372 ++++++++++++++ web/src/features/editors.tsx | 311 ++++++++++++ web/src/features/flashcards.tsx | 290 +++++++++++ web/src/features/quiz.tsx | 519 ++++++++++++++++++++ web/src/features/study.ts | 42 ++ web/src/lib/api.ts | 147 ++++++ web/src/lib/assistantStore.ts | 67 +++ web/src/lib/queries.ts | 54 +++ web/src/lib/types.ts | 514 ++++++++++++++++++++ web/src/lib/util.ts | 288 +++++++++++ web/src/main.tsx | 182 +++++++ web/src/pages/AssistantPage.tsx | 51 ++ web/src/pages/Auth.tsx | 125 +++++ web/src/pages/ClassPage.tsx | 729 ++++++++++++++++++++++++++++ web/src/pages/CramPage.tsx | 69 +++ web/src/pages/DeckPage.tsx | 354 ++++++++++++++ web/src/pages/DocumentPage.tsx | 347 +++++++++++++ web/src/pages/DraftPage.tsx | 514 ++++++++++++++++++++ web/src/pages/Home.tsx | 311 ++++++++++++ web/src/pages/InsightsPage.tsx | 203 ++++++++ web/src/pages/NotePage.tsx | 233 +++++++++ web/src/pages/QuizPage.tsx | 679 ++++++++++++++++++++++++++ web/src/pages/ReviewPage.tsx | 328 +++++++++++++ web/src/pages/SessionPage.tsx | 209 ++++++++ web/src/pages/SettingsPage.tsx | 626 ++++++++++++++++++++++++ web/src/pages/SharedPage.tsx | 402 +++++++++++++++ web/src/styles.css | 497 +++++++++++++++++++ web/src/ui/Markdown.tsx | 109 +++++ web/src/ui/index.tsx | 491 +++++++++++++++++++ 52 files changed, 11976 insertions(+), 1 deletion(-) create mode 100644 .env.example create mode 100644 scripts/build-server.mjs create mode 100644 scripts/make-icons.mjs create mode 100644 vite.config.ts create mode 100644 web/index.html create mode 100644 web/public/icon-180.png create mode 100644 web/public/icon-192.png create mode 100644 web/public/icon-512.png create mode 100644 web/public/icon.svg create mode 100644 web/public/manifest.webmanifest create mode 100644 web/public/robots.txt create mode 100644 web/public/sw.js create mode 100644 web/public/theme.js create mode 100644 web/src/app/Shell.tsx create mode 100644 web/src/features/AiSettings.tsx create mode 100644 web/src/features/AssistantPanel.tsx create mode 100644 web/src/features/Explain.tsx create mode 100644 web/src/features/GenerateDialog.tsx create mode 100644 web/src/features/ImportDialog.tsx create mode 100644 web/src/features/charts.tsx create mode 100644 web/src/features/dialogs.tsx create mode 100644 web/src/features/editors.tsx create mode 100644 web/src/features/flashcards.tsx create mode 100644 web/src/features/quiz.tsx create mode 100644 web/src/features/study.ts create mode 100644 web/src/lib/api.ts create mode 100644 web/src/lib/assistantStore.ts create mode 100644 web/src/lib/queries.ts create mode 100644 web/src/lib/types.ts create mode 100644 web/src/lib/util.ts create mode 100644 web/src/main.tsx create mode 100644 web/src/pages/AssistantPage.tsx create mode 100644 web/src/pages/Auth.tsx create mode 100644 web/src/pages/ClassPage.tsx create mode 100644 web/src/pages/CramPage.tsx create mode 100644 web/src/pages/DeckPage.tsx create mode 100644 web/src/pages/DocumentPage.tsx create mode 100644 web/src/pages/DraftPage.tsx create mode 100644 web/src/pages/Home.tsx create mode 100644 web/src/pages/InsightsPage.tsx create mode 100644 web/src/pages/NotePage.tsx create mode 100644 web/src/pages/QuizPage.tsx create mode 100644 web/src/pages/ReviewPage.tsx create mode 100644 web/src/pages/SessionPage.tsx create mode 100644 web/src/pages/SettingsPage.tsx create mode 100644 web/src/pages/SharedPage.tsx create mode 100644 web/src/styles.css create mode 100644 web/src/ui/Markdown.tsx create mode 100644 web/src/ui/index.tsx diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3afb422 --- /dev/null +++ b/.env.example @@ -0,0 +1,36 @@ +# Study Desk configuration. Every value is optional. +# In Docker, set these as container environment variables instead of using this file. + +# Where the database, uploads and backups live. Default: /data in the container, ./data otherwise. +# DATA_DIR=/data + +# Port and bind address. +# PORT=3726 +# HOST=0.0.0.0 + +# First-run administrator password. If unset, the first visit shows a setup screen that asks +# for the one-time code printed in the log (also written to DATA_DIR/setup-code.txt). +# ADMIN_PASSWORD= + +# Forgot the password? Set this, restart once, sign in, then remove it again. +# RESET_ADMIN_PASSWORD= + +# Secret used to encrypt AI provider API keys at rest. If unset, a random key is generated and +# stored in DATA_DIR/secret.key. Set it explicitly if you want the key kept outside the data folder. +# APP_SECRET= + +# Cookie "Secure" flag: auto (default: on whenever the request arrived over HTTPS), true or false. +# COOKIE_SECURE=auto + +# Trust X-Forwarded-* headers from a reverse proxy (default true). Set false if the container +# is exposed directly to the internet without a proxy. +# TRUST_PROXY=true + +# Largest upload accepted, in megabytes. +# MAX_UPLOAD_MB=100 + +# Number of automatic daily database snapshots to keep. +# BACKUP_KEEP=7 + +# Timezone used for "today", streaks and due dates until you change it in Settings. +# TZ=America/Phoenix diff --git a/.gitignore b/.gitignore index 521e923..7a7fd29 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ coverage/ .DS_Store npm-debug.log* .test-data/ +.claude/ diff --git a/scripts/build-server.mjs b/scripts/build-server.mjs new file mode 100644 index 0000000..2f41883 --- /dev/null +++ b/scripts/build-server.mjs @@ -0,0 +1,14 @@ +// Bundles the server into one file. Dependencies stay external and are installed in the image. +import { build } from 'esbuild'; + +await build({ + entryPoints: ['server/main.ts'], + outfile: 'dist/server/main.js', + bundle: true, + platform: 'node', + format: 'esm', + target: 'node24', + packages: 'external', + sourcemap: true, + logLevel: 'info', +}); diff --git a/scripts/make-icons.mjs b/scripts/make-icons.mjs new file mode 100644 index 0000000..c0f4145 --- /dev/null +++ b/scripts/make-icons.mjs @@ -0,0 +1,60 @@ +// Renders the PNG app icons (no image library needed): a dark tile with two "cards". +import fs from 'node:fs'; +import zlib from 'node:zlib'; + +function png(size, draw) { + const px = Buffer.alloc(size * size * 4); + draw(px, size); + const raw = Buffer.alloc((size * 4 + 1) * size); + for (let y = 0; y < size; y++) px.copy(raw, y * (size * 4 + 1) + 1, y * size * 4, (y + 1) * size * 4); + const chunk = (type, data) => { + const len = Buffer.alloc(4); + len.writeUInt32BE(data.length); + const body = Buffer.concat([Buffer.from(type), data]); + const crc = Buffer.alloc(4); + crc.writeUInt32BE(zlib.crc32(body) >>> 0); + return Buffer.concat([len, body, crc]); + }; + const ihdr = Buffer.alloc(13); + ihdr.writeUInt32BE(size, 0); + ihdr.writeUInt32BE(size, 4); + ihdr[8] = 8; + ihdr[9] = 6; + return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk('IHDR', ihdr), chunk('IDAT', zlib.deflateSync(raw, { level: 9 })), chunk('IEND', Buffer.alloc(0))]); +} + +const hex = (h) => [parseInt(h.slice(1, 3), 16), parseInt(h.slice(3, 5), 16), parseInt(h.slice(5, 7), 16)]; + +function icon(px, size) { + const s = size / 64; + const set = (x, y, [r, g, b], a = 1) => { + if (x < 0 || y < 0 || x >= size || y >= size) return; + const i = (y * size + x) * 4; + px[i] = px[i] * (1 - a) + r * a; + px[i + 1] = px[i + 1] * (1 - a) + g * a; + px[i + 2] = px[i + 2] * (1 - a) + b * a; + px[i + 3] = 255; + }; + const rrect = (x0, y0, w, h, r, color, rot = 0, cx = 0, cy = 0, alpha = 1) => { + const cos = Math.cos(-rot), sin = Math.sin(-rot); + for (let y = 0; y < size; y++) + for (let x = 0; x < size; x++) { + // rotate the sample point back into the rectangle's frame + const dx = x + 0.5 - cx * s, dy = y + 0.5 - cy * s; + const lx = (dx * cos - dy * sin) / s + cx, ly = (dx * sin + dy * cos) / s + cy; + const qx = Math.max(x0 + r - lx, 0, lx - (x0 + w - r)), qy = Math.max(y0 + r - ly, 0, ly - (y0 + h - r)); + const d = Math.hypot(qx, qy) - r; + const a = Math.max(0, Math.min(1, 0.5 - d * s)); + if (a > 0 && lx >= x0 - 1 && lx <= x0 + w + 1 && ly >= y0 - 1 && ly <= y0 + h + 1) set(x, y, color, a * alpha); + } + }; + rrect(0, 0, 64, 64, 0, hex('#1B1A17')); // full-bleed so maskable crops look right + rrect(14, 17, 30, 36, 4, hex('#FBFAF7'), (-7 * Math.PI) / 180, 29, 35); + rrect(21, 13, 30, 36, 4, hex('#FFE36E')); + rrect(27, 23, 18, 3.4, 1.7, hex('#1B1A17')); + rrect(27, 30.5, 13, 3.4, 1.7, hex('#1B1A17'), 0, 0, 0, 0.55); + rrect(27, 38, 15.5, 3.4, 1.7, hex('#1B1A17'), 0, 0, 0, 0.55); +} + +for (const size of [180, 192, 512]) fs.writeFileSync(`web/public/icon-${size}.png`, png(size, icon)); +console.log('icons written'); diff --git a/server/main.ts b/server/main.ts index 6cee523..6417f64 100644 --- a/server/main.ts +++ b/server/main.ts @@ -17,6 +17,12 @@ function log(level: 'info' | 'warn' | 'error', message: string, extra?: unknown) } async function main(): Promise { + // Optional .env file for running outside Docker. Real environment variables always win. + try { + process.loadEnvFile('.env'); + } catch { + /* no .env file: that is the normal case in a container */ + } const config = loadConfig(); log('info', `Study Desk ${APP_VERSION} starting (data: ${config.dataDir})`); diff --git a/server/routes/documents.ts b/server/routes/documents.ts index c3caaf0..c4492c2 100644 --- a/server/routes/documents.ts +++ b/server/routes/documents.ts @@ -71,12 +71,19 @@ export function documentRoutes(app: AppContext): Hono { r.get('/documents/:id/chunks', (c) => { const doc = getDocument(db, idParam(c)); - const offset = Math.max(0, Number(c.req.query('offset') ?? 0) || 0); + let offset = Math.max(0, Number(c.req.query('offset') ?? 0) || 0); const limit = Math.min(100, Math.max(1, Number(c.req.query('limit') ?? 40) || 40)); + // Deep link to one passage (from search or a citation): start just before it. + const around = Number(c.req.query('around')); + if (Number.isFinite(around) && around > 0) { + const hit = db.get<{ seq: number }>('SELECT seq FROM chunks WHERE id = ? AND document_id = ?', around, doc.id); + if (hit) offset = Math.max(0, hit.seq - 1); + } const chunks = listChunks(db, doc.id, offset, limit); return c.json({ chunks: chunks.map((ch) => ({ id: ch.id, seq: ch.seq, text: ch.text, heading: ch.heading, pageStart: ch.pageStart, pageEnd: ch.pageEnd, label: sourceLabel(ch) })), total: doc.chunk_count, + offset, nextOffset: chunks.length === limit && offset + limit < doc.chunk_count ? offset + limit : null, }); }); diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..e5b63b5 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,31 @@ +import { fileURLToPath } from 'node:url'; +import tailwindcss from '@tailwindcss/vite'; +import react from '@vitejs/plugin-react'; +import { defineConfig } from 'vite'; + +const api = process.env.API_ORIGIN ?? 'http://localhost:3726'; + +export default defineConfig({ + root: 'web', + plugins: [react(), tailwindcss()], + resolve: { + alias: { + '@shared': fileURLToPath(new URL('./shared', import.meta.url)), + '@': fileURLToPath(new URL('./web/src', import.meta.url)), + }, + }, + server: { + port: 5173, + strictPort: false, + proxy: { + '/api': { target: api, changeOrigin: false }, + '/media': { target: api, changeOrigin: false }, + }, + }, + build: { + outDir: '../dist/web', + emptyOutDir: true, + sourcemap: false, + chunkSizeWarningLimit: 900, + }, +}); diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..0ea95e4 --- /dev/null +++ b/web/index.html @@ -0,0 +1,20 @@ + + + + + + + + + + + + + Study Desk + + + +
+ + + diff --git a/web/public/icon-180.png b/web/public/icon-180.png new file mode 100644 index 0000000000000000000000000000000000000000..92b493d40253a331cfdfe5198ed9128271ce864d GIT binary patch literal 2418 zcmb7`dpMK*AII-)A_@^X6e_2h5SAQj-AaT^O13FPEi;ywh{8(!L`lsl_0XNA>Ct#( z4kc7-4uzYdoKjJ~b9lz{ySje={{FbX_xt+1zlZC3UGM92eG(7h9OdOS+U9La{!RFcCxqgINv4eorz4rYrh;@z@7})(*Dt2(@yz8hr9Wv zj(RT-Wy2kv_W5S|oP+4w&}B3Bje~(7y*w~eR|tnMA9h*8Sh-&)CUh&`w@#r&-^}`u zvv2%jO`o{uMcnyCly%Y1iy_!)Y)ed@Lvo+&ZIi0kI+p-fDe`7;E#mHPu@e4oWhHD+ zH(0Wk1rqaHC_%DI780WbB?7L$g%lad;ab# z2M~Sb)ZH4@GI!EVf-*M#5XZX)4<6ok&$KXTXv@Dw&7qMQVFIUW#Np+evpml#nb8E zYESCz*g;%p>a)c*V!(+=Oq`qOM@7y3WcrGRu1al0c8#4I?QuWd;+(3RP_yXz#8eqV zh~VSL{~!%9Obf24!*tKwmvltf5HIS(cFEfcMqBFpJnHGvoZ2uNExiD5g4Beg={}`l z&s>-Mh?Y85Wz(`U)z#I4=^ZlRosa!Nl$Rom!?{wEG+=sJke1Dh6=ZM()%E#{GzKa~ zh=zy#tzrEcB}U0MdrMP!&uZ@=>341cJOs5x8(R@13mZl{)PDsO1KTPdH^e}btcE5U1YUE z11~zxZE^*N?Sfk%1j3QH)t`_h?z}tY2?WE`hUY*feD(!=5H*YJj=LR zA~sJb3t+irdYxwd7=N{;vvSINYrSX9YxcL`7~9-z+w#zi_>v8?bRU0Sz$!qVoUrrU zu!;nf4jdXvyk+ z3Nhf$z;QH$V1MFIek$}qF7b=`A^t7_9Rmi$r7q`hw#01^SR#x&@C#VtIdN-K{PK=S zQP+y40;h92ZYlQPJDP%=<1K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%6oyudj8ikT4f$tmenfWmcO9J5g~jE9lElD-sO3!u0CyBM z2I`!qS5Z3uauSNB_R09%bIV2YU4*E@rckAw8v_?lsVR88x%PV%W8+kuy~Iz ze>WALl}&?!adj7obqO_`9z&2Zs0rq975ONZ1C4G=G-HW3CKGfd`MGT(CBUaEO!Jcu@O zo3+}wT==5e|AK&6tTEU+a&g=#{thByhK7mKQjTuJtNA21yJRxzwA6{*kkRE%cDk={ zk8M<|bD((bgjZvY@m_%n%li95w&Z%)poI>_hw+C|jaC6qq0+RPPduQ~I&Fg;$h@vT z4wbk>>vg*@1NqgLt=~K(SBnjq}t)KYKH=;*Z&KK{Mn3h4p0v$HdrJ(Y@YFNrs)9of3-!p|w&Xacl6 zT)kk99c9_{Wh>7&1sI*_kAmrZ;=%ycbV_6t*7IC<)fTWOfs2BCNzIMBfA52ADZe0-ItUY!wZ zjEygeM8?i8E|*eLoD9+Dk$-m!ISgINfu<^0`U+d@<2ndE8%pB@FNO^vv_zJ5gDP=t=`9J-xkoUmBD@lpHqMzU$5Y zeg{dC(uE`5KtJ%Q@#42Q*1gIp*Z!W!+MMW<6M~nT)Ki(pOD|U-|Melk06F1*{Httl ao5vNZ?YP28Cmuqp2Amz-?0H-1iT?p)HYVu+ literal 0 HcmV?d00001 diff --git a/web/public/icon-512.png b/web/public/icon-512.png new file mode 100644 index 0000000000000000000000000000000000000000..56ce4d84a87a60e6afe4d7e7e7afc2c93534d0c2 GIT binary patch literal 7224 zcmb6;c{tQ-)b9++z9eJ`rEo)(kS!BRr6jk-lC2m;mIxzcDoZ6xajj*E_K=WdnX=TB zWx6G@jxDmz3>n)P-}^J8?)N?o7dZhR1PedCtD4o+-|unfS4(rIPb4(}pz z)uH_S`XHJ2LvuA#ay#StLkNzoL3cCz8Rgy~{S*!mpG2722=Gu0P5|WL0|fv#02ufN zMHB}A*V6wJ{Wp{UMEy7VZ<+oL_J7L>cX0!C&i|Kgzd51bME^&7{NA%7F~0We6C16Q zf9G4Q(|qQP^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/dev/null +++ b/web/public/manifest.webmanifest @@ -0,0 +1,15 @@ +{ + "name": "Study Desk", + "short_name": "Study Desk", + "description": "Quizzes, spaced-repetition flashcards and study materials.", + "start_url": "/", + "scope": "/", + "display": "standalone", + "background_color": "#FBFAF7", + "theme_color": "#1B1A17", + "icons": [ + { "src": "/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any" }, + { "src": "/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any maskable" }, + { "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" } + ] +} diff --git a/web/public/robots.txt b/web/public/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/web/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/web/public/sw.js b/web/public/sw.js new file mode 100644 index 0000000..cdfaaa3 --- /dev/null +++ b/web/public/sw.js @@ -0,0 +1,50 @@ +/* Study Desk service worker: makes the app installable and keeps the shell available offline. + * API calls are never cached, so study data is always live. */ +const CACHE = 'studydesk-shell-v1'; + +self.addEventListener('install', (event) => { + event.waitUntil(caches.open(CACHE).then((c) => c.addAll(['/', '/icon.svg', '/manifest.webmanifest'])).then(() => self.skipWaiting())); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil( + caches + .keys() + .then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))) + .then(() => self.clients.claim()), + ); +}); + +self.addEventListener('fetch', (event) => { + const req = event.request; + if (req.method !== 'GET') return; + const url = new URL(req.url); + if (url.origin !== self.location.origin || url.pathname.startsWith('/api/') || url.pathname.startsWith('/media/')) return; + + // Hashed build assets never change: serve from cache, fill on first use. + if (url.pathname.startsWith('/assets/')) { + event.respondWith( + caches.match(req).then( + (hit) => + hit || + fetch(req).then((res) => { + if (res.ok) caches.open(CACHE).then((c) => c.put(req, res.clone())); + return res.clone(); + }), + ), + ); + return; + } + + // Pages: always try the network so updates arrive, fall back to the cached shell offline. + if (req.mode === 'navigate') { + event.respondWith( + fetch(req) + .then((res) => { + if (res.ok) caches.open(CACHE).then((c) => c.put('/', res.clone())); + return res.clone(); + }) + .catch(() => caches.match('/').then((hit) => hit || new Response('Study Desk is offline.', { status: 503, headers: { 'Content-Type': 'text/plain' } }))), + ); + } +}); diff --git a/web/public/theme.js b/web/public/theme.js new file mode 100644 index 0000000..edbdabb --- /dev/null +++ b/web/public/theme.js @@ -0,0 +1,10 @@ +// Applies the saved theme before first paint (kept as a file so the CSP can stay script-src 'self'). +(function () { + try { + var saved = localStorage.getItem('sd.theme') || 'system'; + var dark = saved === 'dark' || (saved === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches); + document.documentElement.dataset.theme = dark ? 'dark' : 'light'; + } catch (e) { + document.documentElement.dataset.theme = 'light'; + } +})(); diff --git a/web/src/app/Shell.tsx b/web/src/app/Shell.tsx new file mode 100644 index 0000000..13aee3a --- /dev/null +++ b/web/src/app/Shell.tsx @@ -0,0 +1,615 @@ +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(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 ( + + + + + } + > +
{ + e.preventDefault(); + void save(); + }} + > +
+ + setName(e.target.value)} placeholder="Pharmacology" maxLength={120} /> + + + setCode(e.target.value)} placeholder="NUR 356" maxLength={40} /> + +
+ +