From 165e1dc11a95dfb3fc2e7d48ce92d7a7f1a7a160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 22 Jul 2026 23:35:32 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20homework=20navigation?= =?UTF-8?q?=20and=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add sidebar homework route with dedicated icon and route label - add course detail homework tab with list and create actions - add global homework page with create side panel and localized copy - document page header button sizing rules --- AGENTS.md | 2 +- docs/navigation-patterns.md | 2 +- docs/ui-redesign-tokens.md | 1 + .../homework/course-homework-panel.tsx | 273 ++++++++++++++++++ src/components/layout/app-shell.tsx | 1 + src/components/layout/side-nav.tsx | 2 + src/components/ui/icons.tsx | 12 + src/i18n/messages.ts | 39 +++ src/pages/course-detail-page.tsx | 17 ++ src/pages/homework-page.tsx | 241 ++++++++++++++++ src/routes/router.tsx | 8 + 11 files changed, 596 insertions(+), 2 deletions(-) create mode 100644 src/components/homework/course-homework-panel.tsx create mode 100644 src/pages/homework-page.tsx diff --git a/AGENTS.md b/AGENTS.md index 7b40412..6388aee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -90,7 +90,7 @@ Solid components run **once**, there is no re-render: - `docs/role-scope-matrix.md` — role access matrix for pages/nav/dashboard cards. - `docs/backend-ui-alignment-plan.md` — completed backend-alignment archive; do not treat it as active work unless backend scope changes. - Durable resources use full detail pages. Short create/edit/filter work uses `SidePanel`. Destructive actions use confirm dialogs. -- 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. +- 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. - 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"`. - Pages/domain components must not import or render `Table` primitives directly; only the `DataTable` wrapper and table primitive files may do that. - **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. diff --git a/docs/navigation-patterns.md b/docs/navigation-patterns.md index 932a180..e602535 100644 --- a/docs/navigation-patterns.md +++ b/docs/navigation-patterns.md @@ -60,7 +60,7 @@ Table action rules: Delete or destructive confirmation stays in a confirm dialog, not a side panel. -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). +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. - 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. 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. diff --git a/docs/ui-redesign-tokens.md b/docs/ui-redesign-tokens.md index e12f08c..2d595bc 100644 --- a/docs/ui-redesign-tokens.md +++ b/docs/ui-redesign-tokens.md @@ -139,6 +139,7 @@ Reference implementation: `src/pages/dashboard-page.tsx`. ## Current Implementation Notes - Data-heavy admin and management views should prefer `DataToolbar`, `DataTableFrame`, and `.data-table`. +- 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"`. - Row-level table actions should use `TableRowActions`; avoid inline action button clusters in table rows. - Quick create/edit flows should use `SidePanel`; destructive actions stay in confirm dialogs. - Durable resources keep full detail pages with breadcrumbs. diff --git a/src/components/homework/course-homework-panel.tsx b/src/components/homework/course-homework-panel.tsx new file mode 100644 index 0000000..8d687ec --- /dev/null +++ b/src/components/homework/course-homework-panel.tsx @@ -0,0 +1,273 @@ +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; +import type { ColumnDef } from "@tanstack/solid-table"; +import { deleteHomeworkById, patchHomeworkById } from "@/api/homework"; +import { getCourseHomework, getCourseSubjects, postCourseHomework } from "@/api/courses"; +import { getTime } from "@/api/time"; +import { formatApiError } from "@/api/client"; +import type { Homework, Subject } from "@/api/client"; +import { Alert } from "@/components/ui/alert"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { DataTable } from "@/components/ui/data-table"; +import { DatePicker } from "@/components/ui/date-picker"; +import { EmptyState } from "@/components/ui/empty-state"; +import { IconEdit, IconTrash } from "@/components/ui/icons"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { PageSpinner } from "@/components/ui/page-spinner"; +import { Select } from "@/components/ui/select"; +import { SidePanel } from "@/components/ui/side-panel"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { Textarea } from "@/components/ui/textarea"; +import { createFlash } from "@/lib/flash"; +import { formatDateTime } from "@/lib/format"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +function dateInputToMs(date: string, time: string): number | null { + const dateMatch = date.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); + const timeMatch = time.trim().match(/^(\d{2}):(\d{2})$/); + if (!dateMatch || !timeMatch) return null; + const [, dayRaw, monthRaw, yearRaw] = dateMatch; + const [, hourRaw, minuteRaw] = timeMatch; + const day = Number(dayRaw); + const month = Number(monthRaw); + const year = Number(yearRaw); + const hour = Number(hourRaw); + const minute = Number(minuteRaw); + const d = new Date(year, month - 1, day, hour, minute, 0, 0); + if (d.getFullYear() !== year || d.getMonth() !== month - 1 || d.getDate() !== day || d.getHours() !== hour || d.getMinutes() !== minute) return null; + return d.getTime(); +} + +function msToDateInput(ms: number): string { + const d = new Date(ms); + const pad = (n: number) => String(n).padStart(2, "0"); + return `${pad(d.getDate())}/${pad(d.getMonth() + 1)}/${d.getFullYear()}`; +} + +function msToTimeInput(ms: number): string { + const d = new Date(ms); + const pad = (n: number) => String(n).padStart(2, "0"); + return `${pad(d.getHours())}:${pad(d.getMinutes())}`; +} + +export function CourseHomeworkPanel(props: { + courseId: string; + canManage: boolean; + active: boolean; + createOpen: boolean; + onCreateOpenChange: (open: boolean) => void; + onCountChange: (count: number) => void; +}) { + const t = useT(); + const { locale } = usePreferences(); + const [homework, { refetch }] = createResource( + () => (props.active ? props.courseId : null), + async (courseId) => (courseId ? (await getCourseHomework(courseId)).items : []), + ); + const [subjects] = createResource( + () => (props.active ? props.courseId : null), + async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), + ); + const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); + const [editing, setEditing] = createSignal(null); + const [deleteTarget, setDeleteTarget] = createSignal(null); + const [title, setTitle] = createSignal(""); + const [description, setDescription] = createSignal(""); + const [subjectId, setSubjectId] = createSignal(""); + const [dueDate, setDueDate] = createSignal(""); + const [dueTime, setDueTime] = createSignal(""); + const [error, setError] = createSignal(""); + const [pending, setPending] = createSignal(false); + const [flash, setFlash] = createFlash(); + + const subjectName = (id: string) => subjects()?.find((subject) => subject.id === id)?.name ?? id; + const resetForm = () => { + setEditing(null); + setTitle(""); + setDescription(""); + setSubjectId(subjects()?.[0]?.id ?? ""); + setDueDate(""); + setDueTime(""); + setError(""); + }; + const openEdit = (item: Homework) => { + setEditing(item); + setTitle(item.title); + setDescription(item.description ?? ""); + setSubjectId(item.subject); + setDueDate(msToDateInput(item.due_at)); + setDueTime(msToTimeInput(item.due_at)); + setError(""); + props.onCreateOpenChange(true); + }; + const setPanelOpen = (open: boolean) => { + props.onCreateOpenChange(open); + if (!open) resetForm(); + }; + + createEffect(() => props.onCountChange(homework()?.length ?? 0)); + createEffect(() => { + if (!subjectId()) setSubjectId(subjects()?.[0]?.id ?? ""); + }); + + const save = async (event: SubmitEvent) => { + event.preventDefault(); + setError(""); + const due_at = dateInputToMs(dueDate(), dueTime()); + if (due_at == null) { + setError(t("homework.dueRequired")); + return; + } + const current = editing(); + if ((!current || due_at !== current.due_at) && due_at < (serverTime()?.now ?? Date.now())) { + setError(t("form.timePast")); + return; + } + setPending(true); + try { + if (current) { + await patchHomeworkById(current.id, { + title: title().trim(), + description: description().trim() || null, + subject_id: subjectId(), + due_at, + }); + setFlash(t("common.saved")); + } else { + await postCourseHomework(props.courseId, { + title: title().trim(), + description: description().trim() || null, + subject_id: subjectId(), + due_at, + }); + setFlash(t("common.created")); + } + setPanelOpen(false); + await refetch(); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + const columns = createMemo[]>(() => [ + { + accessorKey: "title", + header: t("form.title"), + meta: { cellClass: "font-medium" }, + }, + { + id: "subject", + accessorFn: (row) => subjectName(row.subject), + header: t("subjects.subject"), + cell: (cell) => {subjectName(cell.row.original.subject)}, + }, + { + id: "due_at", + accessorFn: (row) => row.due_at, + header: t("homework.dueAt"), + meta: { cellClass: "mono text-xs text-muted-foreground" }, + cell: (cell) => formatDateTime(cell.row.original.due_at, locale()), + }, + { + id: "assigned", + accessorFn: (row) => row.assigned?.length ?? 0, + header: t("homework.assigned"), + cell: (cell) => cell.row.original.assigned?.length ? t("common.countItem", { count: cell.row.original.assigned.length, item: t("courses.rosterItem") }) : t("homework.wholeCourse"), + }, + ...(props.canManage + ? [{ + id: "actions", + header: t("common.actions"), + meta: { headerClass: "w-28 min-w-[7rem] text-center whitespace-nowrap", cellClass: "px-1 text-center" }, + cell: (cell) => ( + , onSelect: () => openEdit(cell.row.original) }, + { label: t("common.delete"), icon: , destructive: true, onSelect: () => setDeleteTarget(cell.row.original) }, + ]} + /> + ), + } satisfies ColumnDef] + : []), + ]); + + return ( +
+ + {flash()} + + + {error()} + + + }> + 0} fallback={}> + + + + + +
void save(event)}> + + {error()} + +
+ + setTitle(event.currentTarget.value)} /> +
+
+ + +
+
+ +