✨ note attachments and side-panel notebook flow
Browse files at this commit7992c8ffa0c7de59de9ed8e62767c6fa5532d6fbParent: 2c64b3a- feat
- ✨ note attachments and side-panel notebook flow
19 changed files +552 -142
- README.md +3 -12
- docs/frontend-next-steps.md +2 -12
- src/api/client.ts +31 -0
- src/api/deleteNoteFileById.ts +5 -0
- src/api/getNoteFileUrl.ts +3 -0
- src/api/getNoteFiles.ts +8 -0
- src/api/patchSettings.ts +1 -0
- src/api/postNoteFile.ts +8 -0
- src/api/types.ts +8 -0
- src/components/notes/note-card.tsx +54 -57
- src/components/notes/note-files-panel.tsx +141 -0
- src/components/notes/note-form.tsx +109 -3
- src/components/notes/note-list.tsx +37 -19
- src/components/notes/note-reader-dialog.tsx +0 -30
- src/components/notes/note-reader-panel.tsx +50 -0
- src/components/ui/dialog.tsx +16 -3
- src/i18n/messages.ts +30 -0
- src/pages/notes-page.tsx +10 -4
- src/pages/settings-page.tsx +36 -2
README.mdmodified+3 -12
| @@ -56,7 +56,7 @@ Dashboard and table summaries must use the same role scope as the related page. | |||
| 56 | | `/login`, `/register` | Guests | Authentication | | 56 | | `/login`, `/register` | Guests | Authentication | |
| 57 | | `/` | Authenticated | Role-scoped, observation-only dashboard | | 57 | | `/` | Authenticated | Role-scoped, observation-only dashboard | |
| 58 | | `/profile` | Authenticated | Edit personal info (name, email, phone, birth date) | | 58 | | `/profile` | Authenticated | Edit personal info (name, email, phone, birth date) | |
| 59 | -| `/notes` | Student+ | Personal notebook CRUD with paper-style read dialogs; file attachments are the next frontend integration | | 59 | +| `/notes` | Student+ | Personal notebook CRUD with paper-style read dialogs and file attachments | |
| 60 | | `/events`, `/events/:id` | Student+ | Event list & detail with search, time filters, and lazy attendance roster | | 60 | | `/events`, `/events/:id` | Student+ | Event list & detail with search, time filters, and lazy attendance roster | |
| 61 | | `/exams` | Student+ | Exam table with role-scoped course filtering | | 61 | | `/exams` | Student+ | Exam table with role-scoped course filtering | |
| 62 | | `/exams/:id` | Student+ | Exam detail, questions, grading, statistics (teacher+) | | 62 | | `/exams/:id` | Student+ | Exam detail, questions, grading, statistics (teacher+) | |
| @@ -79,7 +79,7 @@ Dashboard and table summaries must use the same role scope as the related page. | |||
| 79 | - **Course sessions**: right-panel session creation and paginated roll call panels | 79 | - **Course sessions**: right-panel session creation and paginated roll call panels |
| 80 | - **Schedule validation**: event, exam, and lesson-session forms use `GET /time` for server-clock-aware past-date warnings before submit | 80 | - **Schedule validation**: event, exam, and lesson-session forms use `GET /time` for server-clock-aware past-date warnings before submit |
| 81 | - **Notebook**: notes render as paper-style cards, open in a paper-style read dialog, and keep create/edit/delete in dialogs with three-dot card actions | 81 | - **Notebook**: notes render as paper-style cards, open in a paper-style read dialog, and keep create/edit/delete in dialogs with three-dot card actions |
| 82 | -- **Note files**: backend supports per-note file upload/list/download/delete; frontend integration will use native `FormData`, no upload dependency | 82 | +- **Note files**: per-note upload/list/download/delete through native `FormData`, with school-configured file-size warnings from settings |
| 83 | - **Events and courses**: events keep card rendering with toolbar search and upcoming/past filters; courses use table search plus term/unassigned filters | 83 | - **Events and courses**: events keep card rendering with toolbar search and upcoming/past filters; courses use table search plus term/unassigned filters |
| 84 | - **Attendance UI**: localized status labels with explanatory detail text and semantic colors | 84 | - **Attendance UI**: localized status labels with explanatory detail text and semantic colors |
| 85 | - **Role-scoped dashboard**: read-only summaries and KPIs by current role | 85 | - **Role-scoped dashboard**: read-only summaries and KPIs by current role |
| @@ -97,16 +97,7 @@ Dashboard and table summaries must use the same role scope as the related page. | |||
| 97 | - Disclosure sections either defer hidden content for request savings or preserve mounted content when local state should not reset. | 97 | - Disclosure sections either defer hidden content for request savings or preserve mounted content when local state should not reset. |
| 98 | - Event detail attendance roster is teacher-only and lazy-loaded when its disclosure opens. | 98 | - Event detail attendance roster is teacher-only and lazy-loaded when its disclosure opens. |
| 99 | 99 | ||
| 100 | -## Upcoming Note File Integration | 100 | +- Note attachments live in the note reader dialog. Upload uses native `FormData`; downloads are same-origin links to `/api/notes/{id}/files/{file_id}`. Backend remains authoritative for the 10-file cap and payload validation. |
| 101 | - | ||
| 102 | -The backend now supports note attachments: `POST /notes/{id}/files` with multipart field `file`, `GET /notes/{id}/files`, raw download by file id, and delete by file id. The frontend implementation should stay minimal: | ||
| 103 | - | ||
| 104 | -- Add `NoteFile` and `max_file_bytes` to API types/settings. | ||
| 105 | -- Add one API file per request: list, upload, delete, and a download URL helper. | ||
| 106 | -- Use native `FormData`; do not set `Content-Type` manually for multipart. | ||
| 107 | -- Mount a small attachments panel in the note reader dialog only after a note exists. | ||
| 108 | -- Read `settings.max_file_bytes` for a client-side size warning; backend remains authoritative for `413` and the 10-file cap. | ||
| 109 | -- Skip list-card attachment counts and file previews until there is a real product need. | ||
| 110 | 101 | ||
| 111 | ## Docs | 102 | ## Docs |
| 112 | 103 | ||
docs/frontend-next-steps.mdmodified+2 -12
| @@ -18,7 +18,7 @@ validation, and list filtering cleanup. | |||
| 18 | - Settings requests are cached and refreshed after settings patches. | 18 | - Settings requests are cached and refreshed after settings patches. |
| 19 | - Sidebar icons use local SVG wrappers to avoid large icon package module graphs. | 19 | - Sidebar icons use local SVG wrappers to avoid large icon package module graphs. |
| 20 | - Notes use a paper-style notebook card layout, a paper-style read dialog, and dialog-based create/edit/delete flows. | 20 | - Notes use a paper-style notebook card layout, a paper-style read dialog, and dialog-based create/edit/delete flows. |
| 21 | -- Backend note attachments are available but not yet wired in the frontend. Planned frontend scope is reader-dialog attachments only, using native `FormData` and backend-enforced caps. | 21 | +- Note attachments are wired in the reader dialog with native `FormData`, same-origin download links, and settings-based file-size warnings. Backend remains authoritative for the 10-file cap and upload validation. |
| 22 | - List endpoints return `{ items, total, limit, offset }`. API helpers under `src/api/` accept optional `limit`/`offset` via `Page<T>`. | 22 | - List endpoints return `{ items, total, limit, offset }`. API helpers under `src/api/` accept optional `limit`/`offset` via `Page<T>`. |
| 23 | - Events keep card rendering with shared toolbar search and all/upcoming/past filters. | 23 | - Events keep card rendering with shared toolbar search and all/upcoming/past filters. |
| 24 | - Event, exam, and lesson-session schedule forms use `GET /time` for server-clock-aware past-date warnings before submit. | 24 | - Event, exam, and lesson-session schedule forms use `GET /time` for server-clock-aware past-date warnings before submit. |
| @@ -54,17 +54,6 @@ validation, and list filtering cleanup. | |||
| 54 | 54 | ||
| 55 | ## Active Backlog | 55 | ## Active Backlog |
| 56 | 56 | ||
| 57 | -### Note File Attachments | ||
| 58 | - | ||
| 59 | -| Item | Plan | | ||
| 60 | -|---|---| | ||
| 61 | -| API types | Add `NoteFile` and `SchoolSettings.max_file_bytes` | | ||
| 62 | -| API helpers | Add list/upload/delete helpers plus a download URL helper; keep one file per request | | ||
| 63 | -| Upload transport | Use native `FormData` with the multipart field named `file`; do not route multipart through JSON `client()` | | ||
| 64 | -| UI | Add a compact `NoteFilesPanel` inside the note reader dialog; no card-level file counts | | ||
| 65 | -| Limits | Read `settings.max_file_bytes` for client warning; backend remains authoritative for 10-file cap and `413` | | ||
| 66 | -| Deferred | No previews, no drag-drop dependency, no draft-upload queue before note creation | | ||
| 67 | - | ||
| 68 | ### Recently fixed (this batch) | 57 | ### Recently fixed (this batch) |
| 69 | 58 | ||
| 70 | | Item | Fix | | 59 | | Item | Fix | |
| @@ -75,6 +64,7 @@ validation, and list filtering cleanup. | |||
| 75 | | Manager work log | `/management/staff-work` + get/patch/delete work APIs | | 64 | | Manager work log | `/management/staff-work` + get/patch/delete work APIs | |
| 76 | | Work route guard | `beforeLoad` teacher+ on `/work` | | 65 | | Work route guard | `beforeLoad` teacher+ on `/work` | |
| 77 | | BE student-only gates (enroll/sit/grade/roll call) | Localized error strings for the new 400/403 messages; student-marks lookup picker filters `role=student`; exam-detail own-result gates on `isStudent()` | | 66 | | BE student-only gates (enroll/sit/grade/roll call) | Localized error strings for the new 400/403 messages; student-marks lookup picker filters `role=student`; exam-detail own-result gates on `isStudent()` | |
| 67 | +| Note file attachments | Reader-dialog attachments panel with list/upload/download/delete; settings exposes `max_file_bytes` | | ||
| 78 | 68 | ||
| 79 | ### Incomplete Product Features | 69 | ### Incomplete Product Features |
| 80 | 70 | ||
src/api/client.tsmodified+31 -0
| @@ -171,6 +171,37 @@ export async function client<T>(path: string, options: RequestOptions = {}): Pro | |||
| 171 | return data as T; | 171 | return data as T; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | +export async function formClient<T>(path: string, body: FormData, signal?: AbortSignal): Promise<T> { | ||
| 175 | + const res = await fetch(`${API_PREFIX}${path}`, { | ||
| 176 | + method: "POST", | ||
| 177 | + body, | ||
| 178 | + credentials: "same-origin", | ||
| 179 | + signal, | ||
| 180 | + }); | ||
| 181 | + | ||
| 182 | + const text = await res.text(); | ||
| 183 | + let data: unknown = null; | ||
| 184 | + if (text) { | ||
| 185 | + try { | ||
| 186 | + data = JSON.parse(text); | ||
| 187 | + } catch { | ||
| 188 | + data = { error: text }; | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + if (!res.ok) { | ||
| 193 | + const message = | ||
| 194 | + data && typeof data === "object" && "error" in data && typeof (data as { error: unknown }).error === "string" | ||
| 195 | + ? (data as { error: string }).error | ||
| 196 | + : data && typeof data === "object" && "message" in data && typeof (data as { message: unknown }).message === "string" | ||
| 197 | + ? (data as { message: string }).message | ||
| 198 | + : res.statusText || "Request failed"; | ||
| 199 | + throw new ApiError(res.status, message); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + return data as T; | ||
| 203 | +} | ||
| 204 | + | ||
| 174 | export function formatApiErrorMessage(message: string, locale: Locale = currentLocale()): string { | 205 | export function formatApiErrorMessage(message: string, locale: Locale = currentLocale()): string { |
| 175 | const normalized = normalizeApiMessage(message); | 206 | const normalized = normalizeApiMessage(message); |
| 176 | const known = API_ERROR_MESSAGES[normalized]?.[locale]; | 207 | const known = API_ERROR_MESSAGES[normalized]?.[locale]; |
src/api/deleteNoteFileById.tsadded+5 -0
| @@ -0,0 +1,5 @@ | |||
| 1 | +import { client } from "./client"; | ||
| 2 | + | ||
| 3 | +export function deleteNoteFileById(noteId: string, fileId: string): Promise<void> { | ||
| 4 | + return client<void>(`/notes/${noteId}/files/${fileId}`, { method: "DELETE" }); | ||
| 5 | +} | ||
src/api/getNoteFileUrl.tsadded+3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | +export function getNoteFileUrl(noteId: string, fileId: string): string { | ||
| 2 | + return `/api/notes/${encodeURIComponent(noteId)}/files/${encodeURIComponent(fileId)}`; | ||
| 3 | +} | ||
src/api/getNoteFiles.tsadded+8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | +import { client } from "./client"; | ||
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "./page"; | ||
| 3 | +import type { NoteFile } from "./types"; | ||
| 4 | + | ||
| 5 | +export async function getNoteFiles(noteId: string, params?: PageParams, signal?: AbortSignal): Promise<Page<NoteFile>> { | ||
| 6 | + const data = await client<unknown>(`/notes/${noteId}/files${pageQuery(params)}`, { signal }); | ||
| 7 | + return normalizePage<NoteFile>(data); | ||
| 8 | +} | ||
src/api/patchSettings.tsmodified+1 -0
| @@ -6,6 +6,7 @@ export type PatchSettingsBody = { | |||
| 6 | exam_kinds?: ExamKindSetting[]; | 6 | exam_kinds?: ExamKindSetting[]; |
| 7 | attendance_statuses?: string[]; | 7 | attendance_statuses?: string[]; |
| 8 | grade_bands?: GradeBand[]; | 8 | grade_bands?: GradeBand[]; |
| 9 | + max_file_bytes?: number; | ||
| 9 | }; | 10 | }; |
| 10 | 11 | ||
| 11 | export function patchSettings(body: PatchSettingsBody): Promise<SchoolSettings> { | 12 | export function patchSettings(body: PatchSettingsBody): Promise<SchoolSettings> { |
src/api/postNoteFile.tsadded+8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | +import { formClient } from "./client"; | ||
| 2 | +import type { NoteFile } from "./types"; | ||
| 3 | + | ||
| 4 | +export function postNoteFile(noteId: string, file: File, signal?: AbortSignal): Promise<NoteFile> { | ||
| 5 | + const body = new FormData(); | ||
| 6 | + body.append("file", file); | ||
| 7 | + return formClient<NoteFile>(`/notes/${noteId}/files`, body, signal); | ||
| 8 | +} | ||
src/api/types.tsmodified+8 -0
| @@ -40,6 +40,13 @@ export type Note = { | |||
| 40 | content: string; | 40 | content: string; |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | +export type NoteFile = { | ||
| 44 | + id: string; | ||
| 45 | + name: string; | ||
| 46 | + content_type: string; | ||
| 47 | + size: number; | ||
| 48 | +}; | ||
| 49 | + | ||
| 43 | export type Event = { | 50 | export type Event = { |
| 44 | id: string; | 51 | id: string; |
| 45 | creator: string; | 52 | creator: string; |
| @@ -297,6 +304,7 @@ export type SchoolSettings = { | |||
| 297 | exam_kinds: ExamKindSetting[]; | 304 | exam_kinds: ExamKindSetting[]; |
| 298 | attendance_statuses: string[]; | 305 | attendance_statuses: string[]; |
| 299 | grade_bands: GradeBand[]; | 306 | grade_bands: GradeBand[]; |
| 307 | + max_file_bytes: number; | ||
| 300 | }; | 308 | }; |
| 301 | 309 | ||
| 302 | export const EXAM_KINDS: KnownExamKind[] = [ | 310 | export const EXAM_KINDS: KnownExamKind[] = [ |
src/components/notes/note-card.tsxmodified+54 -57
| @@ -2,80 +2,77 @@ import { createSignal } from "solid-js"; | |||
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | import type { Note } from "@/api/types"; | 3 | import type { Note } from "@/api/types"; |
| 4 | import { NoteForm } from "@/components/notes/note-form"; | 4 | import { NoteForm } from "@/components/notes/note-form"; |
| 5 | -import { NoteReaderDialog } from "@/components/notes/note-reader-dialog"; | ||
| 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 5 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 7 | -import { FormDialog } from "@/components/ui/form-dialog"; | ||
| 8 | import { IconEdit, IconTrash } from "@/components/ui/icons"; | 6 | import { IconEdit, IconTrash } from "@/components/ui/icons"; |
| 7 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 9 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 8 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 10 | import { useT } from "@/stores/preferences-context"; | 9 | import { useT } from "@/stores/preferences-context"; |
| 11 | 10 | ||
| 12 | export function NoteCard(props: { | 11 | export function NoteCard(props: { |
| 13 | note: Note; | 12 | note: Note; |
| 13 | + onOpen: (note: Note) => void; | ||
| 14 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; | 14 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; |
| 15 | onDelete: (id: string) => Promise<void>; | 15 | onDelete: (id: string) => Promise<void>; |
| 16 | }) { | 16 | }) { |
| 17 | const t = useT(); | 17 | const t = useT(); |
| 18 | - const [reading, setReading] = createSignal(false); | ||
| 19 | const [editing, setEditing] = createSignal(false); | 18 | const [editing, setEditing] = createSignal(false); |
| 20 | const [error, setError] = createSignal(""); | 19 | const [error, setError] = createSignal(""); |
| 21 | const [deleteOpen, setDeleteOpen] = createSignal(false); | 20 | const [deleteOpen, setDeleteOpen] = createSignal(false); |
| 22 | 21 | ||
| 23 | return ( | 22 | return ( |
| 24 | - <article | 23 | + <> |
| 25 | - role="button" | 24 | + <article |
| 26 | - tabindex="0" | 25 | + role="button" |
| 27 | - class="group flex h-full min-h-72 cursor-pointer flex-col overflow-hidden rounded-2xl border border-amber-200/70 bg-card shadow-sm transition-all hover:-translate-y-0.5 hover:border-amber-400/60 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:border-amber-500/20" | 26 | + tabindex="0" |
| 28 | - onClick={() => setReading(true)} | 27 | + class="group flex h-full min-h-72 cursor-pointer flex-col overflow-hidden rounded-2xl border border-amber-200/70 bg-card shadow-sm transition-all hover:-translate-y-0.5 hover:border-amber-400/60 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:border-amber-500/20" |
| 29 | - onKeyDown={(event) => { | 28 | + onClick={() => props.onOpen(props.note)} |
| 30 | - if (event.key === "Enter" || event.key === " ") setReading(true); | 29 | + onKeyDown={(event) => { |
| 31 | - }} | 30 | + if (event.key === "Enter" || event.key === " ") { |
| 32 | - > | 31 | + event.preventDefault(); |
| 33 | - <div class="flex items-start justify-between gap-3 border-b border-amber-200/70 bg-amber-50/60 px-4 py-3 dark:border-amber-500/20 dark:bg-amber-500/10"> | 32 | + props.onOpen(props.note); |
| 34 | - <h3 class="line-clamp-2 min-w-0 font-display text-base font-semibold leading-snug">{props.note.title}</h3> | 33 | + } |
| 35 | - <div class="shrink-0" onClick={(event) => event.stopPropagation()}> | 34 | + }} |
| 36 | - <TableRowActions | 35 | + > |
| 37 | - label={t("common.actions")} | 36 | + <div class="flex items-start justify-between gap-3 border-b border-amber-200/70 bg-amber-50/60 px-4 py-3 dark:border-amber-500/20 dark:bg-amber-500/10"> |
| 38 | - actions={[ | 37 | + <h3 class="line-clamp-2 min-w-0 font-display text-base font-semibold leading-snug">{props.note.title}</h3> |
| 39 | - { | 38 | + <div class="shrink-0" onClick={(event) => event.stopPropagation()}> |
| 40 | - label: t("common.edit"), | 39 | + <TableRowActions |
| 41 | - icon: <IconEdit class="h-4 w-4" />, | 40 | + label={t("common.actions")} |
| 42 | - onSelect: () => setEditing(true), | 41 | + actions={[ |
| 43 | - }, | 42 | + { |
| 44 | - { | 43 | + label: t("common.edit"), |
| 45 | - label: t("common.delete"), | 44 | + icon: <IconEdit class="h-4 w-4" />, |
| 46 | - icon: <IconTrash class="h-4 w-4" />, | 45 | + onSelect: () => setEditing(true), |
| 47 | - destructive: true, | 46 | + }, |
| 48 | - onSelect: () => setDeleteOpen(true), | 47 | + { |
| 49 | - }, | 48 | + label: t("common.delete"), |
| 50 | - ]} | 49 | + icon: <IconTrash class="h-4 w-4" />, |
| 51 | - /> | 50 | + destructive: true, |
| 51 | + onSelect: () => setDeleteOpen(true), | ||
| 52 | + }, | ||
| 53 | + ]} | ||
| 54 | + /> | ||
| 55 | + </div> | ||
| 52 | </div> | 56 | </div> |
| 53 | - </div> | 57 | + <div class="flex flex-1 flex-col gap-4 bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(120,113,108,0.14)_2.1rem)] px-4 py-4 pl-12 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.1)_0,rgba(245,158,11,0.1)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(214,211,209,0.1)_2.1rem)]"> |
| 54 | - <div class="flex flex-1 flex-col gap-4 bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(120,113,108,0.14)_2.1rem)] px-4 py-4 pl-12 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.1)_0,rgba(245,158,11,0.1)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(214,211,209,0.1)_2.1rem)]"> | 58 | + <p class="line-clamp-6 whitespace-pre-wrap text-[13px] leading-8 text-muted-foreground group-hover:text-foreground"> |
| 55 | - <p class="line-clamp-6 whitespace-pre-wrap text-[13px] leading-8 text-muted-foreground group-hover:text-foreground"> | 59 | + {props.note.content || t("notes.noContent")} |
| 56 | - {props.note.content || t("notes.noContent")} | 60 | + </p> |
| 57 | - </p> | 61 | + {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 58 | - {error() && <p class="text-sm text-destructive">{error()}</p>} | 62 | + </div> |
| 59 | - </div> | 63 | + </article> |
| 60 | - | ||
| 61 | - <NoteReaderDialog note={props.note} open={reading()} onOpenChange={setReading} /> | ||
| 62 | 64 | ||
| 63 | - <FormDialog | 65 | + <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={props.note.title}> |
| 64 | - open={editing()} | 66 | + <NoteForm |
| 65 | - onOpenChange={setEditing} | 67 | + initial={props.note} |
| 66 | - title={t("common.edit")} | 68 | + submitLabel={t("common.update")} |
| 67 | - description={props.note.title} | 69 | + onCancel={() => setEditing(false)} |
| 68 | - > | 70 | + onSubmit={async (values) => { |
| 69 | - <NoteForm | 71 | + await props.onUpdate(props.note.id, values); |
| 70 | - initial={props.note} | 72 | + setEditing(false); |
| 71 | - submitLabel={t("common.update")} | 73 | + }} |
| 72 | - onCancel={() => setEditing(false)} | 74 | + /> |
| 73 | - onSubmit={async (values) => { | 75 | + </SidePanel> |
| 74 | - await props.onUpdate(props.note.id, values); | ||
| 75 | - setEditing(false); | ||
| 76 | - }} | ||
| 77 | - /> | ||
| 78 | - </FormDialog> | ||
| 79 | 76 | ||
| 80 | <ConfirmDialog | 77 | <ConfirmDialog |
| 81 | open={deleteOpen()} | 78 | open={deleteOpen()} |
| @@ -93,6 +90,6 @@ export function NoteCard(props: { | |||
| 93 | } | 90 | } |
| 94 | }} | 91 | }} |
| 95 | /> | 92 | /> |
| 96 | - </article> | 93 | + </> |
| 97 | ); | 94 | ); |
| 98 | } | 95 | } |
src/components/notes/note-files-panel.tsxadded+141 -0
| @@ -0,0 +1,141 @@ | |||
| 1 | +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | ||
| 2 | +import { deleteNoteFileById } from "@/api/deleteNoteFileById"; | ||
| 3 | +import { getNoteFileUrl } from "@/api/getNoteFileUrl"; | ||
| 4 | +import { getNoteFiles } from "@/api/getNoteFiles"; | ||
| 5 | +import { getSettings } from "@/api/getSettings"; | ||
| 6 | +import { postNoteFile } from "@/api/postNoteFile"; | ||
| 7 | +import { ApiError, formatApiError } from "@/api/client"; | ||
| 8 | +import type { NoteFile } from "@/api/types"; | ||
| 9 | +import { Button } from "@/components/ui/button"; | ||
| 10 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 11 | +import { IconPlus, IconTrash } from "@/components/ui/icons"; | ||
| 12 | +import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 13 | +import { useT } from "@/stores/preferences-context"; | ||
| 14 | + | ||
| 15 | +const MAX_NOTE_FILES = 10; | ||
| 16 | + | ||
| 17 | +function formatBytes(bytes: number): string { | ||
| 18 | + if (bytes < 1024) return `${bytes} B`; | ||
| 19 | + if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`; | ||
| 20 | + return `${(bytes / 1024 / 1024).toFixed(1)} MB`; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +export function NoteFilesPanel(props: { noteId: string; active: boolean }) { | ||
| 24 | + let input: HTMLInputElement | undefined; | ||
| 25 | + const t = useT(); | ||
| 26 | + const [error, setError] = createSignal(""); | ||
| 27 | + const [pending, setPending] = createSignal(false); | ||
| 28 | + const [deleteTarget, setDeleteTarget] = createSignal<NoteFile | null>(null); | ||
| 29 | + const [files, { refetch }] = createResource( | ||
| 30 | + () => (props.active ? props.noteId : null), | ||
| 31 | + async (noteId) => { | ||
| 32 | + if (!noteId) return [] as NoteFile[]; | ||
| 33 | + // ponytail: empty on 404 so missing BE file API doesn't kill the reader dialog | ||
| 34 | + try { | ||
| 35 | + return (await getNoteFiles(noteId, { limit: MAX_NOTE_FILES })).items; | ||
| 36 | + } catch (err) { | ||
| 37 | + if (err instanceof ApiError && (err.status === 404 || err.status === 501)) return []; | ||
| 38 | + throw err; | ||
| 39 | + } | ||
| 40 | + }, | ||
| 41 | + ); | ||
| 42 | + const [settings] = createResource(async () => { | ||
| 43 | + try { | ||
| 44 | + return await getSettings(); | ||
| 45 | + } catch { | ||
| 46 | + return null; | ||
| 47 | + } | ||
| 48 | + }); | ||
| 49 | + const maxFileBytes = () => settings()?.max_file_bytes ?? 5 * 1024 * 1024; | ||
| 50 | + const atLimit = () => (files() ?? []).length >= MAX_NOTE_FILES; | ||
| 51 | + | ||
| 52 | + const upload = async (file: File | undefined) => { | ||
| 53 | + if (!file) return; | ||
| 54 | + setError(""); | ||
| 55 | + if (file.size > maxFileBytes()) { | ||
| 56 | + setError(t("notes.fileTooLarge", { size: formatBytes(maxFileBytes()) })); | ||
| 57 | + return; | ||
| 58 | + } | ||
| 59 | + setPending(true); | ||
| 60 | + try { | ||
| 61 | + await postNoteFile(props.noteId, file); | ||
| 62 | + await refetch(); | ||
| 63 | + if (input) input.value = ""; | ||
| 64 | + } catch (err) { | ||
| 65 | + setError(formatApiError(err)); | ||
| 66 | + } finally { | ||
| 67 | + setPending(false); | ||
| 68 | + } | ||
| 69 | + }; | ||
| 70 | + | ||
| 71 | + return ( | ||
| 72 | + <section class="space-y-3 rounded-2xl border border-border/70 bg-card/80 p-4 shadow-sm"> | ||
| 73 | + <div class="flex flex-wrap items-center justify-between gap-3"> | ||
| 74 | + <div> | ||
| 75 | + <h3 class="font-display text-sm font-semibold">{t("notes.files")}</h3> | ||
| 76 | + <p class="mt-1 text-xs text-muted-foreground">{t("notes.filesHelp", { size: formatBytes(maxFileBytes()) })}</p> | ||
| 77 | + </div> | ||
| 78 | + <input | ||
| 79 | + ref={(el) => { | ||
| 80 | + input = el; | ||
| 81 | + }} | ||
| 82 | + type="file" | ||
| 83 | + class="hidden" | ||
| 84 | + disabled={pending() || atLimit()} | ||
| 85 | + onChange={(event) => void upload(event.currentTarget.files?.[0])} | ||
| 86 | + /> | ||
| 87 | + <Button type="button" size="sm" class="rounded-md" disabled={pending() || atLimit()} onClick={() => input?.click()}> | ||
| 88 | + <IconPlus class="h-4 w-4" /> | ||
| 89 | + {t("notes.addFile")} | ||
| 90 | + </Button> | ||
| 91 | + </div> | ||
| 92 | + | ||
| 93 | + {error() && <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} | ||
| 94 | + <Show when={atLimit()}> | ||
| 95 | + <p class="text-xs text-muted-foreground">{t("notes.fileLimit")}</p> | ||
| 96 | + </Show> | ||
| 97 | + | ||
| 98 | + <Show when={files.error}> | ||
| 99 | + <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{formatApiError(files.error)}</p> | ||
| 100 | + </Show> | ||
| 101 | + | ||
| 102 | + <Suspense fallback={<PageSpinner />}> | ||
| 103 | + <Show | ||
| 104 | + when={(files() ?? []).length > 0} | ||
| 105 | + fallback={<p class="rounded-md border border-dashed border-border/80 bg-muted/20 px-3 py-6 text-center text-sm text-muted-foreground">{t("notes.noFiles")}</p>} | ||
| 106 | + > | ||
| 107 | + <ul class="divide-y divide-border/70 rounded-md border border-border/70 bg-background/70"> | ||
| 108 | + <For each={files() ?? []}> | ||
| 109 | + {(file) => ( | ||
| 110 | + <li class="flex items-center justify-between gap-3 px-3 py-2 text-sm"> | ||
| 111 | + <a class="min-w-0 flex-1 truncate font-medium hover:text-primary" href={getNoteFileUrl(props.noteId, file.id)} download={file.name}> | ||
| 112 | + {file.name} | ||
| 113 | + </a> | ||
| 114 | + <span class="shrink-0 text-xs text-muted-foreground">{formatBytes(file.size)}</span> | ||
| 115 | + <Button type="button" variant="ghost" size="icon" class="h-8 w-8 rounded-md text-destructive hover:text-destructive" onClick={() => setDeleteTarget(file)}> | ||
| 116 | + <IconTrash class="h-4 w-4" /> | ||
| 117 | + </Button> | ||
| 118 | + </li> | ||
| 119 | + )} | ||
| 120 | + </For> | ||
| 121 | + </ul> | ||
| 122 | + </Show> | ||
| 123 | + </Suspense> | ||
| 124 | + | ||
| 125 | + <ConfirmDialog | ||
| 126 | + open={deleteTarget() != null} | ||
| 127 | + onOpenChange={(open) => !open && setDeleteTarget(null)} | ||
| 128 | + title={t("confirm.deleteTitle")} | ||
| 129 | + variant="destructive" | ||
| 130 | + summary={t("confirm.deleteNoteFile", { title: deleteTarget()?.name ?? "" })} | ||
| 131 | + onConfirm={async () => { | ||
| 132 | + const target = deleteTarget(); | ||
| 133 | + if (!target) return; | ||
| 134 | + await deleteNoteFileById(props.noteId, target.id); | ||
| 135 | + setDeleteTarget(null); | ||
| 136 | + await refetch(); | ||
| 137 | + }} | ||
| 138 | + /> | ||
| 139 | + </section> | ||
| 140 | + ); | ||
| 141 | +} | ||
src/components/notes/note-form.tsxmodified+109 -3
| @@ -1,8 +1,10 @@ | |||
| 1 | -import { createSignal } from "solid-js"; | 1 | +import { For, Show, createResource, createSignal } from "solid-js"; |
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | +import { getSettings } from "@/api/getSettings"; | ||
| 3 | import type { Note } from "@/api/types"; | 4 | import type { Note } from "@/api/types"; |
| 4 | import { Button } from "@/components/ui/button"; | 5 | import { Button } from "@/components/ui/button"; |
| 5 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 7 | +import { IconPlus, IconTrash } from "@/components/ui/icons"; | ||
| 6 | import { Input } from "@/components/ui/input"; | 8 | import { Input } from "@/components/ui/input"; |
| 7 | import { Label } from "@/components/ui/label"; | 9 | import { Label } from "@/components/ui/label"; |
| 8 | import { Textarea } from "@/components/ui/textarea"; | 10 | import { Textarea } from "@/components/ui/textarea"; |
| @@ -11,22 +13,44 @@ import { useT } from "@/stores/preferences-context"; | |||
| 11 | export type NoteFormValues = { | 13 | export type NoteFormValues = { |
| 12 | title: string; | 14 | title: string; |
| 13 | content: string; | 15 | content: string; |
| 16 | + files: File[]; | ||
| 14 | }; | 17 | }; |
| 15 | 18 | ||
| 19 | +const MAX_NOTE_FILES = 10; | ||
| 20 | + | ||
| 21 | +function formatBytes(bytes: number): string { | ||
| 22 | + if (bytes < 1024) return `${bytes} B`; | ||
| 23 | + if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`; | ||
| 24 | + return `${(bytes / 1024 / 1024).toFixed(1)} MB`; | ||
| 25 | +} | ||
| 26 | + | ||
| 16 | export function NoteForm(props: { | 27 | export function NoteForm(props: { |
| 17 | initial?: Partial<Note>; | 28 | initial?: Partial<Note>; |
| 18 | submitLabel?: string; | 29 | submitLabel?: string; |
| 30 | + /** Stage files on create (uploaded by parent after note exists). */ | ||
| 31 | + enableFiles?: boolean; | ||
| 19 | onSubmit: (values: NoteFormValues) => Promise<void>; | 32 | onSubmit: (values: NoteFormValues) => Promise<void>; |
| 20 | onCancel?: () => void; | 33 | onCancel?: () => void; |
| 21 | }) { | 34 | }) { |
| 22 | const t = useT(); | 35 | const t = useT(); |
| 36 | + let fileInput: HTMLInputElement | undefined; | ||
| 23 | const isUpdate = () => !!props.initial?.id; | 37 | const isUpdate = () => !!props.initial?.id; |
| 24 | const [title, setTitle] = createSignal(props.initial?.title ?? ""); | 38 | const [title, setTitle] = createSignal(props.initial?.title ?? ""); |
| 25 | const [content, setContent] = createSignal(props.initial?.content ?? ""); | 39 | const [content, setContent] = createSignal(props.initial?.content ?? ""); |
| 40 | + const [files, setFiles] = createSignal<File[]>([]); | ||
| 26 | const [error, setError] = createSignal(""); | 41 | const [error, setError] = createSignal(""); |
| 27 | const [pending, setPending] = createSignal(false); | 42 | const [pending, setPending] = createSignal(false); |
| 28 | const [confirmOpen, setConfirmOpen] = createSignal(false); | 43 | const [confirmOpen, setConfirmOpen] = createSignal(false); |
| 29 | const [pendingValues, setPendingValues] = createSignal<NoteFormValues | null>(null); | 44 | const [pendingValues, setPendingValues] = createSignal<NoteFormValues | null>(null); |
| 45 | + const [settings] = createResource(async () => { | ||
| 46 | + try { | ||
| 47 | + return await getSettings(); | ||
| 48 | + } catch { | ||
| 49 | + return null; | ||
| 50 | + } | ||
| 51 | + }); | ||
| 52 | + const maxFileBytes = () => settings()?.max_file_bytes ?? 5 * 1024 * 1024; | ||
| 53 | + const showFiles = () => !!props.enableFiles && !isUpdate(); | ||
| 30 | 54 | ||
| 31 | const validate = (): string | null => { | 55 | const validate = (): string | null => { |
| 32 | const value = title().trim(); | 56 | const value = title().trim(); |
| @@ -36,6 +60,21 @@ export function NoteForm(props: { | |||
| 36 | return null; | 60 | return null; |
| 37 | }; | 61 | }; |
| 38 | 62 | ||
| 63 | + const addFile = (file: File | undefined) => { | ||
| 64 | + if (!file) return; | ||
| 65 | + setError(""); | ||
| 66 | + if (file.size > maxFileBytes()) { | ||
| 67 | + setError(t("notes.fileTooLarge", { size: formatBytes(maxFileBytes()) })); | ||
| 68 | + return; | ||
| 69 | + } | ||
| 70 | + if (files().length >= MAX_NOTE_FILES) { | ||
| 71 | + setError(t("notes.fileLimit")); | ||
| 72 | + return; | ||
| 73 | + } | ||
| 74 | + setFiles((prev) => [...prev, file]); | ||
| 75 | + if (fileInput) fileInput.value = ""; | ||
| 76 | + }; | ||
| 77 | + | ||
| 39 | const save = async (values: NoteFormValues) => { | 78 | const save = async (values: NoteFormValues) => { |
| 40 | setError(""); | 79 | setError(""); |
| 41 | setPending(true); | 80 | setPending(true); |
| @@ -44,6 +83,7 @@ export function NoteForm(props: { | |||
| 44 | if (!isUpdate()) { | 83 | if (!isUpdate()) { |
| 45 | setTitle(""); | 84 | setTitle(""); |
| 46 | setContent(""); | 85 | setContent(""); |
| 86 | + setFiles([]); | ||
| 47 | } | 87 | } |
| 48 | } catch (err) { | 88 | } catch (err) { |
| 49 | setError(formatApiError(err)); | 89 | setError(formatApiError(err)); |
| @@ -59,7 +99,7 @@ export function NoteForm(props: { | |||
| 59 | setError(v); | 99 | setError(v); |
| 60 | return; | 100 | return; |
| 61 | } | 101 | } |
| 62 | - const values = { title: title().trim(), content: content() }; | 102 | + const values: NoteFormValues = { title: title().trim(), content: content(), files: files() }; |
| 63 | if (isUpdate()) { | 103 | if (isUpdate()) { |
| 64 | setPendingValues(values); | 104 | setPendingValues(values); |
| 65 | setConfirmOpen(true); | 105 | setConfirmOpen(true); |
| @@ -93,7 +133,73 @@ export function NoteForm(props: { | |||
| 93 | onInput={(e) => setContent(e.currentTarget.value)} | 133 | onInput={(e) => setContent(e.currentTarget.value)} |
| 94 | /> | 134 | /> |
| 95 | </div> | 135 | </div> |
| 96 | - {error() && <p class="rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} | 136 | + |
| 137 | + <Show when={showFiles()}> | ||
| 138 | + <section class="space-y-3 rounded-xl border border-border/80 bg-card p-4 shadow-sm"> | ||
| 139 | + <div class="flex flex-wrap items-center justify-between gap-3"> | ||
| 140 | + <div> | ||
| 141 | + <h3 class="text-sm font-semibold">{t("notes.files")}</h3> | ||
| 142 | + <p class="mt-1 text-xs text-muted-foreground"> | ||
| 143 | + {t("notes.filesHelp", { size: formatBytes(maxFileBytes()) })} | ||
| 144 | + </p> | ||
| 145 | + </div> | ||
| 146 | + <input | ||
| 147 | + ref={(el) => { | ||
| 148 | + fileInput = el; | ||
| 149 | + }} | ||
| 150 | + type="file" | ||
| 151 | + class="hidden" | ||
| 152 | + disabled={pending() || files().length >= MAX_NOTE_FILES} | ||
| 153 | + onChange={(event) => addFile(event.currentTarget.files?.[0])} | ||
| 154 | + /> | ||
| 155 | + <Button | ||
| 156 | + type="button" | ||
| 157 | + size="sm" | ||
| 158 | + variant="outline" | ||
| 159 | + class="rounded-md" | ||
| 160 | + disabled={pending() || files().length >= MAX_NOTE_FILES} | ||
| 161 | + onClick={() => fileInput?.click()} | ||
| 162 | + > | ||
| 163 | + <IconPlus class="h-4 w-4" /> | ||
| 164 | + {t("notes.addFile")} | ||
| 165 | + </Button> | ||
| 166 | + </div> | ||
| 167 | + <Show | ||
| 168 | + when={files().length > 0} | ||
| 169 | + fallback={ | ||
| 170 | + <p class="rounded-md border border-dashed border-border/80 bg-muted/20 px-3 py-4 text-center text-sm text-muted-foreground"> | ||
| 171 | + {t("notes.noFiles")} | ||
| 172 | + </p> | ||
| 173 | + } | ||
| 174 | + > | ||
| 175 | + <ul class="divide-y divide-border/70 rounded-md border border-border/70"> | ||
| 176 | + <For each={files()}> | ||
| 177 | + {(file, index) => ( | ||
| 178 | + <li class="flex items-center justify-between gap-3 px-3 py-2 text-sm"> | ||
| 179 | + <span class="min-w-0 flex-1 truncate font-medium">{file.name}</span> | ||
| 180 | + <span class="shrink-0 text-xs text-muted-foreground">{formatBytes(file.size)}</span> | ||
| 181 | + <Button | ||
| 182 | + type="button" | ||
| 183 | + variant="ghost" | ||
| 184 | + size="icon" | ||
| 185 | + class="h-8 w-8 rounded-md text-destructive hover:text-destructive" | ||
| 186 | + onClick={() => setFiles((prev) => prev.filter((_, i) => i !== index()))} | ||
| 187 | + > | ||
| 188 | + <IconTrash class="h-4 w-4" /> | ||
| 189 | + </Button> | ||
| 190 | + </li> | ||
| 191 | + )} | ||
| 192 | + </For> | ||
| 193 | + </ul> | ||
| 194 | + </Show> | ||
| 195 | + </section> | ||
| 196 | + </Show> | ||
| 197 | + | ||
| 198 | + {error() && ( | ||
| 199 | + <p class="rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-sm text-destructive"> | ||
| 200 | + {error()} | ||
| 201 | + </p> | ||
| 202 | + )} | ||
| 97 | <div class="flex flex-wrap items-center justify-end gap-2 border-t border-border/80 pt-4"> | 203 | <div class="flex flex-wrap items-center justify-end gap-2 border-t border-border/80 pt-4"> |
| 98 | {props.onCancel && ( | 204 | {props.onCancel && ( |
| 99 | <Button type="button" variant="outline" class="h-10 rounded-lg" onClick={props.onCancel}> | 205 | <Button type="button" variant="outline" class="h-10 rounded-lg" onClick={props.onCancel}> |
src/components/notes/note-list.tsxmodified+37 -19
| @@ -1,6 +1,7 @@ | |||
| 1 | -import { For, Show } from "solid-js"; | 1 | +import { For, Show, createSignal } from "solid-js"; |
| 2 | import type { Note } from "@/api/types"; | 2 | import type { Note } from "@/api/types"; |
| 3 | import { NoteCard } from "@/components/notes/note-card"; | 3 | import { NoteCard } from "@/components/notes/note-card"; |
| 4 | +import { NoteReaderPanel } from "@/components/notes/note-reader-panel"; | ||
| 4 | 5 | ||
| 5 | export function NoteList(props: { | 6 | export function NoteList(props: { |
| 6 | notes: Note[]; | 7 | notes: Note[]; |
| @@ -8,24 +9,41 @@ export function NoteList(props: { | |||
| 8 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; | 9 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; |
| 9 | onDelete: (id: string) => Promise<void>; | 10 | onDelete: (id: string) => Promise<void>; |
| 10 | }) { | 11 | }) { |
| 12 | + const [readingNote, setReadingNote] = createSignal<Note | null>(null); | ||
| 13 | + | ||
| 11 | return ( | 14 | return ( |
| 12 | - <Show | 15 | + <> |
| 13 | - when={props.notes.length > 0} | 16 | + <Show |
| 14 | - fallback={ | 17 | + when={props.notes.length > 0} |
| 15 | - <div class="flex min-h-[12rem] items-center justify-center rounded-lg border border-dashed border-border/80 bg-muted/20 px-6 text-center text-sm text-muted-foreground"> | 18 | + fallback={ |
| 16 | - {props.emptyLabel ?? ""} | 19 | + <div class="flex min-h-[12rem] items-center justify-center rounded-lg border border-dashed border-border/80 bg-muted/20 px-6 text-center text-sm text-muted-foreground"> |
| 17 | - </div> | 20 | + {props.emptyLabel ?? ""} |
| 18 | - } | 21 | + </div> |
| 19 | - > | 22 | + } |
| 20 | - <ul class="grid grid-cols-2 gap-3 xl:grid-cols-3"> | 23 | + > |
| 21 | - <For each={props.notes}> | 24 | + <ul class="grid grid-cols-2 gap-3 xl:grid-cols-3"> |
| 22 | - {(note) => ( | 25 | + <For each={props.notes}> |
| 23 | - <li class="animate-fade-up"> | 26 | + {(note) => ( |
| 24 | - <NoteCard note={note} onUpdate={props.onUpdate} onDelete={props.onDelete} /> | 27 | + <li class="animate-fade-up"> |
| 25 | - </li> | 28 | + <NoteCard |
| 26 | - )} | 29 | + note={note} |
| 27 | - </For> | 30 | + onOpen={setReadingNote} |
| 28 | - </ul> | 31 | + onUpdate={props.onUpdate} |
| 29 | - </Show> | 32 | + onDelete={props.onDelete} |
| 33 | + /> | ||
| 34 | + </li> | ||
| 35 | + )} | ||
| 36 | + </For> | ||
| 37 | + </ul> | ||
| 38 | + </Show> | ||
| 39 | + | ||
| 40 | + <NoteReaderPanel | ||
| 41 | + note={readingNote()} | ||
| 42 | + open={readingNote() != null} | ||
| 43 | + onOpenChange={(open) => { | ||
| 44 | + if (!open) setReadingNote(null); | ||
| 45 | + }} | ||
| 46 | + /> | ||
| 47 | + </> | ||
| 30 | ); | 48 | ); |
| 31 | } | 49 | } |
src/components/notes/note-reader-dialog.tsxdeleted+0 -30
| @@ -1,30 +0,0 @@ | |||
| 1 | -import { For, Show, createMemo } from "solid-js"; | ||
| 2 | -import type { Note } from "@/api/types"; | ||
| 3 | -import { FormDialog } from "@/components/ui/form-dialog"; | ||
| 4 | -import { useT } from "@/stores/preferences-context"; | ||
| 5 | - | ||
| 6 | -export function NoteReaderDialog(props: { | ||
| 7 | - note: Note; | ||
| 8 | - open: boolean; | ||
| 9 | - onOpenChange: (open: boolean) => void; | ||
| 10 | -}) { | ||
| 11 | - const t = useT(); | ||
| 12 | - const paragraphs = createMemo(() => props.note.content.split(/\n{2,}/).map((part) => part.trim()).filter(Boolean)); | ||
| 13 | - | ||
| 14 | - return ( | ||
| 15 | - <FormDialog open={props.open} onOpenChange={props.onOpenChange} title={props.note.title} description={t("notes.subtitle")}> | ||
| 16 | - <article class="overflow-hidden rounded-2xl border border-amber-200/70 bg-[linear-gradient(90deg,rgba(245,158,11,0.14)_0,rgba(245,158,11,0.14)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(120,113,108,0.16)_2.5rem)] shadow-sm dark:border-amber-500/20 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(214,211,209,0.12)_2.5rem)]"> | ||
| 17 | - <div class="min-h-80 space-y-4 px-5 py-5 pl-16"> | ||
| 18 | - <Show | ||
| 19 | - when={paragraphs().length > 0} | ||
| 20 | - fallback={<p class="text-sm italic leading-8 text-muted-foreground">{t("notes.noContent")}</p>} | ||
| 21 | - > | ||
| 22 | - <For each={paragraphs()}> | ||
| 23 | - {(paragraph) => <p class="whitespace-pre-wrap text-sm leading-8 text-foreground">{paragraph}</p>} | ||
| 24 | - </For> | ||
| 25 | - </Show> | ||
| 26 | - </div> | ||
| 27 | - </article> | ||
| 28 | - </FormDialog> | ||
| 29 | - ); | ||
| 30 | -} | ||
src/components/notes/note-reader-panel.tsxadded+50 -0
| @@ -0,0 +1,50 @@ | |||
| 1 | +import { For, Show, createMemo } from "solid-js"; | ||
| 2 | +import type { Note } from "@/api/types"; | ||
| 3 | +import { NoteFilesPanel } from "@/components/notes/note-files-panel"; | ||
| 4 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 5 | +import { useT } from "@/stores/preferences-context"; | ||
| 6 | + | ||
| 7 | +export function NoteReaderPanel(props: { | ||
| 8 | + note: Note | null; | ||
| 9 | + open: boolean; | ||
| 10 | + onOpenChange: (open: boolean) => void; | ||
| 11 | +}) { | ||
| 12 | + const t = useT(); | ||
| 13 | + const note = () => props.note; | ||
| 14 | + const paragraphs = createMemo(() => | ||
| 15 | + (note()?.content ?? "") | ||
| 16 | + .split(/\n{2,}/) | ||
| 17 | + .map((part) => part.trim()) | ||
| 18 | + .filter(Boolean), | ||
| 19 | + ); | ||
| 20 | + | ||
| 21 | + return ( | ||
| 22 | + <SidePanel | ||
| 23 | + open={props.open && note() != null} | ||
| 24 | + onOpenChange={props.onOpenChange} | ||
| 25 | + title={note()?.title ?? t("notes.title")} | ||
| 26 | + description={t("notes.subtitle")} | ||
| 27 | + size="wide" | ||
| 28 | + > | ||
| 29 | + <Show when={note()}> | ||
| 30 | + {(n) => ( | ||
| 31 | + <div class="space-y-4"> | ||
| 32 | + <article class="overflow-hidden rounded-2xl border border-amber-200/70 bg-[linear-gradient(90deg,rgba(245,158,11,0.14)_0,rgba(245,158,11,0.14)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(120,113,108,0.16)_2.5rem)] shadow-sm dark:border-amber-500/20 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(214,211,209,0.12)_2.5rem)]"> | ||
| 33 | + <div class="min-h-80 space-y-4 px-5 py-5 pl-16"> | ||
| 34 | + <Show | ||
| 35 | + when={paragraphs().length > 0} | ||
| 36 | + fallback={<p class="text-sm italic leading-8 text-muted-foreground">{t("notes.noContent")}</p>} | ||
| 37 | + > | ||
| 38 | + <For each={paragraphs()}> | ||
| 39 | + {(paragraph) => <p class="whitespace-pre-wrap text-sm leading-8 text-foreground">{paragraph}</p>} | ||
| 40 | + </For> | ||
| 41 | + </Show> | ||
| 42 | + </div> | ||
| 43 | + </article> | ||
| 44 | + <NoteFilesPanel noteId={n().id} active={props.open} /> | ||
| 45 | + </div> | ||
| 46 | + )} | ||
| 47 | + </Show> | ||
| 48 | + </SidePanel> | ||
| 49 | + ); | ||
| 50 | +} | ||
src/components/ui/dialog.tsxmodified+16 -3
| @@ -1,6 +1,7 @@ | |||
| 1 | import { Dialog as DialogPrimitive } from "@kobalte/core/dialog"; | 1 | import { Dialog as DialogPrimitive } from "@kobalte/core/dialog"; |
| 2 | import type { ComponentProps, ParentProps, ValidComponent } from "solid-js"; | 2 | import type { ComponentProps, ParentProps, ValidComponent } from "solid-js"; |
| 3 | import { splitProps } from "solid-js"; | 3 | import { splitProps } from "solid-js"; |
| 4 | +import { IconX } from "@/components/ui/icons"; | ||
| 4 | import { cn } from "@/lib/cn"; | 5 | import { cn } from "@/lib/cn"; |
| 5 | 6 | ||
| 6 | export const Dialog = DialogPrimitive; | 7 | export const Dialog = DialogPrimitive; |
| @@ -17,14 +18,26 @@ export function DialogContent<T extends ValidComponent = "div">( | |||
| 17 | return ( | 18 | return ( |
| 18 | <DialogPrimitive.Portal> | 19 | <DialogPrimitive.Portal> |
| 19 | <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/40 dark:bg-black/60" /> | 20 | <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/40 dark:bg-black/60" /> |
| 20 | - <div class="fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"> | 21 | + {/* flex center — animate-fade-up must not own transform positioning */} |
| 22 | + <div class="pointer-events-none fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"> | ||
| 21 | <DialogPrimitive.Content | 23 | <DialogPrimitive.Content |
| 22 | class={cn( | 24 | class={cn( |
| 23 | - "flex max-h-[min(90vh,48rem)] w-full max-w-3xl flex-col overflow-hidden rounded-sm border border-border bg-popover text-popover-foreground shadow-md outline-none animate-fade-up", | 25 | + "pointer-events-auto relative flex max-h-[min(90vh,48rem)] w-full max-w-3xl flex-col overflow-hidden rounded-sm border border-border bg-popover text-popover-foreground shadow-md outline-none animate-fade-up", |
| 24 | local.class, | 26 | local.class, |
| 25 | )} | 27 | )} |
| 28 | + // ponytail: close only via X — outside/ESC races with clickable cards underneath | ||
| 29 | + onPointerDownOutside={(e) => e.preventDefault()} | ||
| 30 | + onInteractOutside={(e) => e.preventDefault()} | ||
| 31 | + onEscapeKeyDown={(e) => e.preventDefault()} | ||
| 26 | {...rest} | 32 | {...rest} |
| 27 | > | 33 | > |
| 34 | + <DialogPrimitive.CloseButton | ||
| 35 | + type="button" | ||
| 36 | + class="absolute right-3 top-3 z-10 inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/80 bg-background text-muted-foreground shadow-sm transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" | ||
| 37 | + aria-label="Close" | ||
| 38 | + > | ||
| 39 | + <IconX class="h-4 w-4" /> | ||
| 40 | + </DialogPrimitive.CloseButton> | ||
| 28 | {local.children} | 41 | {local.children} |
| 29 | </DialogPrimitive.Content> | 42 | </DialogPrimitive.Content> |
| 30 | </div> | 43 | </div> |
| @@ -33,7 +46,7 @@ export function DialogContent<T extends ValidComponent = "div">( | |||
| 33 | } | 46 | } |
| 34 | 47 | ||
| 35 | export function DialogHeader(props: ParentProps<{ class?: string }>) { | 48 | export function DialogHeader(props: ParentProps<{ class?: string }>) { |
| 36 | - return <div class={cn("border-b border-border px-5 py-4", props.class)}>{props.children}</div>; | 49 | + return <div class={cn("border-b border-border px-5 py-4 pr-14", props.class)}>{props.children}</div>; |
| 37 | } | 50 | } |
| 38 | 51 | ||
| 39 | export function DialogBody(props: ParentProps<{ class?: string }>) { | 52 | export function DialogBody(props: ParentProps<{ class?: string }>) { |
src/i18n/messages.tsmodified+30 -0
| @@ -59,6 +59,7 @@ export type MessageKey = | |||
| 59 | | "confirm.deleteTitle" | 59 | | "confirm.deleteTitle" |
| 60 | | "confirm.updateTitle" | 60 | | "confirm.updateTitle" |
| 61 | | "confirm.deleteNote" | 61 | | "confirm.deleteNote" |
| 62 | + | "confirm.deleteNoteFile" | ||
| 62 | | "confirm.updateNote" | 63 | | "confirm.updateNote" |
| 63 | | "confirm.deleteEvent" | 64 | | "confirm.deleteEvent" |
| 64 | | "confirm.updateEvent" | 65 | | "confirm.updateEvent" |
| @@ -176,6 +177,12 @@ export type MessageKey = | |||
| 176 | | "notes.new" | 177 | | "notes.new" |
| 177 | | "notes.empty" | 178 | | "notes.empty" |
| 178 | | "notes.noContent" | 179 | | "notes.noContent" |
| 180 | + | "notes.files" | ||
| 181 | + | "notes.filesHelp" | ||
| 182 | + | "notes.addFile" | ||
| 183 | + | "notes.noFiles" | ||
| 184 | + | "notes.fileLimit" | ||
| 185 | + | "notes.fileTooLarge" | ||
| 179 | | "notes.helpTitle" | 186 | | "notes.helpTitle" |
| 180 | | "notes.helpBody" | 187 | | "notes.helpBody" |
| 181 | | "events.title" | 188 | | "events.title" |
| @@ -443,6 +450,9 @@ export type MessageKey = | |||
| 443 | | "settings.locked" | 450 | | "settings.locked" |
| 444 | | "settings.unsaved" | 451 | | "settings.unsaved" |
| 445 | | "settings.empty" | 452 | | "settings.empty" |
| 453 | + | "settings.maxFileSize" | ||
| 454 | + | "settings.maxFileSizeHelp" | ||
| 455 | + | "settings.maxFileSizeInvalid" | ||
| 446 | | "terms.title" | 456 | | "terms.title" |
| 447 | | "terms.subtitle" | 457 | | "terms.subtitle" |
| 448 | | "terms.create" | 458 | | "terms.create" |
| @@ -562,6 +572,7 @@ const en: Dict = { | |||
| 562 | "confirm.deleteTitle": "Confirm delete", | 572 | "confirm.deleteTitle": "Confirm delete", |
| 563 | "confirm.updateTitle": "Confirm update", | 573 | "confirm.updateTitle": "Confirm update", |
| 564 | "confirm.deleteNote": "Delete note “{title}”?", | 574 | "confirm.deleteNote": "Delete note “{title}”?", |
| 575 | + "confirm.deleteNoteFile": "Delete file “{title}”?", | ||
| 565 | "confirm.updateNote": "Update note “{title}”?", | 576 | "confirm.updateNote": "Update note “{title}”?", |
| 566 | "confirm.deleteEvent": "Delete event “{title}”?", | 577 | "confirm.deleteEvent": "Delete event “{title}”?", |
| 567 | "confirm.updateEvent": "Update event “{title}”?", | 578 | "confirm.updateEvent": "Update event “{title}”?", |
| @@ -679,6 +690,12 @@ const en: Dict = { | |||
| 679 | "notes.new": "New note", | 690 | "notes.new": "New note", |
| 680 | "notes.empty": "Nothing here yet. Write your first note.", | 691 | "notes.empty": "Nothing here yet. Write your first note.", |
| 681 | "notes.noContent": "No content", | 692 | "notes.noContent": "No content", |
| 693 | + "notes.files": "Attachments", | ||
| 694 | + "notes.filesHelp": "Up to 10 files. Max {size} each.", | ||
| 695 | + "notes.addFile": "Add file", | ||
| 696 | + "notes.noFiles": "No files attached.", | ||
| 697 | + "notes.fileLimit": "This note already has 10 files.", | ||
| 698 | + "notes.fileTooLarge": "File is too large. Max {size}.", | ||
| 682 | "notes.helpTitle": "About notes", | 699 | "notes.helpTitle": "About notes", |
| 683 | "notes.helpBody": | 700 | "notes.helpBody": |
| 684 | "Notes are private to you only. Title max 200 characters, content max 10,000. Delete and update open a confirmation dialog with a short summary before they run.", | 701 | "Notes are private to you only. Title max 200 characters, content max 10,000. Delete and update open a confirmation dialog with a short summary before they run.", |
| @@ -959,6 +976,9 @@ const en: Dict = { | |||
| 959 | "settings.locked": "Locked", | 976 | "settings.locked": "Locked", |
| 960 | "settings.unsaved": "Unsaved changes", | 977 | "settings.unsaved": "Unsaved changes", |
| 961 | "settings.empty": "No rows yet.", | 978 | "settings.empty": "No rows yet.", |
| 979 | + "settings.maxFileSize": "Max note file size", | ||
| 980 | + "settings.maxFileSizeHelp": "Per-file upload cap for note attachments, in MiB. Backend accepts 0.001-25 MiB.", | ||
| 981 | + "settings.maxFileSizeInvalid": "Enter a valid file size.", | ||
| 962 | "terms.title": "Academic terms", | 982 | "terms.title": "Academic terms", |
| 963 | "terms.subtitle": "Manage calendar terms and assign courses to them.", | 983 | "terms.subtitle": "Manage calendar terms and assign courses to them.", |
| 964 | "terms.create": "Create term", | 984 | "terms.create": "Create term", |
| @@ -1077,6 +1097,7 @@ const tr: Dict = { | |||
| 1077 | "confirm.deleteTitle": "Silmeyi onayla", | 1097 | "confirm.deleteTitle": "Silmeyi onayla", |
| 1078 | "confirm.updateTitle": "Güncellemeyi onayla", | 1098 | "confirm.updateTitle": "Güncellemeyi onayla", |
| 1079 | "confirm.deleteNote": "“{title}” notu silinsin mi?", | 1099 | "confirm.deleteNote": "“{title}” notu silinsin mi?", |
| 1100 | + "confirm.deleteNoteFile": "“{title}” dosyası silinsin mi?", | ||
| 1080 | "confirm.updateNote": "“{title}” notu güncellensin mi?", | 1101 | "confirm.updateNote": "“{title}” notu güncellensin mi?", |
| 1081 | "confirm.deleteEvent": "“{title}” etkinliği silinsin mi?", | 1102 | "confirm.deleteEvent": "“{title}” etkinliği silinsin mi?", |
| 1082 | "confirm.updateEvent": "“{title}” etkinliği güncellensin mi?", | 1103 | "confirm.updateEvent": "“{title}” etkinliği güncellensin mi?", |
| @@ -1194,6 +1215,12 @@ const tr: Dict = { | |||
| 1194 | "notes.new": "Yeni not", | 1215 | "notes.new": "Yeni not", |
| 1195 | "notes.empty": "Henüz bir şey yok. İlk notunu yaz.", | 1216 | "notes.empty": "Henüz bir şey yok. İlk notunu yaz.", |
| 1196 | "notes.noContent": "İçerik yok", | 1217 | "notes.noContent": "İçerik yok", |
| 1218 | + "notes.files": "Ekler", | ||
| 1219 | + "notes.filesHelp": "En fazla 10 dosya. Dosya başına {size} sınırı.", | ||
| 1220 | + "notes.addFile": "Dosya ekle", | ||
| 1221 | + "notes.noFiles": "Henüz dosya eklenmemiş.", | ||
| 1222 | + "notes.fileLimit": "Bu notta zaten 10 dosya var.", | ||
| 1223 | + "notes.fileTooLarge": "Dosya çok büyük. En fazla {size}.", | ||
| 1197 | "notes.helpTitle": "Notlar hakkında", | 1224 | "notes.helpTitle": "Notlar hakkında", |
| 1198 | "notes.helpBody": | 1225 | "notes.helpBody": |
| 1199 | "Notlar yalnızca sana aittir. Başlık en fazla 200, içerik 10.000 karakter. Silme ve güncelleme özetli onay penceresi ister.", | 1226 | "Notlar yalnızca sana aittir. Başlık en fazla 200, içerik 10.000 karakter. Silme ve güncelleme özetli onay penceresi ister.", |
| @@ -1474,6 +1501,9 @@ const tr: Dict = { | |||
| 1474 | "settings.locked": "Kilitli", | 1501 | "settings.locked": "Kilitli", |
| 1475 | "settings.unsaved": "Kaydedilmemiş değişiklikler", | 1502 | "settings.unsaved": "Kaydedilmemiş değişiklikler", |
| 1476 | "settings.empty": "Henüz satır yok.", | 1503 | "settings.empty": "Henüz satır yok.", |
| 1504 | + "settings.maxFileSize": "Not dosyası boyut sınırı", | ||
| 1505 | + "settings.maxFileSizeHelp": "Not ekleri için dosya başına yükleme sınırı, MiB cinsinden. Backend 0.001-25 MiB kabul eder.", | ||
| 1506 | + "settings.maxFileSizeInvalid": "Geçerli bir dosya boyutu gir.", | ||
| 1477 | "terms.title": "Akademik dönemler", | 1507 | "terms.title": "Akademik dönemler", |
| 1478 | "terms.subtitle": "Takvim dönemlerini yönet ve dersleri dönemlere bağla.", | 1508 | "terms.subtitle": "Takvim dönemlerini yönet ve dersleri dönemlere bağla.", |
| 1479 | "terms.create": "Dönem oluştur", | 1509 | "terms.create": "Dönem oluştur", |
src/pages/notes-page.tsxmodified+10 -4
| @@ -3,6 +3,7 @@ import { deleteNoteById } from "@/api/deleteNoteById"; | |||
| 3 | import { getNotes } from "@/api/getNotes"; | 3 | import { getNotes } from "@/api/getNotes"; |
| 4 | import { patchNoteById } from "@/api/patchNoteById"; | 4 | import { patchNoteById } from "@/api/patchNoteById"; |
| 5 | import { postNote } from "@/api/postNote"; | 5 | import { postNote } from "@/api/postNote"; |
| 6 | +import { postNoteFile } from "@/api/postNoteFile"; | ||
| 6 | import { formatApiError } from "@/api/client"; | 7 | import { formatApiError } from "@/api/client"; |
| 7 | import { Alert } from "@/components/ui/alert"; | 8 | import { Alert } from "@/components/ui/alert"; |
| 8 | import { RouteGuard } from "@/components/layout/route-guard"; | 9 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -10,10 +11,10 @@ import { PageHeader } from "@/components/layout/page-header"; | |||
| 10 | import { NoteForm } from "@/components/notes/note-form"; | 11 | import { NoteForm } from "@/components/notes/note-form"; |
| 11 | import { NoteList } from "@/components/notes/note-list"; | 12 | import { NoteList } from "@/components/notes/note-list"; |
| 12 | import { Button } from "@/components/ui/button"; | 13 | import { Button } from "@/components/ui/button"; |
| 13 | -import { FormDialog } from "@/components/ui/form-dialog"; | ||
| 14 | import { IconPlus } from "@/components/ui/icons"; | 14 | import { IconPlus } from "@/components/ui/icons"; |
| 15 | import { PageSpinner } from "@/components/ui/page-spinner"; | 15 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 16 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 16 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 17 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 17 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; | 18 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; |
| 18 | import { useT } from "@/stores/preferences-context"; | 19 | import { useT } from "@/stores/preferences-context"; |
| 19 | 20 | ||
| @@ -79,20 +80,25 @@ function NotesContent() { | |||
| 79 | /> | 80 | /> |
| 80 | </div> | 81 | </div> |
| 81 | 82 | ||
| 82 | - <FormDialog open={createOpen()} onOpenChange={setCreateOpen} title={t("notes.new")} description={t("notes.subtitle")}> | 83 | + <SidePanel open={createOpen()} onOpenChange={setCreateOpen} title={t("notes.new")} description={t("notes.subtitle")}> |
| 83 | <NoteForm | 84 | <NoteForm |
| 85 | + enableFiles | ||
| 84 | submitLabel={t("common.create")} | 86 | submitLabel={t("common.create")} |
| 85 | onCancel={() => setCreateOpen(false)} | 87 | onCancel={() => setCreateOpen(false)} |
| 86 | onSubmit={async (values) => { | 88 | onSubmit={async (values) => { |
| 87 | - await postNote({ | 89 | + const note = await postNote({ |
| 88 | title: values.title, | 90 | title: values.title, |
| 89 | content: values.content || undefined, | 91 | content: values.content || undefined, |
| 90 | }); | 92 | }); |
| 93 | + // ponytail: upload after create — file API needs note id | ||
| 94 | + for (const file of values.files) { | ||
| 95 | + await postNoteFile(note.id, file); | ||
| 96 | + } | ||
| 91 | await refetch(); | 97 | await refetch(); |
| 92 | setCreateOpen(false); | 98 | setCreateOpen(false); |
| 93 | }} | 99 | }} |
| 94 | /> | 100 | /> |
| 95 | - </FormDialog> | 101 | + </SidePanel> |
| 96 | 102 | ||
| 97 | <div class="space-y-5"> | 103 | <div class="space-y-5"> |
| 98 | <section class="min-w-0 space-y-4"> | 104 | <section class="min-w-0 space-y-4"> |
src/pages/settings-page.tsxmodified+36 -2
| @@ -24,6 +24,8 @@ const CORE_ATTENDANCE_LABELS = { | |||
| 24 | excused: "status.excused", | 24 | excused: "status.excused", |
| 25 | } as const; | 25 | } as const; |
| 26 | 26 | ||
| 27 | +const BYTES_PER_MIB = 1024 * 1024; | ||
| 28 | + | ||
| 27 | function isCoreAttendance(status: string): status is keyof typeof CORE_ATTENDANCE_LABELS { | 29 | function isCoreAttendance(status: string): status is keyof typeof CORE_ATTENDANCE_LABELS { |
| 28 | return status in CORE_ATTENDANCE_LABELS; | 30 | return status in CORE_ATTENDANCE_LABELS; |
| 29 | } | 31 | } |
| @@ -42,6 +44,7 @@ function SettingsContent() { | |||
| 42 | const [examKinds, setExamKinds] = createSignal<ExamKindSetting[]>([]); | 44 | const [examKinds, setExamKinds] = createSignal<ExamKindSetting[]>([]); |
| 43 | const [attendanceStatuses, setAttendanceStatuses] = createSignal<string[]>([]); | 45 | const [attendanceStatuses, setAttendanceStatuses] = createSignal<string[]>([]); |
| 44 | const [gradeBands, setGradeBands] = createSignal<GradeBand[]>([]); | 46 | const [gradeBands, setGradeBands] = createSignal<GradeBand[]>([]); |
| 47 | + const [maxFileMiB, setMaxFileMiB] = createSignal("5"); | ||
| 45 | const [error, setError] = createSignal(""); | 48 | const [error, setError] = createSignal(""); |
| 46 | const [saved, setSaved] = createSignal(false); | 49 | const [saved, setSaved] = createSignal(false); |
| 47 | const [pending, setPending] = createSignal(false); | 50 | const [pending, setPending] = createSignal(false); |
| @@ -53,19 +56,23 @@ function SettingsContent() { | |||
| 53 | exam_kinds: examKinds(), | 56 | exam_kinds: examKinds(), |
| 54 | attendance_statuses: attendanceStatuses(), | 57 | attendance_statuses: attendanceStatuses(), |
| 55 | grade_bands: gradeBands(), | 58 | grade_bands: gradeBands(), |
| 59 | + max_file_bytes: Math.round(Number(maxFileMiB()) * BYTES_PER_MIB), | ||
| 56 | }); | 60 | }); |
| 57 | 61 | ||
| 58 | createEffect(() => { | 62 | createEffect(() => { |
| 59 | const next = settings(); | 63 | const next = settings(); |
| 60 | if (!next) return; | 64 | if (!next) return; |
| 65 | + const fileBytes = next.max_file_bytes ?? 5 * BYTES_PER_MIB; | ||
| 61 | setExamKinds(next.exam_kinds.map((item) => ({ ...item }))); | 66 | setExamKinds(next.exam_kinds.map((item) => ({ ...item }))); |
| 62 | setAttendanceStatuses([...next.attendance_statuses]); | 67 | setAttendanceStatuses([...next.attendance_statuses]); |
| 63 | setGradeBands(next.grade_bands.map((item) => ({ ...item }))); | 68 | setGradeBands(next.grade_bands.map((item) => ({ ...item }))); |
| 69 | + setMaxFileMiB(String(Math.round((fileBytes / BYTES_PER_MIB) * 10) / 10)); | ||
| 64 | setBaseline( | 70 | setBaseline( |
| 65 | JSON.stringify({ | 71 | JSON.stringify({ |
| 66 | exam_kinds: next.exam_kinds, | 72 | exam_kinds: next.exam_kinds, |
| 67 | attendance_statuses: next.attendance_statuses, | 73 | attendance_statuses: next.attendance_statuses, |
| 68 | grade_bands: next.grade_bands, | 74 | grade_bands: next.grade_bands, |
| 75 | + max_file_bytes: fileBytes, | ||
| 69 | }), | 76 | }), |
| 70 | ); | 77 | ); |
| 71 | }); | 78 | }); |
| @@ -79,12 +86,18 @@ function SettingsContent() { | |||
| 79 | const save = async () => { | 86 | const save = async () => { |
| 80 | setError(""); | 87 | setError(""); |
| 81 | setSaved(false); | 88 | setSaved(false); |
| 89 | + const maxFileBytes = Math.round(Number(maxFileMiB()) * BYTES_PER_MIB); | ||
| 90 | + if (!Number.isFinite(maxFileBytes)) { | ||
| 91 | + setError(t("settings.maxFileSizeInvalid")); | ||
| 92 | + return; | ||
| 93 | + } | ||
| 82 | setPending(true); | 94 | setPending(true); |
| 83 | try { | 95 | try { |
| 84 | const next = await patchSettings({ | 96 | const next = await patchSettings({ |
| 85 | exam_kinds: examKinds().map((item) => ({ name: item.name.trim(), weight: Number(item.weight) })), | 97 | exam_kinds: examKinds().map((item) => ({ name: item.name.trim(), weight: Number(item.weight) })), |
| 86 | attendance_statuses: attendanceStatuses().map((status) => status.trim()), | 98 | attendance_statuses: attendanceStatuses().map((status) => status.trim()), |
| 87 | grade_bands: gradeBands().map((band) => ({ min: Number(band.min), label: band.label.trim() })), | 99 | grade_bands: gradeBands().map((band) => ({ min: Number(band.min), label: band.label.trim() })), |
| 100 | + max_file_bytes: maxFileBytes, | ||
| 88 | }); | 101 | }); |
| 89 | mutate(next); | 102 | mutate(next); |
| 90 | setBaseline( | 103 | setBaseline( |
| @@ -92,6 +105,7 @@ function SettingsContent() { | |||
| 92 | exam_kinds: next.exam_kinds, | 105 | exam_kinds: next.exam_kinds, |
| 93 | attendance_statuses: next.attendance_statuses, | 106 | attendance_statuses: next.attendance_statuses, |
| 94 | grade_bands: next.grade_bands, | 107 | grade_bands: next.grade_bands, |
| 108 | + max_file_bytes: next.max_file_bytes, | ||
| 95 | }), | 109 | }), |
| 96 | ); | 110 | ); |
| 97 | setSaved(true); | 111 | setSaved(true); |
| @@ -149,10 +163,30 @@ function SettingsContent() { | |||
| 149 | <ErrorAlert message={formatApiError(settings.error)} onRetry={() => void refetch()} /> | 163 | <ErrorAlert message={formatApiError(settings.error)} onRetry={() => void refetch()} /> |
| 150 | </Show> | 164 | </Show> |
| 151 | <Show when={settings()}> | 165 | <Show when={settings()}> |
| 152 | - <section class="grid grid-cols-3 gap-3"> | 166 | + <section class="grid grid-cols-2 gap-3 lg:grid-cols-4"> |
| 153 | <Metric label={t("settings.examKinds")} value={examKinds().length} /> | 167 | <Metric label={t("settings.examKinds")} value={examKinds().length} /> |
| 154 | <Metric label={t("settings.attendanceStatuses")} value={attendanceStatuses().length} /> | 168 | <Metric label={t("settings.attendanceStatuses")} value={attendanceStatuses().length} /> |
| 155 | <Metric label={t("settings.gradeBands")} value={gradeBands().length} /> | 169 | <Metric label={t("settings.gradeBands")} value={gradeBands().length} /> |
| 170 | + <Metric label={t("settings.maxFileSize")} value={`${maxFileMiB()} MiB`} /> | ||
| 171 | + </section> | ||
| 172 | + | ||
| 173 | + <section class="data-shell p-4"> | ||
| 174 | + <div class="grid gap-3 sm:grid-cols-[minmax(0,1fr)_10rem] sm:items-end"> | ||
| 175 | + <div> | ||
| 176 | + <h2 class="font-display text-base font-semibold">{t("settings.maxFileSize")}</h2> | ||
| 177 | + <p class="mt-1 text-sm text-muted-foreground">{t("settings.maxFileSizeHelp")}</p> | ||
| 178 | + </div> | ||
| 179 | + <Input | ||
| 180 | + aria-label={t("settings.maxFileSize")} | ||
| 181 | + class="h-10 rounded-md text-right font-mono" | ||
| 182 | + type="number" | ||
| 183 | + min={0.001} | ||
| 184 | + max={25} | ||
| 185 | + step={0.1} | ||
| 186 | + value={maxFileMiB()} | ||
| 187 | + onInput={(event) => setMaxFileMiB(event.currentTarget.value)} | ||
| 188 | + /> | ||
| 189 | + </div> | ||
| 156 | </section> | 190 | </section> |
| 157 | 191 | ||
| 158 | <div class="grid gap-4 xl:grid-cols-3"> | 192 | <div class="grid gap-4 xl:grid-cols-3"> |
| @@ -414,7 +448,7 @@ function SettingsContent() { | |||
| 414 | ); | 448 | ); |
| 415 | } | 449 | } |
| 416 | 450 | ||
| 417 | -function Metric(props: { label: string; value: number }) { | 451 | +function Metric(props: { label: string; value: number | string }) { |
| 418 | return ( | 452 | return ( |
| 419 | <div class="rounded-xl border border-border/60 bg-card px-3 py-3 shadow-xs"> | 453 | <div class="rounded-xl border border-border/60 bg-card px-3 py-3 shadow-xs"> |
| 420 | <p class="truncate text-[11px] font-medium uppercase tracking-wide text-muted-foreground">{props.label}</p> | 454 | <p class="truncate text-[11px] font-medium uppercase tracking-wide text-muted-foreground">{props.label}</p> |