✨ add homework navigation and UI
Browse files at this commit165e1dc11a95dfb3fc2e7d48ce92d7a7f1a7a160Parent: 6d0e29c- feat
- ✨ add homework navigation and UI
11 changed files +596 -2
- AGENTS.md +1 -1
- docs/navigation-patterns.md +1 -1
- docs/ui-redesign-tokens.md +1 -0
- src/components/homework/course-homework-panel.tsx +273 -0
- src/components/layout/app-shell.tsx +1 -0
- src/components/layout/side-nav.tsx +2 -0
- src/components/ui/icons.tsx +12 -0
- src/i18n/messages.ts +39 -0
- src/pages/course-detail-page.tsx +17 -0
- src/pages/homework-page.tsx +241 -0
- src/routes/router.tsx +8 -0
AGENTS.mdmodified+1 -1
| @@ -90,7 +90,7 @@ Solid components run **once**, there is no re-render: | |||
| 90 | - `docs/role-scope-matrix.md` — role access matrix for pages/nav/dashboard cards. | 90 | - `docs/role-scope-matrix.md` — role access matrix for pages/nav/dashboard cards. |
| 91 | - `docs/backend-ui-alignment-plan.md` — completed backend-alignment archive; do not treat it as active work unless backend scope changes. | 91 | - `docs/backend-ui-alignment-plan.md` — completed backend-alignment archive; do not treat it as active work unless backend scope changes. |
| 92 | - Durable resources use full detail pages. Short create/edit/filter work uses `SidePanel`. Destructive actions use confirm dialogs. | 92 | - Durable resources use full detail pages. Short create/edit/filter work uses `SidePanel`. Destructive actions use confirm dialogs. |
| 93 | -- Header create actions use compact icon+label buttons with consistent size and current radius (e.g. `variant="outline" size="sm" class="rounded-lg"` in `SectionDisclosure` header `actions`). Action buttons inside sub-panels must not duplicate section headers — primary create/add/assign actions must be placed in the header `actions` prop of the parent disclosure or page header. | 93 | +- Header create actions use compact icon+label buttons with consistent size and current radius. Page header primary create/add buttons use `size="sm" class="min-w-[7.5rem] rounded-lg"`; secondary/import buttons use `variant="outline"` with the same size/class. Section/sub-panel header actions use `variant="outline" size="sm" class="rounded-lg"` unless matching a page header button. Action buttons inside sub-panels must not duplicate section headers — primary create/add/assign actions must be placed in the header `actions` prop of the parent disclosure or page header. |
| 94 | - Application tables must use `src/components/ui/data-table.tsx` `DataTable`. Actions columns must use `w-28 min-w-[7rem] text-center whitespace-nowrap` to prevent truncation of localized headers like `"İŞLEMLER"`. | 94 | - Application tables must use `src/components/ui/data-table.tsx` `DataTable`. Actions columns must use `w-28 min-w-[7rem] text-center whitespace-nowrap` to prevent truncation of localized headers like `"İŞLEMLER"`. |
| 95 | - Pages/domain components must not import or render `Table` primitives directly; only the `DataTable` wrapper and table primitive files may do that. | 95 | - Pages/domain components must not import or render `Table` primitives directly; only the `DataTable` wrapper and table primitive files may do that. |
| 96 | - **Note Import Assistant**: Raw PDF/TXT/MD files are converted to structured Markdown notes using `src/lib/note-importer.ts`. Noise (page numbers, headers/footers, watermarks) is removed, PDF mid-sentence line wraps are re-joined, headings (`##`) and bullet lists are formatted, and OCR unreadable artifacts are flagged with `⚠️ Some content may be unreadable due to OCR/extraction issues`. Never invent content or fluff preamble. Note Import Assistant lives in a dedicated `SidePanel` triggered from the Notes page header to the right of the "Yeni Not" button. | 96 | - **Note Import Assistant**: Raw PDF/TXT/MD files are converted to structured Markdown notes using `src/lib/note-importer.ts`. Noise (page numbers, headers/footers, watermarks) is removed, PDF mid-sentence line wraps are re-joined, headings (`##`) and bullet lists are formatted, and OCR unreadable artifacts are flagged with `⚠️ Some content may be unreadable due to OCR/extraction issues`. Never invent content or fluff preamble. Note Import Assistant lives in a dedicated `SidePanel` triggered from the Notes page header to the right of the "Yeni Not" button. |
docs/navigation-patterns.mdmodified+1 -1
| @@ -60,7 +60,7 @@ Table action rules: | |||
| 60 | 60 | ||
| 61 | Delete or destructive confirmation stays in a confirm dialog, not a side panel. | 61 | Delete or destructive confirmation stays in a confirm dialog, not a side panel. |
| 62 | 62 | ||
| 63 | -Header create actions should use a consistent compact button shape: icon plus label, `size="sm"`, equal min-width, and the current app radius (`rounded-lg` in page headers). | 63 | +Header create actions should use a consistent compact button shape: icon plus label, `size="sm"`, equal min-width, and the current app radius. Page header primary create/add buttons use `class="min-w-[7.5rem] rounded-lg"`; secondary/import buttons add `variant="outline"` but keep the same size/class. |
| 64 | - On the Notes page header, the **"İçe Aktar"** button sits directly to the right of **"Yeni Not"** and opens a dedicated `SidePanel` for Note Import Assistant file conversion. | 64 | - On the Notes page header, the **"İçe Aktar"** button sits directly to the right of **"Yeni Not"** and opens a dedicated `SidePanel` for Note Import Assistant file conversion. |
| 65 | 65 | ||
| 66 | Date picking should use the shared `DatePicker` plus a separate `HH:mm` input when time is needed. Avoid native `date` and `datetime-local` controls in product forms. | 66 | Date picking should use the shared `DatePicker` plus a separate `HH:mm` input when time is needed. Avoid native `date` and `datetime-local` controls in product forms. |
docs/ui-redesign-tokens.mdmodified+1 -0
| @@ -139,6 +139,7 @@ Reference implementation: `src/pages/dashboard-page.tsx`. | |||
| 139 | ## Current Implementation Notes | 139 | ## Current Implementation Notes |
| 140 | 140 | ||
| 141 | - Data-heavy admin and management views should prefer `DataToolbar`, `DataTableFrame`, and `.data-table`. | 141 | - Data-heavy admin and management views should prefer `DataToolbar`, `DataTableFrame`, and `.data-table`. |
| 142 | +- Page header create/add buttons use compact icon + label controls with `size="sm" class="min-w-[7.5rem] rounded-lg"`; secondary header actions keep the same shape with `variant="outline"`. | ||
| 142 | - Row-level table actions should use `TableRowActions`; avoid inline action button clusters in table rows. | 143 | - Row-level table actions should use `TableRowActions`; avoid inline action button clusters in table rows. |
| 143 | - Quick create/edit flows should use `SidePanel`; destructive actions stay in confirm dialogs. | 144 | - Quick create/edit flows should use `SidePanel`; destructive actions stay in confirm dialogs. |
| 144 | - Durable resources keep full detail pages with breadcrumbs. | 145 | - Durable resources keep full detail pages with breadcrumbs. |
src/components/homework/course-homework-panel.tsxadded+273 -0
| @@ -0,0 +1,273 @@ | |||
| 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; | ||
| 2 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 3 | +import { deleteHomeworkById, patchHomeworkById } from "@/api/homework"; | ||
| 4 | +import { getCourseHomework, getCourseSubjects, postCourseHomework } from "@/api/courses"; | ||
| 5 | +import { getTime } from "@/api/time"; | ||
| 6 | +import { formatApiError } from "@/api/client"; | ||
| 7 | +import type { Homework, Subject } from "@/api/client"; | ||
| 8 | +import { Alert } from "@/components/ui/alert"; | ||
| 9 | +import { Badge } from "@/components/ui/badge"; | ||
| 10 | +import { Button } from "@/components/ui/button"; | ||
| 11 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 12 | +import { DataTable } from "@/components/ui/data-table"; | ||
| 13 | +import { DatePicker } from "@/components/ui/date-picker"; | ||
| 14 | +import { EmptyState } from "@/components/ui/empty-state"; | ||
| 15 | +import { IconEdit, IconTrash } from "@/components/ui/icons"; | ||
| 16 | +import { Input } from "@/components/ui/input"; | ||
| 17 | +import { Label } from "@/components/ui/label"; | ||
| 18 | +import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 19 | +import { Select } from "@/components/ui/select"; | ||
| 20 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 21 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 22 | +import { Textarea } from "@/components/ui/textarea"; | ||
| 23 | +import { createFlash } from "@/lib/flash"; | ||
| 24 | +import { formatDateTime } from "@/lib/format"; | ||
| 25 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 26 | + | ||
| 27 | +function dateInputToMs(date: string, time: string): number | null { | ||
| 28 | + const dateMatch = date.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); | ||
| 29 | + const timeMatch = time.trim().match(/^(\d{2}):(\d{2})$/); | ||
| 30 | + if (!dateMatch || !timeMatch) return null; | ||
| 31 | + const [, dayRaw, monthRaw, yearRaw] = dateMatch; | ||
| 32 | + const [, hourRaw, minuteRaw] = timeMatch; | ||
| 33 | + const day = Number(dayRaw); | ||
| 34 | + const month = Number(monthRaw); | ||
| 35 | + const year = Number(yearRaw); | ||
| 36 | + const hour = Number(hourRaw); | ||
| 37 | + const minute = Number(minuteRaw); | ||
| 38 | + const d = new Date(year, month - 1, day, hour, minute, 0, 0); | ||
| 39 | + if (d.getFullYear() !== year || d.getMonth() !== month - 1 || d.getDate() !== day || d.getHours() !== hour || d.getMinutes() !== minute) return null; | ||
| 40 | + return d.getTime(); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +function msToDateInput(ms: number): string { | ||
| 44 | + const d = new Date(ms); | ||
| 45 | + const pad = (n: number) => String(n).padStart(2, "0"); | ||
| 46 | + return `${pad(d.getDate())}/${pad(d.getMonth() + 1)}/${d.getFullYear()}`; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +function msToTimeInput(ms: number): string { | ||
| 50 | + const d = new Date(ms); | ||
| 51 | + const pad = (n: number) => String(n).padStart(2, "0"); | ||
| 52 | + return `${pad(d.getHours())}:${pad(d.getMinutes())}`; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +export function CourseHomeworkPanel(props: { | ||
| 56 | + courseId: string; | ||
| 57 | + canManage: boolean; | ||
| 58 | + active: boolean; | ||
| 59 | + createOpen: boolean; | ||
| 60 | + onCreateOpenChange: (open: boolean) => void; | ||
| 61 | + onCountChange: (count: number) => void; | ||
| 62 | +}) { | ||
| 63 | + const t = useT(); | ||
| 64 | + const { locale } = usePreferences(); | ||
| 65 | + const [homework, { refetch }] = createResource( | ||
| 66 | + () => (props.active ? props.courseId : null), | ||
| 67 | + async (courseId) => (courseId ? (await getCourseHomework(courseId)).items : []), | ||
| 68 | + ); | ||
| 69 | + const [subjects] = createResource( | ||
| 70 | + () => (props.active ? props.courseId : null), | ||
| 71 | + async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), | ||
| 72 | + ); | ||
| 73 | + const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | ||
| 74 | + const [editing, setEditing] = createSignal<Homework | null>(null); | ||
| 75 | + const [deleteTarget, setDeleteTarget] = createSignal<Homework | null>(null); | ||
| 76 | + const [title, setTitle] = createSignal(""); | ||
| 77 | + const [description, setDescription] = createSignal(""); | ||
| 78 | + const [subjectId, setSubjectId] = createSignal(""); | ||
| 79 | + const [dueDate, setDueDate] = createSignal(""); | ||
| 80 | + const [dueTime, setDueTime] = createSignal(""); | ||
| 81 | + const [error, setError] = createSignal(""); | ||
| 82 | + const [pending, setPending] = createSignal(false); | ||
| 83 | + const [flash, setFlash] = createFlash(); | ||
| 84 | + | ||
| 85 | + const subjectName = (id: string) => subjects()?.find((subject) => subject.id === id)?.name ?? id; | ||
| 86 | + const resetForm = () => { | ||
| 87 | + setEditing(null); | ||
| 88 | + setTitle(""); | ||
| 89 | + setDescription(""); | ||
| 90 | + setSubjectId(subjects()?.[0]?.id ?? ""); | ||
| 91 | + setDueDate(""); | ||
| 92 | + setDueTime(""); | ||
| 93 | + setError(""); | ||
| 94 | + }; | ||
| 95 | + const openEdit = (item: Homework) => { | ||
| 96 | + setEditing(item); | ||
| 97 | + setTitle(item.title); | ||
| 98 | + setDescription(item.description ?? ""); | ||
| 99 | + setSubjectId(item.subject); | ||
| 100 | + setDueDate(msToDateInput(item.due_at)); | ||
| 101 | + setDueTime(msToTimeInput(item.due_at)); | ||
| 102 | + setError(""); | ||
| 103 | + props.onCreateOpenChange(true); | ||
| 104 | + }; | ||
| 105 | + const setPanelOpen = (open: boolean) => { | ||
| 106 | + props.onCreateOpenChange(open); | ||
| 107 | + if (!open) resetForm(); | ||
| 108 | + }; | ||
| 109 | + | ||
| 110 | + createEffect(() => props.onCountChange(homework()?.length ?? 0)); | ||
| 111 | + createEffect(() => { | ||
| 112 | + if (!subjectId()) setSubjectId(subjects()?.[0]?.id ?? ""); | ||
| 113 | + }); | ||
| 114 | + | ||
| 115 | + const save = async (event: SubmitEvent) => { | ||
| 116 | + event.preventDefault(); | ||
| 117 | + setError(""); | ||
| 118 | + const due_at = dateInputToMs(dueDate(), dueTime()); | ||
| 119 | + if (due_at == null) { | ||
| 120 | + setError(t("homework.dueRequired")); | ||
| 121 | + return; | ||
| 122 | + } | ||
| 123 | + const current = editing(); | ||
| 124 | + if ((!current || due_at !== current.due_at) && due_at < (serverTime()?.now ?? Date.now())) { | ||
| 125 | + setError(t("form.timePast")); | ||
| 126 | + return; | ||
| 127 | + } | ||
| 128 | + setPending(true); | ||
| 129 | + try { | ||
| 130 | + if (current) { | ||
| 131 | + await patchHomeworkById(current.id, { | ||
| 132 | + title: title().trim(), | ||
| 133 | + description: description().trim() || null, | ||
| 134 | + subject_id: subjectId(), | ||
| 135 | + due_at, | ||
| 136 | + }); | ||
| 137 | + setFlash(t("common.saved")); | ||
| 138 | + } else { | ||
| 139 | + await postCourseHomework(props.courseId, { | ||
| 140 | + title: title().trim(), | ||
| 141 | + description: description().trim() || null, | ||
| 142 | + subject_id: subjectId(), | ||
| 143 | + due_at, | ||
| 144 | + }); | ||
| 145 | + setFlash(t("common.created")); | ||
| 146 | + } | ||
| 147 | + setPanelOpen(false); | ||
| 148 | + await refetch(); | ||
| 149 | + } catch (err) { | ||
| 150 | + setError(formatApiError(err)); | ||
| 151 | + } finally { | ||
| 152 | + setPending(false); | ||
| 153 | + } | ||
| 154 | + }; | ||
| 155 | + | ||
| 156 | + const columns = createMemo<ColumnDef<Homework>[]>(() => [ | ||
| 157 | + { | ||
| 158 | + accessorKey: "title", | ||
| 159 | + header: t("form.title"), | ||
| 160 | + meta: { cellClass: "font-medium" }, | ||
| 161 | + }, | ||
| 162 | + { | ||
| 163 | + id: "subject", | ||
| 164 | + accessorFn: (row) => subjectName(row.subject), | ||
| 165 | + header: t("subjects.subject"), | ||
| 166 | + cell: (cell) => <Badge variant="outline" class="rounded-full">{subjectName(cell.row.original.subject)}</Badge>, | ||
| 167 | + }, | ||
| 168 | + { | ||
| 169 | + id: "due_at", | ||
| 170 | + accessorFn: (row) => row.due_at, | ||
| 171 | + header: t("homework.dueAt"), | ||
| 172 | + meta: { cellClass: "mono text-xs text-muted-foreground" }, | ||
| 173 | + cell: (cell) => formatDateTime(cell.row.original.due_at, locale()), | ||
| 174 | + }, | ||
| 175 | + { | ||
| 176 | + id: "assigned", | ||
| 177 | + accessorFn: (row) => row.assigned?.length ?? 0, | ||
| 178 | + header: t("homework.assigned"), | ||
| 179 | + cell: (cell) => cell.row.original.assigned?.length ? t("common.countItem", { count: cell.row.original.assigned.length, item: t("courses.rosterItem") }) : t("homework.wholeCourse"), | ||
| 180 | + }, | ||
| 181 | + ...(props.canManage | ||
| 182 | + ? [{ | ||
| 183 | + id: "actions", | ||
| 184 | + header: t("common.actions"), | ||
| 185 | + meta: { headerClass: "w-28 min-w-[7rem] text-center whitespace-nowrap", cellClass: "px-1 text-center" }, | ||
| 186 | + cell: (cell) => ( | ||
| 187 | + <TableRowActions | ||
| 188 | + label={t("common.actions")} | ||
| 189 | + actions={[ | ||
| 190 | + { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => openEdit(cell.row.original) }, | ||
| 191 | + { label: t("common.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteTarget(cell.row.original) }, | ||
| 192 | + ]} | ||
| 193 | + /> | ||
| 194 | + ), | ||
| 195 | + } satisfies ColumnDef<Homework>] | ||
| 196 | + : []), | ||
| 197 | + ]); | ||
| 198 | + | ||
| 199 | + return ( | ||
| 200 | + <div class="space-y-4"> | ||
| 201 | + <Show when={flash()}> | ||
| 202 | + <Alert variant="success">{flash()}</Alert> | ||
| 203 | + </Show> | ||
| 204 | + <Show when={error() && !props.createOpen}> | ||
| 205 | + <Alert variant="destructive">{error()}</Alert> | ||
| 206 | + </Show> | ||
| 207 | + | ||
| 208 | + <Suspense fallback={<PageSpinner />}> | ||
| 209 | + <Show when={(homework() ?? []).length > 0} fallback={<EmptyState title={t("homework.empty")} />}> | ||
| 210 | + <DataTable columns={columns()} data={homework() ?? []} filterColumn="title" enablePagination pageSize={10} empty={t("homework.empty")} /> | ||
| 211 | + </Show> | ||
| 212 | + </Suspense> | ||
| 213 | + | ||
| 214 | + <SidePanel open={props.createOpen} onOpenChange={setPanelOpen} title={editing() ? t("homework.edit") : t("homework.add")} description={t("homework.help")}> | ||
| 215 | + <form class="space-y-4" onSubmit={(event) => void save(event)}> | ||
| 216 | + <Show when={error()}> | ||
| 217 | + <Alert variant="destructive">{error()}</Alert> | ||
| 218 | + </Show> | ||
| 219 | + <div class="space-y-1.5"> | ||
| 220 | + <Label for="homework-title">{t("form.title")}</Label> | ||
| 221 | + <Input id="homework-title" required maxlength={200} value={title()} onInput={(event) => setTitle(event.currentTarget.value)} /> | ||
| 222 | + </div> | ||
| 223 | + <div class="space-y-1.5"> | ||
| 224 | + <Label for="homework-subject">{t("subjects.subject")}</Label> | ||
| 225 | + <Select id="homework-subject" required value={subjectId()} onChange={(event) => setSubjectId(event.currentTarget.value)}> | ||
| 226 | + <For each={subjects() ?? []}>{(subject: Subject) => <option value={subject.id}>{subject.name}</option>}</For> | ||
| 227 | + </Select> | ||
| 228 | + </div> | ||
| 229 | + <div class="space-y-1.5"> | ||
| 230 | + <Label for="homework-description">{t("form.description")}</Label> | ||
| 231 | + <Textarea id="homework-description" maxlength={2000} rows={3} value={description()} onInput={(event) => setDescription(event.currentTarget.value)} /> | ||
| 232 | + </div> | ||
| 233 | + <div class="space-y-1.5"> | ||
| 234 | + <Label for="homework-due-date">{t("homework.dueAt")}</Label> | ||
| 235 | + <div class="grid grid-cols-2 gap-2"> | ||
| 236 | + <DatePicker id="homework-due-date" class="h-10" placeholder={t("form.datePlaceholder")} value={dueDate()} required onChange={setDueDate} /> | ||
| 237 | + <Input class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/35" placeholder="17:00" value={dueTime()} required onInput={(event) => setDueTime(event.currentTarget.value)} /> | ||
| 238 | + </div> | ||
| 239 | + </div> | ||
| 240 | + <p class="rounded-xl border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">{t("homework.wholeCourseHelp")}</p> | ||
| 241 | + <div class="flex flex-wrap gap-2"> | ||
| 242 | + <Button type="submit" class="rounded-xl" disabled={pending() || (subjects() ?? []).length === 0}>{editing() ? t("common.update") : t("common.create")}</Button> | ||
| 243 | + <Button type="button" variant="outline" class="rounded-xl" onClick={() => setPanelOpen(false)}>{t("common.cancel")}</Button> | ||
| 244 | + </div> | ||
| 245 | + </form> | ||
| 246 | + </SidePanel> | ||
| 247 | + | ||
| 248 | + <ConfirmDialog | ||
| 249 | + open={deleteTarget() != null} | ||
| 250 | + onOpenChange={(open) => { | ||
| 251 | + if (!open) setDeleteTarget(null); | ||
| 252 | + }} | ||
| 253 | + title={t("confirm.deleteTitle")} | ||
| 254 | + variant="destructive" | ||
| 255 | + summary={deleteTarget()?.title ?? ""} | ||
| 256 | + onConfirm={async () => { | ||
| 257 | + const target = deleteTarget(); | ||
| 258 | + if (!target) return; | ||
| 259 | + setError(""); | ||
| 260 | + try { | ||
| 261 | + await deleteHomeworkById(target.id); | ||
| 262 | + await refetch(); | ||
| 263 | + setFlash(t("common.deleted")); | ||
| 264 | + } catch (err) { | ||
| 265 | + setError(formatApiError(err)); | ||
| 266 | + } finally { | ||
| 267 | + setDeleteTarget(null); | ||
| 268 | + } | ||
| 269 | + }} | ||
| 270 | + /> | ||
| 271 | + </div> | ||
| 272 | + ); | ||
| 273 | +} | ||
src/components/layout/app-shell.tsxmodified+1 -0
| @@ -38,6 +38,7 @@ export function AppShell(props: ParentProps) { | |||
| 38 | if (path === "/courses" || path.startsWith("/courses/")) return `${t("nav.group.classes")} / ${t("nav.courses")}`; | 38 | if (path === "/courses" || path.startsWith("/courses/")) return `${t("nav.group.classes")} / ${t("nav.courses")}`; |
| 39 | if (path === "/studies") return `${t("nav.group.classes")} / ${t("nav.studies")}`; | 39 | if (path === "/studies") return `${t("nav.group.classes")} / ${t("nav.studies")}`; |
| 40 | if (path === "/clubs") return `${t("nav.group.classes")} / ${t("nav.clubs")}`; | 40 | if (path === "/clubs") return `${t("nav.group.classes")} / ${t("nav.clubs")}`; |
| 41 | + if (path === "/homework") return `${t("nav.group.classes")} / ${t("nav.homework")}`; | ||
| 41 | if (path === "/events" || path.startsWith("/events/")) return `${t("nav.group.classes")} / ${t("nav.events")}`; | 42 | if (path === "/events" || path.startsWith("/events/")) return `${t("nav.group.classes")} / ${t("nav.events")}`; |
| 42 | if (path === "/exams" || path.startsWith("/exams/")) return `${t("nav.group.classes")} / ${t("nav.exams")}`; | 43 | if (path === "/exams" || path.startsWith("/exams/")) return `${t("nav.group.classes")} / ${t("nav.exams")}`; |
| 43 | if (path === "/calendar") return `${t("nav.group.classes")} / ${t("nav.calendar")}`; | 44 | if (path === "/calendar") return `${t("nav.group.classes")} / ${t("nav.calendar")}`; |
src/components/layout/side-nav.tsxmodified+2 -0
| @@ -24,6 +24,7 @@ import { | |||
| 24 | IconExam, | 24 | IconExam, |
| 25 | IconGlobe, | 25 | IconGlobe, |
| 26 | IconHelpCircle, | 26 | IconHelpCircle, |
| 27 | + IconHomework, | ||
| 27 | IconHome, | 28 | IconHome, |
| 28 | IconMessage, | 29 | IconMessage, |
| 29 | IconNote, | 30 | IconNote, |
| @@ -64,6 +65,7 @@ const NAV_GROUPS: NavGroup[] = [ | |||
| 64 | { to: "/courses", labelKey: "nav.courses", Icon: IconBook }, | 65 | { to: "/courses", labelKey: "nav.courses", Icon: IconBook }, |
| 65 | { to: "/studies", labelKey: "nav.studies", Icon: IconClock }, | 66 | { to: "/studies", labelKey: "nav.studies", Icon: IconClock }, |
| 66 | { to: "/clubs", labelKey: "nav.clubs", Icon: IconUsers }, | 67 | { to: "/clubs", labelKey: "nav.clubs", Icon: IconUsers }, |
| 68 | + { to: "/homework", labelKey: "nav.homework", Icon: IconHomework }, | ||
| 67 | { to: "/exams", labelKey: "nav.exams", Icon: IconExam }, | 69 | { to: "/exams", labelKey: "nav.exams", Icon: IconExam }, |
| 68 | { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, | 70 | { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, |
| 69 | { to: "/calendar", labelKey: "nav.calendar", Icon: IconCalendarDays }, | 71 | { to: "/calendar", labelKey: "nav.calendar", Icon: IconCalendarDays }, |
src/components/ui/icons.tsxmodified+12 -0
| @@ -371,6 +371,18 @@ export function IconFileText(props: IconProps) { | |||
| 371 | ); | 371 | ); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | +export function IconHomework(props: IconProps) { | ||
| 375 | + return ( | ||
| 376 | + <Svg {...props}> | ||
| 377 | + <path d="M15 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6Z" /> | ||
| 378 | + <path d="M14 2v4a2 2 0 0 0 2 2h3" /> | ||
| 379 | + <path d="M8 13h5" /> | ||
| 380 | + <path d="M8 17h3" /> | ||
| 381 | + <path d="m15 16 4-4 2 2-4 4h-2z" /> | ||
| 382 | + </Svg> | ||
| 383 | + ); | ||
| 384 | +} | ||
| 385 | + | ||
| 374 | export function IconFileSpreadsheet(props: IconProps) { | 386 | export function IconFileSpreadsheet(props: IconProps) { |
| 375 | return ( | 387 | return ( |
| 376 | <Svg {...props}> | 388 | <Svg {...props}> |
src/i18n/messages.tsmodified+39 -0
| @@ -14,6 +14,7 @@ export type MessageKey = | |||
| 14 | | "nav.notes" | 14 | | "nav.notes" |
| 15 | | "nav.events" | 15 | | "nav.events" |
| 16 | | "nav.exams" | 16 | | "nav.exams" |
| 17 | + | "nav.homework" | ||
| 17 | | "nav.courses" | 18 | | "nav.courses" |
| 18 | | "nav.studies" | 19 | | "nav.studies" |
| 19 | | "nav.clubs" | 20 | | "nav.clubs" |
| @@ -557,6 +558,18 @@ export type MessageKey = | |||
| 557 | | "courses.teacherAssigned" | 558 | | "courses.teacherAssigned" |
| 558 | | "courses.teacherUnassigned" | 559 | | "courses.teacherUnassigned" |
| 559 | | "courses.noTeachers" | 560 | | "courses.noTeachers" |
| 561 | + | "homework.title" | ||
| 562 | + | "homework.item" | ||
| 563 | + | "homework.add" | ||
| 564 | + | "homework.edit" | ||
| 565 | + | "homework.empty" | ||
| 566 | + | "homework.help" | ||
| 567 | + | "homework.listHelp" | ||
| 568 | + | "homework.dueAt" | ||
| 569 | + | "homework.assigned" | ||
| 570 | + | "homework.wholeCourse" | ||
| 571 | + | "homework.wholeCourseHelp" | ||
| 572 | + | "homework.dueRequired" | ||
| 560 | | "marks.title" | 573 | | "marks.title" |
| 561 | | "marks.subtitle" | 574 | | "marks.subtitle" |
| 562 | | "marks.overall" | 575 | | "marks.overall" |
| @@ -748,6 +761,7 @@ const en: Dict = { | |||
| 748 | "nav.notes": "Notes", | 761 | "nav.notes": "Notes", |
| 749 | "nav.events": "Events", | 762 | "nav.events": "Events", |
| 750 | "nav.exams": "Exams", | 763 | "nav.exams": "Exams", |
| 764 | + "nav.homework": "Homework", | ||
| 751 | "nav.courses": "Courses", | 765 | "nav.courses": "Courses", |
| 752 | "nav.studies": "Study sessions", | 766 | "nav.studies": "Study sessions", |
| 753 | "nav.clubs": "Clubs", | 767 | "nav.clubs": "Clubs", |
| @@ -1309,6 +1323,18 @@ const en: Dict = { | |||
| 1309 | "courses.teacherAssigned": "Teacher assigned successfully.", | 1323 | "courses.teacherAssigned": "Teacher assigned successfully.", |
| 1310 | "courses.teacherUnassigned": "Teacher unassigned successfully.", | 1324 | "courses.teacherUnassigned": "Teacher unassigned successfully.", |
| 1311 | "courses.noTeachers": "No assigned teachers.", | 1325 | "courses.noTeachers": "No assigned teachers.", |
| 1326 | + "homework.title": "Homework", | ||
| 1327 | + "homework.item": "Homework", | ||
| 1328 | + "homework.add": "Add homework", | ||
| 1329 | + "homework.edit": "Edit homework", | ||
| 1330 | + "homework.empty": "No homework yet.", | ||
| 1331 | + "homework.help": "Assign homework for this course and track its due date.", | ||
| 1332 | + "homework.listHelp": "All visible homework. Open a row to manage it in its course.", | ||
| 1333 | + "homework.dueAt": "Due date", | ||
| 1334 | + "homework.assigned": "Assigned to", | ||
| 1335 | + "homework.wholeCourse": "Whole course", | ||
| 1336 | + "homework.wholeCourseHelp": "This first version assigns homework to the whole course. Use the backend API for student subsets until the multi-select UI exists.", | ||
| 1337 | + "homework.dueRequired": "Choose a valid due date and time.", | ||
| 1312 | "marks.title": "Report card", | 1338 | "marks.title": "Report card", |
| 1313 | "marks.subtitle": "Weighted averages across enrolled courses.", | 1339 | "marks.subtitle": "Weighted averages across enrolled courses.", |
| 1314 | "marks.overall": "Overall average", | 1340 | "marks.overall": "Overall average", |
| @@ -1494,6 +1520,7 @@ const tr: Dict = { | |||
| 1494 | "nav.notes": "Defter", | 1520 | "nav.notes": "Defter", |
| 1495 | "nav.events": "Etkinlikler", | 1521 | "nav.events": "Etkinlikler", |
| 1496 | "nav.exams": "Sınavlar", | 1522 | "nav.exams": "Sınavlar", |
| 1523 | + "nav.homework": "Ödevler", | ||
| 1497 | "nav.courses": "Ders", | 1524 | "nav.courses": "Ders", |
| 1498 | "nav.studies": "Etüt", | 1525 | "nav.studies": "Etüt", |
| 1499 | "nav.clubs": "Kulüp", | 1526 | "nav.clubs": "Kulüp", |
| @@ -2055,6 +2082,18 @@ const tr: Dict = { | |||
| 2055 | "courses.teacherAssigned": "Öğretmen başarıyla atandı.", | 2082 | "courses.teacherAssigned": "Öğretmen başarıyla atandı.", |
| 2056 | "courses.teacherUnassigned": "Öğretmen başarıyla çıkarıldı.", | 2083 | "courses.teacherUnassigned": "Öğretmen başarıyla çıkarıldı.", |
| 2057 | "courses.noTeachers": "Atanmış öğretmen yok.", | 2084 | "courses.noTeachers": "Atanmış öğretmen yok.", |
| 2085 | + "homework.title": "Ödevler", | ||
| 2086 | + "homework.item": "Ödev", | ||
| 2087 | + "homework.add": "Ödev ekle", | ||
| 2088 | + "homework.edit": "Ödevi düzenle", | ||
| 2089 | + "homework.empty": "Henüz ödev yok.", | ||
| 2090 | + "homework.help": "Bu ders için ödev ver ve son teslim tarihini takip et.", | ||
| 2091 | + "homework.listHelp": "Görebildiğin tüm ödevler. Yönetmek için satırı açıp dersine git.", | ||
| 2092 | + "homework.dueAt": "Son teslim", | ||
| 2093 | + "homework.assigned": "Atanan", | ||
| 2094 | + "homework.wholeCourse": "Tüm ders", | ||
| 2095 | + "homework.wholeCourseHelp": "İlk sürüm ödevi tüm derse atar. Öğrenci alt grupları için çoklu seçim arayüzü gelene kadar backend API kullanılabilir.", | ||
| 2096 | + "homework.dueRequired": "Geçerli bir son teslim tarihi ve saati seç.", | ||
| 2058 | "marks.title": "Karnem", | 2097 | "marks.title": "Karnem", |
| 2059 | "marks.subtitle": "Kayıtlı derslerdeki ağırlıklı ortalamalar.", | 2098 | "marks.subtitle": "Kayıtlı derslerdeki ağırlıklı ortalamalar.", |
| 2060 | "marks.overall": "Genel ortalama", | 2099 | "marks.overall": "Genel ortalama", |
src/pages/course-detail-page.tsxmodified+17 -0
| @@ -20,6 +20,7 @@ import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; | |||
| 20 | import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; | 20 | import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; |
| 21 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; | 21 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; |
| 22 | import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel"; | 22 | import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel"; |
| 23 | +import { CourseHomeworkPanel } from "@/components/homework/course-homework-panel"; | ||
| 23 | import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; | 24 | import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; |
| 24 | import { RouteGuard } from "@/components/layout/route-guard"; | 25 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 25 | import { PageHeader } from "@/components/layout/page-header"; | 26 | import { PageHeader } from "@/components/layout/page-header"; |
| @@ -114,10 +115,12 @@ function CourseDetailContent() { | |||
| 114 | const [createdCourseExam, setCreatedCourseExam] = createSignal<Exam | null>(null); | 115 | const [createdCourseExam, setCreatedCourseExam] = createSignal<Exam | null>(null); |
| 115 | const [showSubjectForm, setShowSubjectForm] = createSignal(false); | 116 | const [showSubjectForm, setShowSubjectForm] = createSignal(false); |
| 116 | const [showSessionForm, setShowSessionForm] = createSignal(false); | 117 | const [showSessionForm, setShowSessionForm] = createSignal(false); |
| 118 | + const [showHomeworkForm, setShowHomeworkForm] = createSignal(false); | ||
| 117 | const [showTeacherForm, setShowTeacherForm] = createSignal(false); | 119 | const [showTeacherForm, setShowTeacherForm] = createSignal(false); |
| 118 | const [showEnrollPanel, setShowEnrollPanel] = createSignal(false); | 120 | const [showEnrollPanel, setShowEnrollPanel] = createSignal(false); |
| 119 | const [subjectCount, setSubjectCount] = createSignal(0); | 121 | const [subjectCount, setSubjectCount] = createSignal(0); |
| 120 | const [sessionCount, setSessionCount] = createSignal(0); | 122 | const [sessionCount, setSessionCount] = createSignal(0); |
| 123 | + const [homeworkCount, setHomeworkCount] = createSignal(0); | ||
| 121 | const [enrollUserId, setEnrollUserId] = createSignal(""); | 124 | const [enrollUserId, setEnrollUserId] = createSignal(""); |
| 122 | const [error, setError] = createSignal(""); | 125 | const [error, setError] = createSignal(""); |
| 123 | const [pending, setPending] = createSignal(false); | 126 | const [pending, setPending] = createSignal(false); |
| @@ -559,6 +562,7 @@ function CourseDetailContent() { | |||
| 559 | </Show> | 562 | </Show> |
| 560 | <TabsTrigger value="subjects">{t("subjects.title")}</TabsTrigger> | 563 | <TabsTrigger value="subjects">{t("subjects.title")}</TabsTrigger> |
| 561 | <TabsTrigger value="exams">{t("courses.exams")}</TabsTrigger> | 564 | <TabsTrigger value="exams">{t("courses.exams")}</TabsTrigger> |
| 565 | + <TabsTrigger value="homework">{t("homework.title")}</TabsTrigger> | ||
| 562 | <TabsTrigger value="sessions">{t("sessions.title")}</TabsTrigger> | 566 | <TabsTrigger value="sessions">{t("sessions.title")}</TabsTrigger> |
| 563 | <Show when={hasCourseManagementRights()}> | 567 | <Show when={hasCourseManagementRights()}> |
| 564 | <TabsTrigger value="roster">{t("courses.roster")}</TabsTrigger> | 568 | <TabsTrigger value="roster">{t("courses.roster")}</TabsTrigger> |
| @@ -608,6 +612,19 @@ function CourseDetailContent() { | |||
| 608 | </Suspense> | 612 | </Suspense> |
| 609 | </TabsContent> | 613 | </TabsContent> |
| 610 | 614 | ||
| 615 | + <TabsContent value="homework" forceMount class="space-y-4"> | ||
| 616 | + <div class="tab-panel-header"> | ||
| 617 | + <p class="text-sm text-muted-foreground">{countDescription(homeworkCount(), t("homework.item"))}</p> | ||
| 618 | + <Show when={canManage()}> | ||
| 619 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowHomeworkForm(true)}> | ||
| 620 | + <IconPlus class="h-4 w-4" /> | ||
| 621 | + {t("homework.add")} | ||
| 622 | + </Button> | ||
| 623 | + </Show> | ||
| 624 | + </div> | ||
| 625 | + <CourseHomeworkPanel courseId={id()} canManage={canManage()} active={courseTab() === "homework"} createOpen={showHomeworkForm()} onCreateOpenChange={setShowHomeworkForm} onCountChange={setHomeworkCount} /> | ||
| 626 | + </TabsContent> | ||
| 627 | + | ||
| 611 | <TabsContent value="sessions" forceMount class="space-y-4"> | 628 | <TabsContent value="sessions" forceMount class="space-y-4"> |
| 612 | <div class="tab-panel-header"> | 629 | <div class="tab-panel-header"> |
| 613 | <p class="text-sm text-muted-foreground">{countDescription(sessionCount(), t("sessions.item"))}</p> | 630 | <p class="text-sm text-muted-foreground">{countDescription(sessionCount(), t("sessions.item"))}</p> |
src/pages/homework-page.tsxadded+241 -0
| @@ -0,0 +1,241 @@ | |||
| 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; | ||
| 2 | +import { useNavigate } from "@tanstack/solid-router"; | ||
| 3 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 4 | +import { getCourseById, getCourseSubjects, getCourses, postCourseHomework } from "@/api/courses"; | ||
| 5 | +import { getHomework } from "@/api/homework"; | ||
| 6 | +import { getSubjectById } from "@/api/subjects"; | ||
| 7 | +import { getTime } from "@/api/time"; | ||
| 8 | +import { formatApiError } from "@/api/client"; | ||
| 9 | +import type { Course, Homework } from "@/api/client"; | ||
| 10 | +import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 11 | +import { PageHeader } from "@/components/layout/page-header"; | ||
| 12 | +import { Alert } from "@/components/ui/alert"; | ||
| 13 | +import { Badge } from "@/components/ui/badge"; | ||
| 14 | +import { Button } from "@/components/ui/button"; | ||
| 15 | +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | ||
| 16 | +import { DatePicker } from "@/components/ui/date-picker"; | ||
| 17 | +import { IconPlus } from "@/components/ui/icons"; | ||
| 18 | +import { Input } from "@/components/ui/input"; | ||
| 19 | +import { Label } from "@/components/ui/label"; | ||
| 20 | +import { Select } from "@/components/ui/select"; | ||
| 21 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 22 | +import { Textarea } from "@/components/ui/textarea"; | ||
| 23 | +import { formatDateTime } from "@/lib/format"; | ||
| 24 | +import { hasMinRole } from "@/lib/roles"; | ||
| 25 | +import { useAuth } from "@/stores/auth-context"; | ||
| 26 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 27 | + | ||
| 28 | +function dateInputToMs(date: string, time: string): number | null { | ||
| 29 | + const dateMatch = date.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); | ||
| 30 | + const timeMatch = time.trim().match(/^(\d{2}):(\d{2})$/); | ||
| 31 | + if (!dateMatch || !timeMatch) return null; | ||
| 32 | + const [, dayRaw, monthRaw, yearRaw] = dateMatch; | ||
| 33 | + const [, hourRaw, minuteRaw] = timeMatch; | ||
| 34 | + const day = Number(dayRaw); | ||
| 35 | + const month = Number(monthRaw); | ||
| 36 | + const year = Number(yearRaw); | ||
| 37 | + const hour = Number(hourRaw); | ||
| 38 | + const minute = Number(minuteRaw); | ||
| 39 | + const d = new Date(year, month - 1, day, hour, minute, 0, 0); | ||
| 40 | + if (d.getFullYear() !== year || d.getMonth() !== month - 1 || d.getDate() !== day || d.getHours() !== hour || d.getMinutes() !== minute) return null; | ||
| 41 | + return d.getTime(); | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +export default function HomeworkPage() { | ||
| 45 | + return ( | ||
| 46 | + <RouteGuard> | ||
| 47 | + <HomeworkContent /> | ||
| 48 | + </RouteGuard> | ||
| 49 | + ); | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +function HomeworkContent() { | ||
| 53 | + const t = useT(); | ||
| 54 | + const auth = useAuth(); | ||
| 55 | + const { locale } = usePreferences(); | ||
| 56 | + const navigate = useNavigate(); | ||
| 57 | + const [createOpen, setCreateOpen] = createSignal(false); | ||
| 58 | + const [selectedCourseId, setSelectedCourseId] = createSignal(""); | ||
| 59 | + const [title, setTitle] = createSignal(""); | ||
| 60 | + const [description, setDescription] = createSignal(""); | ||
| 61 | + const [subjectId, setSubjectId] = createSignal(""); | ||
| 62 | + const [dueDate, setDueDate] = createSignal(""); | ||
| 63 | + const [dueTime, setDueTime] = createSignal(""); | ||
| 64 | + const [error, setError] = createSignal(""); | ||
| 65 | + const [pending, setPending] = createSignal(false); | ||
| 66 | + const [courseNames, setCourseNames] = createSignal<Record<string, string>>({}); | ||
| 67 | + const [subjectNames, setSubjectNames] = createSignal<Record<string, string>>({}); | ||
| 68 | + const [list, { refetch }] = createResource(async () => { | ||
| 69 | + const items = (await getHomework({ limit: 100 })).items; | ||
| 70 | + const courses = [...new Set(items.map((item) => item.course))]; | ||
| 71 | + const subjects = [...new Set(items.map((item) => item.subject))]; | ||
| 72 | + await Promise.all(courses.map((id) => getCourseById(id).then((course) => setCourseNames((current) => ({ ...current, [id]: course.title }))).catch(() => {}))); | ||
| 73 | + await Promise.all(subjects.map((id) => getSubjectById(id).then((subject) => setSubjectNames((current) => ({ ...current, [id]: subject.name }))).catch(() => {}))); | ||
| 74 | + return items; | ||
| 75 | + }); | ||
| 76 | + const [courses] = createResource( | ||
| 77 | + () => (hasMinRole(auth.user()?.role, "teacher") ? true : null), | ||
| 78 | + async (enabled) => (enabled ? (await getCourses({ limit: 100 })).items : []), | ||
| 79 | + ); | ||
| 80 | + const manageableCourses = createMemo(() => (courses() ?? []).filter((course: Course) => { | ||
| 81 | + const user = auth.user(); | ||
| 82 | + if (!user) return false; | ||
| 83 | + return course.creator.id === user.id || (course.teachers ?? []).some((teacher) => teacher.id === user.id) || hasMinRole(user.role, "manager"); | ||
| 84 | + })); | ||
| 85 | + const [subjects] = createResource( | ||
| 86 | + () => selectedCourseId() || null, | ||
| 87 | + async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), | ||
| 88 | + ); | ||
| 89 | + const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | ||
| 90 | + const courseName = (id: string) => courseNames()[id] ?? id; | ||
| 91 | + const subjectName = (id: string) => subjectNames()[id] ?? id; | ||
| 92 | + const canCreate = () => manageableCourses().length > 0; | ||
| 93 | + | ||
| 94 | + createEffect(() => { | ||
| 95 | + if (!createOpen()) return; | ||
| 96 | + if (!selectedCourseId()) setSelectedCourseId(manageableCourses()[0]?.id ?? ""); | ||
| 97 | + }); | ||
| 98 | + | ||
| 99 | + createEffect(() => { | ||
| 100 | + setSubjectId(subjects()?.[0]?.id ?? ""); | ||
| 101 | + }); | ||
| 102 | + | ||
| 103 | + const resetForm = () => { | ||
| 104 | + setTitle(""); | ||
| 105 | + setDescription(""); | ||
| 106 | + setSelectedCourseId(manageableCourses()[0]?.id ?? ""); | ||
| 107 | + setSubjectId(""); | ||
| 108 | + setDueDate(""); | ||
| 109 | + setDueTime(""); | ||
| 110 | + setError(""); | ||
| 111 | + }; | ||
| 112 | + | ||
| 113 | + const save = async (event: SubmitEvent) => { | ||
| 114 | + event.preventDefault(); | ||
| 115 | + setError(""); | ||
| 116 | + const due_at = dateInputToMs(dueDate(), dueTime()); | ||
| 117 | + if (!selectedCourseId()) return setError(t("exams.missingCourse")); | ||
| 118 | + if (!subjectId()) return setError(t("subjects.select")); | ||
| 119 | + if (due_at == null) return setError(t("homework.dueRequired")); | ||
| 120 | + if (due_at < (serverTime()?.now ?? Date.now())) return setError(t("form.timePast")); | ||
| 121 | + setPending(true); | ||
| 122 | + try { | ||
| 123 | + await postCourseHomework(selectedCourseId(), { | ||
| 124 | + title: title().trim(), | ||
| 125 | + description: description().trim() || null, | ||
| 126 | + subject_id: subjectId(), | ||
| 127 | + due_at, | ||
| 128 | + }); | ||
| 129 | + resetForm(); | ||
| 130 | + setCreateOpen(false); | ||
| 131 | + await refetch(); | ||
| 132 | + } catch (err) { | ||
| 133 | + setError(formatApiError(err)); | ||
| 134 | + } finally { | ||
| 135 | + setPending(false); | ||
| 136 | + } | ||
| 137 | + }; | ||
| 138 | + const columns = createMemo<ColumnDef<Homework>[]>(() => [ | ||
| 139 | + { | ||
| 140 | + accessorKey: "title", | ||
| 141 | + header: t("form.title"), | ||
| 142 | + meta: { cellClass: "font-medium" }, | ||
| 143 | + cell: (cell) => ( | ||
| 144 | + <div class="min-w-0"> | ||
| 145 | + <p class="truncate font-medium">{cell.row.original.title}</p> | ||
| 146 | + <p class="truncate text-xs text-muted-foreground">{cell.row.original.description || "—"}</p> | ||
| 147 | + </div> | ||
| 148 | + ), | ||
| 149 | + }, | ||
| 150 | + { | ||
| 151 | + id: "course", | ||
| 152 | + accessorFn: (row) => courseName(row.course), | ||
| 153 | + header: t("nav.courses"), | ||
| 154 | + meta: { cellClass: "text-muted-foreground" }, | ||
| 155 | + cell: (cell) => courseName(cell.row.original.course), | ||
| 156 | + }, | ||
| 157 | + { | ||
| 158 | + id: "subject", | ||
| 159 | + accessorFn: (row) => subjectName(row.subject), | ||
| 160 | + header: t("subjects.subject"), | ||
| 161 | + cell: (cell) => <Badge variant="outline" class="rounded-full">{subjectName(cell.row.original.subject)}</Badge>, | ||
| 162 | + }, | ||
| 163 | + { | ||
| 164 | + id: "due_at", | ||
| 165 | + accessorFn: (row) => row.due_at, | ||
| 166 | + header: t("homework.dueAt"), | ||
| 167 | + meta: { cellClass: "mono whitespace-nowrap text-muted-foreground" }, | ||
| 168 | + cell: (cell) => formatDateTime(cell.row.original.due_at, locale()), | ||
| 169 | + }, | ||
| 170 | + { | ||
| 171 | + id: "assigned", | ||
| 172 | + accessorFn: (row) => row.assigned?.length ?? 0, | ||
| 173 | + header: t("homework.assigned"), | ||
| 174 | + cell: (cell) => cell.row.original.assigned?.length ? t("common.countItem", { count: cell.row.original.assigned.length, item: t("courses.rosterItem") }) : t("homework.wholeCourse"), | ||
| 175 | + }, | ||
| 176 | + ]); | ||
| 177 | + | ||
| 178 | + return ( | ||
| 179 | + <div class="space-y-6"> | ||
| 180 | + <PageHeader | ||
| 181 | + accent="amber" | ||
| 182 | + eyebrow={t("nav.group.classes")} | ||
| 183 | + title={t("homework.title")} | ||
| 184 | + description={t("homework.listHelp")} | ||
| 185 | + actions={ | ||
| 186 | + <Show when={canCreate()}> | ||
| 187 | + <Button type="button" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => setCreateOpen(true)}> | ||
| 188 | + <IconPlus class="h-4 w-4" /> | ||
| 189 | + {t("homework.add")} | ||
| 190 | + </Button> | ||
| 191 | + </Show> | ||
| 192 | + } | ||
| 193 | + /> | ||
| 194 | + <SidePanel open={createOpen()} onOpenChange={(open) => { setCreateOpen(open); if (!open) resetForm(); }} title={t("homework.add")} description={t("homework.help")}> | ||
| 195 | + <form class="space-y-4" onSubmit={(event) => void save(event)}> | ||
| 196 | + <Show when={error()}> | ||
| 197 | + <Alert variant="destructive">{error()}</Alert> | ||
| 198 | + </Show> | ||
| 199 | + <div class="space-y-1.5"> | ||
| 200 | + <Label for="homework-course">{t("nav.courses")}</Label> | ||
| 201 | + <Select id="homework-course" required value={selectedCourseId()} onChange={(event) => setSelectedCourseId(event.currentTarget.value)}> | ||
| 202 | + <For each={manageableCourses()}>{(course) => <option value={course.id}>{course.title}</option>}</For> | ||
| 203 | + </Select> | ||
| 204 | + </div> | ||
| 205 | + <div class="space-y-1.5"> | ||
| 206 | + <Label for="homework-subject-global">{t("subjects.subject")}</Label> | ||
| 207 | + <Select id="homework-subject-global" required value={subjectId()} onChange={(event) => setSubjectId(event.currentTarget.value)}> | ||
| 208 | + <For each={subjects() ?? []}>{(subject) => <option value={subject.id}>{subject.name}</option>}</For> | ||
| 209 | + </Select> | ||
| 210 | + </div> | ||
| 211 | + <div class="space-y-1.5"> | ||
| 212 | + <Label for="homework-title-global">{t("form.title")}</Label> | ||
| 213 | + <Input id="homework-title-global" required maxlength={200} value={title()} onInput={(event) => setTitle(event.currentTarget.value)} /> | ||
| 214 | + </div> | ||
| 215 | + <div class="space-y-1.5"> | ||
| 216 | + <Label for="homework-description-global">{t("form.description")}</Label> | ||
| 217 | + <Textarea id="homework-description-global" maxlength={2000} rows={3} value={description()} onInput={(event) => setDescription(event.currentTarget.value)} /> | ||
| 218 | + </div> | ||
| 219 | + <div class="space-y-1.5"> | ||
| 220 | + <Label for="homework-due-global">{t("homework.dueAt")}</Label> | ||
| 221 | + <div class="grid grid-cols-2 gap-2"> | ||
| 222 | + <DatePicker id="homework-due-global" class="h-10" placeholder={t("form.datePlaceholder")} value={dueDate()} required onChange={setDueDate} /> | ||
| 223 | + <Input class="h-10 rounded-sm font-mono placeholder:text-muted-foreground/35" placeholder="17:00" value={dueTime()} required onInput={(event) => setDueTime(event.currentTarget.value)} /> | ||
| 224 | + </div> | ||
| 225 | + </div> | ||
| 226 | + <p class="rounded-xl border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">{t("homework.wholeCourseHelp")}</p> | ||
| 227 | + <div class="flex flex-wrap gap-2"> | ||
| 228 | + <Button type="submit" class="rounded-xl" disabled={pending()}>{t("common.create")}</Button> | ||
| 229 | + <Button type="button" variant="outline" class="rounded-xl" onClick={() => setCreateOpen(false)}>{t("common.cancel")}</Button> | ||
| 230 | + </div> | ||
| 231 | + </form> | ||
| 232 | + </SidePanel> | ||
| 233 | + <Suspense fallback={<DataTableSkeleton />}> | ||
| 234 | + <Show when={list.error}> | ||
| 235 | + <Alert variant="destructive">{formatApiError(list.error)}</Alert> | ||
| 236 | + </Show> | ||
| 237 | + <DataTable columns={columns()} data={list() ?? []} filterColumn="title" enablePagination pageSize={12} empty={t("homework.empty")} onRowClick={(item) => void navigate({ to: "/courses/$id", params: { id: item.course } })} /> | ||
| 238 | + </Suspense> | ||
| 239 | + </div> | ||
| 240 | + ); | ||
| 241 | +} | ||
src/routes/router.tsxmodified+8 -0
| @@ -27,6 +27,7 @@ const DashboardPage = lazyRoute(() => import("@/pages/dashboard-page")); | |||
| 27 | const NotesPage = lazyRoute(() => import("@/pages/notes-page")); | 27 | const NotesPage = lazyRoute(() => import("@/pages/notes-page")); |
| 28 | const EventsPage = lazyRoute(() => import("@/pages/events-page")); | 28 | const EventsPage = lazyRoute(() => import("@/pages/events-page")); |
| 29 | const EventDetailPage = lazyRoute(() => import("@/pages/event-detail-page")); | 29 | const EventDetailPage = lazyRoute(() => import("@/pages/event-detail-page")); |
| 30 | +const HomeworkPage = lazyRoute(() => import("@/pages/homework-page")); | ||
| 30 | const ExamsPage = lazyRoute(() => import("@/pages/exams-page")); | 31 | const ExamsPage = lazyRoute(() => import("@/pages/exams-page")); |
| 31 | const ExamDetailPage = lazyRoute(() => import("@/pages/exam-detail-page")); | 32 | const ExamDetailPage = lazyRoute(() => import("@/pages/exam-detail-page")); |
| 32 | const ExamRoomPage = lazyRoute(() => import("@/pages/exam-room-page")); | 33 | const ExamRoomPage = lazyRoute(() => import("@/pages/exam-room-page")); |
| @@ -117,6 +118,12 @@ const examsRoute = createRoute({ | |||
| 117 | component: ExamsPage, | 118 | component: ExamsPage, |
| 118 | }); | 119 | }); |
| 119 | 120 | ||
| 121 | +const homeworkRoute = createRoute({ | ||
| 122 | + getParentRoute: () => rootRoute, | ||
| 123 | + path: "/homework", | ||
| 124 | + component: HomeworkPage, | ||
| 125 | +}); | ||
| 126 | + | ||
| 120 | const examDetailRoute = createRoute({ | 127 | const examDetailRoute = createRoute({ |
| 121 | getParentRoute: () => rootRoute, | 128 | getParentRoute: () => rootRoute, |
| 122 | path: "/exams/$id", | 129 | path: "/exams/$id", |
| @@ -268,6 +275,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 268 | notesRoute, | 275 | notesRoute, |
| 269 | eventsRoute, | 276 | eventsRoute, |
| 270 | eventDetailRoute, | 277 | eventDetailRoute, |
| 278 | + homeworkRoute, | ||
| 271 | examDetailRoute, | 279 | examDetailRoute, |
| 272 | examRoomRoute, | 280 | examRoomRoute, |
| 273 | liveMonitorRoute, | 281 | liveMonitorRoute, |