diff --git a/src/components/attendance/attendance-report-view.tsx b/src/components/attendance/attendance-report-view.tsx index 9184b6a..bf386f3 100644 --- a/src/components/attendance/attendance-report-view.tsx +++ b/src/components/attendance/attendance-report-view.tsx @@ -17,100 +17,122 @@ function customEntries(counts: AttendanceCounts) { return Object.entries(counts.custom ?? {}).filter(([, count]) => count > 0); } -function CountsCard(props: { title: string; counts: AttendanceCounts }) { +function CountsCard(props: { title: string; counts: AttendanceCounts; compact?: boolean }) { const t = useT(); return ( -
+
-

{props.title}

- {percent(props.counts.rate)} +

{props.title}

+ + {percent(props.counts.rate)} +
-
+
- {(status) => } + {(status) => ( + + )}
- - + +
0}> -
- {([label, count]) => {label}: {count}} +
+ + {([label, count]) => ( + + {label}: {count} + + )} +
); } -function Stat(props: { label: string; value: string | number }) { +function Stat(props: { label: string; value: string | number; compact?: boolean }) { return ( -
-
{props.label}
-
{props.value}
+
+
{props.label}
+
{props.value}
); } -function StatusStat(props: { label: string; detail: string; value: number; class: string }) { +function StatusStat(props: { label: string; detail?: string; value: number; class: string; compact?: boolean }) { return ( -
-
- {props.label} - {props.detail} +
+
+ {props.label} + + +
-
{props.value}
+
{props.value}
); } -export function AttendanceReportView(props: { report: AttendanceReport }) { +export function AttendanceReportView(props: { report: AttendanceReport; compact?: boolean }) { const t = useT(); + const compact = () => props.compact === true; + return ( -
-
- - +
+
+ +
-
-

{t("attendance.courseBreakdown")}

+
+

{t("attendance.courseBreakdown")}

0} - fallback={{t("attendance.emptyCourses")}} + fallback={{t("attendance.emptyCourses")}} > - - - - - - - - - - - + +
{t("nav.courses")} - {(status) => {t(status.key)}} + {(status) => ( + + {compact() ? t(status.key).slice(0, 1) : t(status.key)} + + )} - {t("common.all")} - {t("attendance.rate")} + {compact() ? "Σ" : t("common.all")} + % {(block) => ( - - {block.course.title} + + + {block.course.title} + {(status) => ( - + {block.counts[status.value]} diff --git a/src/components/marks/marks-report-view.tsx b/src/components/marks/marks-report-view.tsx index 9702e53..2bd05e0 100644 --- a/src/components/marks/marks-report-view.tsx +++ b/src/components/marks/marks-report-view.tsx @@ -6,6 +6,7 @@ import { Badge } from "@/components/ui/badge"; import { DataTableEmpty, DataTableFrame } from "@/components/ui/data-table"; import { ExamLink } from "@/components/exams/exam-link"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { cn } from "@/lib/cn"; import { examKindLabel } from "@/lib/exam-labels"; import { examWeight } from "@/lib/exam-weight"; import { useT } from "@/stores/preferences-context"; @@ -17,59 +18,67 @@ function markWithGrade(mark: number | null, grade?: string | null) { return grade ? `${round(mark)} / ${grade}` : round(mark); } -export function MarksReportView(props: { report: MarksReport }) { +export function MarksReportView(props: { report: MarksReport; compact?: boolean }) { const t = useT(); const [settings] = createResource(() => getSettings()); + const compact = () => props.compact === true; + return ( - 0} - fallback={ - {t("marks.empty")} - } - > -
-
- {t("marks.overall")} -

+ 0} fallback={{t("marks.empty")}}> +

+
+ {t("marks.overall")} +

{markWithGrade(props.report.overall_average, props.report.overall_grade)} - / 100 + / 100

{(block) => ( -
-
-

- +
+
+

+ {block.course.title}

- + {markWithGrade(block.average, block.average_grade)}
- 0} - fallback={ - {t("exams.noResults")} - } - > - -

- - - - - - + 0} fallback={{t("exams.noResults")}}> + +
+ + + + + + + + {t("marks.exam")} - {t("exams.kind")} + {t("exams.kind")} {t("marks.weight")} {t("marks.mark")} @@ -78,12 +87,17 @@ export function MarksReportView(props: { report: MarksReport }) { {(entry) => ( - - + + {entry.title} + +

+ {examKindLabel(entry.kind, t)} +

+
- + {examKindLabel(entry.kind, t)} diff --git a/src/components/ui/side-panel.tsx b/src/components/ui/side-panel.tsx index c63c62b..fae0963 100644 --- a/src/components/ui/side-panel.tsx +++ b/src/components/ui/side-panel.tsx @@ -3,30 +3,42 @@ import type { ParentProps } from "solid-js"; import { IconX } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; -export function SidePanel(props: ParentProps<{ - open: boolean; - onOpenChange: (open: boolean) => void; - title: string; - description?: string; - class?: string; -}>) { +export function SidePanel( + props: ParentProps<{ + open: boolean; + onOpenChange: (open: boolean) => void; + title: string; + description?: string; + class?: string; + /** default ~34rem, wide ~42rem, xl ~48rem — for report tables */ + size?: "default" | "wide" | "xl"; + }>, +) { + const width = () => { + if (props.size === "xl") return "max-w-[min(48rem,100vw)]"; + if (props.size === "wide") return "max-w-[min(42rem,100vw)]"; + return "max-w-[min(34rem,100vw)]"; + }; + return ( -
-
+
+
{props.title} {props.description && ( - + {props.description} )} @@ -35,7 +47,9 @@ export function SidePanel(props: ParentProps<{
-
{props.children}
+
+ {props.children} +
diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 5af40b1..89fbb90 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -496,7 +496,9 @@ export type MessageKey = | "work.timesRequired" | "work.deleteSummary" | "work.teacherIdentity" - | "work.noTeachers"; + | "work.noTeachers" + | "lookup.searchHint" + | "work.userNotFound"; type Dict = Record; @@ -1003,6 +1005,8 @@ const en: Dict = { "work.staffSubtitle": "Look up a teacher, correct closed stints, or delete entries.", "work.teacherIdentity": "Teacher", "work.noTeachers": "No teachers found.", + "lookup.searchHint": "Type at least 2 characters to search.", + "work.userNotFound": "No work log found for this user.", "work.show": "Show log", "work.forUser": "Log for {user}", "work.correct": "Correct entry", @@ -1515,6 +1519,8 @@ const tr: Dict = { "work.staffSubtitle": "Öğretmen ara, kapalı mesaileri düzelt veya kayıt sil.", "work.teacherIdentity": "Öğretmen", "work.noTeachers": "Öğretmen bulunamadı.", + "lookup.searchHint": "Aramak için en az 2 karakter yaz.", + "work.userNotFound": "Bu kullanıcı için mesai kaydı bulunamadı.", "work.show": "Kaydı göster", "work.forUser": "{user} için kayıtlar", "work.correct": "Kaydı düzelt", diff --git a/src/lib/debounced.ts b/src/lib/debounced.ts new file mode 100644 index 0000000..201e117 --- /dev/null +++ b/src/lib/debounced.ts @@ -0,0 +1,12 @@ +import { createEffect, createSignal, onCleanup, type Accessor } from "solid-js"; + +/** Debounce an accessor value; useful for search inputs. */ +export function createDebounced(source: Accessor, ms = 300): Accessor { + const [value, setValue] = createSignal(source()); + createEffect(() => { + const next = source(); + const timer = window.setTimeout(() => setValue(() => next), ms); + onCleanup(() => window.clearTimeout(timer)); + }); + return value; +} diff --git a/src/pages/staff-work-page.tsx b/src/pages/staff-work-page.tsx index 2d4f2a7..59e2a33 100644 --- a/src/pages/staff-work-page.tsx +++ b/src/pages/staff-work-page.tsx @@ -1,33 +1,36 @@ -import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; +import { For, Show, createMemo, createResource, createSignal } from "solid-js"; import { deleteWorkEntryById } from "@/api/deleteWorkEntryById"; +import { getUserSearch } from "@/api/getUserSearch"; import { getUserWorkLog } from "@/api/getUserWorkLog"; import { patchWorkEntryById } from "@/api/patchWorkEntryById"; -import { formatApiError } from "@/api/client"; +import { ApiError, formatApiError } from "@/api/client"; +import type { Page } from "@/api/page"; import type { PersonRef, WorkEntry } from "@/api/types"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; -import { UserSearchSelect } from "@/components/users/user-search-select"; 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 { DataTableFrame } from "@/components/ui/data-table"; +import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { DataToolbar } from "@/components/ui/data-toolbar"; import { DatePicker } from "@/components/ui/date-picker"; -import { ErrorAlert } from "@/components/ui/error-alert"; -import { IconEdit, IconTrash } from "@/components/ui/icons"; +import { IconEdit, IconEye, 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 { PaginationControls } from "@/components/ui/pagination-controls"; import { SidePanel } from "@/components/ui/side-panel"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { TableRowActions } from "@/components/ui/table-row-actions"; +import { createDebounced } from "@/lib/debounced"; import { formatDateTime, formatDurationMinutes } from "@/lib/format"; import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; import { personLabel } from "@/lib/person"; import { usePreferences, useT } from "@/stores/preferences-context"; +const PEOPLE_PAGE_SIZE = 12; const WORK_PAGE_SIZE = 15; +const MIN_QUERY = 2; function msToDateInput(ms: number): string { const d = new Date(ms); @@ -57,6 +60,9 @@ function dateInputToMs(date: string, time: string): number | null { return d.getTime(); } +const emptyPeople: Page = { items: [], total: 0, limit: null, offset: 0 }; +const emptyEntries = { items: [] as WorkEntry[], total: 0 }; + export default function StaffWorkPage() { return ( @@ -68,11 +74,11 @@ export default function StaffWorkPage() { function StaffWorkContent() { const t = useT(); const { locale } = usePreferences(); - const [userId, setUserId] = createSignal(""); - const [selectedUser, setSelectedUser] = createSignal(null); - const [lookupId, setLookupId] = createSignal(null); - const [lookupLabel, setLookupLabel] = createSignal(""); + const [query, setQuery] = createSignal(""); + const debouncedQuery = createDebounced(query, 300); const [page, setPage] = createSignal(0); + const [viewUser, setViewUser] = createSignal(null); + const [entryPage, setEntryPage] = createSignal(0); const [error, setError] = createSignal(""); const [editTarget, setEditTarget] = createSignal(null); const [deleteTarget, setDeleteTarget] = createSignal(null); @@ -82,24 +88,70 @@ function StaffWorkContent() { const [checkOutTime, setCheckOutTime] = createSignal(""); const [pending, setPending] = createSignal(false); - const [list, { refetch }] = createResource( - () => (lookupId() ? `${lookupId()}|${page()}` : null), + const searchKey = createMemo(() => { + const q = debouncedQuery().trim(); + if (q.length < MIN_QUERY) return null; + return `${q}|${page()}`; + }); + + // initialValue prevents Suspense remount of the page (which steals input focus). + const [people] = createResource( + searchKey, + async (key) => { + try { + const q = key.split("|")[0]!; + return await getUserSearch(q, undefined, "teacher", { + limit: PEOPLE_PAGE_SIZE, + offset: page() * PEOPLE_PAGE_SIZE, + }); + } catch (err) { + setError(formatApiError(err)); + return emptyPeople; + } + }, + { initialValue: emptyPeople }, + ); + + const [entries, { refetch: refetchEntries }] = createResource( + () => { + const user = viewUser(); + if (!user) return null; + return `${user.id}|${entryPage()}`; + }, async (key) => { - if (!key) return { items: [] as WorkEntry[], total: 0 }; - const id = key.split("|")[0]!; - return loadListPage({ - page: page(), - pageSize: WORK_PAGE_SIZE, - clientMode: false, - fetch: (params) => getUserWorkLog(id, params), - }); + try { + const id = key.split("|")[0]!; + return await loadListPage({ + page: entryPage(), + pageSize: WORK_PAGE_SIZE, + clientMode: false, + fetch: (params) => getUserWorkLog(id, params), + }); + } catch (err) { + if (err instanceof ApiError && err.status === 404) { + setError(t("work.userNotFound")); + return emptyEntries; + } + setError(formatApiError(err)); + return emptyEntries; + } }, + { initialValue: emptyEntries }, ); - const total = () => list()?.total ?? 0; - const pageItems = () => list()?.items ?? []; - const totalPages = createMemo(() => pagesOf(total(), WORK_PAGE_SIZE)); - const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); + const peopleTotal = () => people().total; + const peopleRows = () => people().items; + const peoplePages = createMemo(() => pagesOf(peopleTotal(), PEOPLE_PAGE_SIZE)); + const safePeoplePage = createMemo(() => Math.min(page(), peoplePages() - 1)); + + const entryTotal = () => entries().total; + const entryRows = () => entries().items; + const entryPages = createMemo(() => pagesOf(entryTotal(), WORK_PAGE_SIZE)); + const safeEntryPage = createMemo(() => Math.min(entryPage(), entryPages() - 1)); + + const canSearch = () => debouncedQuery().trim().length >= MIN_QUERY; + const hasPeople = () => peopleRows().length > 0; + const peopleLoading = () => canSearch() && people.loading; const startEdit = (entry: WorkEntry) => { if (entry.check_out == null) { @@ -133,7 +185,7 @@ function StaffWorkContent() { try { await patchWorkEntryById(entry.id, { check_in, check_out }); setEditTarget(null); - await refetch(); + await refetchEntries(); } catch (err) { setError(formatApiError(err)); } finally { @@ -153,57 +205,102 @@ function StaffWorkContent() {
-
{ - e.preventDefault(); - const id = userId().trim(); - if (!id) return; - setLookupId(id); - setLookupLabel(personLabel(selectedUser()) === "—" ? id : personLabel(selectedUser())); +
+
+

{t("work.teacherIdentity")}

+

+ {canSearch() ? `${peopleRows().length} / ${peopleTotal()}` : t("lookup.searchHint")} +

+
+
+ + { + setError(""); + setQuery(value); setPage(0); }} - > - - - - + /> + + {error()} -
- -
-
-
-

{t("work.entries")}

-

{t("work.forUser", { user: lookupLabel() || lookupId() || "" })}

-
- - {total()} - -
- }> - - void refetch()} /> + {t("lookup.searchHint")}}> + }> + {t("work.noTeachers")}}> + +
+ + + {t("admin.username")} + {t("profile.name")} + {t("admin.id")} + {t("common.actions")} + + + + + {(user) => ( + + {user.username} + {user.display_name || "—"} + {user.id} + + , + onSelect: () => { + setError(""); + setEntryPage(0); + setViewUser(user); + }, + }, + ]} + /> + + + )} + + +
+
+ PEOPLE_PAGE_SIZE}> + +
- 0} - fallback={
{t("work.empty")}
} - > +
+ +
+ + { + if (!open) { + setViewUser(null); + setError(""); + } + }} + title={t("work.forUser", { user: personLabel(viewUser()) })} + description={t("work.entries")} + > + + + {error()} + + + }> + 0} + fallback={
{t("work.empty")}
} + > +
@@ -216,12 +313,12 @@ function StaffWorkContent() { - + {(entry) => ( - {formatDateTime(entry.check_in, locale())} - {formatDateTime(entry.check_out, locale())} - {formatDurationMinutes(entry.duration_ms, locale())} + {formatDateTime(entry.check_in, locale())} + {formatDateTime(entry.check_out, locale())} + {formatDurationMinutes(entry.duration_ms, locale())} {entry.check_out == null ? t("work.open") : t("work.closed")} @@ -252,13 +349,13 @@ function StaffWorkContent() {
- WORK_PAGE_SIZE}> - + WORK_PAGE_SIZE}> + - - -
- +
+ + + setEditTarget(null)}> {t("common.cancel")} -
@@ -313,7 +410,7 @@ function StaffWorkContent() { if (!entry) return; try { await deleteWorkEntryById(entry.id); - await refetch(); + await refetchEntries(); } catch (err) { setError(formatApiError(err)); } finally { diff --git a/src/pages/student-attendance-page.tsx b/src/pages/student-attendance-page.tsx index e4e7574..b3b499c 100644 --- a/src/pages/student-attendance-page.tsx +++ b/src/pages/student-attendance-page.tsx @@ -1,17 +1,30 @@ -import { Show, Suspense, createResource, createSignal } from "solid-js"; +import { For, Show, createMemo, createResource, createSignal } from "solid-js"; import { getUserAttendance } from "@/api/getUserAttendance"; -import { formatApiError } from "@/api/client"; +import { getUserSearch } from "@/api/getUserSearch"; +import { ApiError, formatApiError } from "@/api/client"; +import type { Page } from "@/api/page"; import type { PersonRef } from "@/api/types"; import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; -import { UserSearchSelect } from "@/components/users/user-search-select"; -import { Button } from "@/components/ui/button"; +import { Alert } from "@/components/ui/alert"; +import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { DataToolbar } from "@/components/ui/data-toolbar"; import { ErrorAlert } from "@/components/ui/error-alert"; -import { PageSpinner } from "@/components/ui/page-spinner"; +import { IconEye } from "@/components/ui/icons"; +import { PaginationControls } from "@/components/ui/pagination-controls"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { createDebounced } from "@/lib/debounced"; +import { totalPages as pagesOf } from "@/lib/list-page"; import { personLabel } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; +const PAGE_SIZE = 12; +const MIN_QUERY = 2; +const emptyPage: Page = { items: [], total: 0, limit: null, offset: 0 }; + export default function StudentAttendancePage() { return ( @@ -22,66 +35,165 @@ export default function StudentAttendancePage() { function StudentAttendanceContent() { const t = useT(); - const [userId, setUserId] = createSignal(""); - const [selectedUser, setSelectedUser] = createSignal(null); - const [lookupId, setLookupId] = createSignal(null); - const [lookupLabel, setLookupLabel] = createSignal(""); - const [report, { refetch }] = createResource(lookupId, async (id) => { - if (!id) return null; - return getUserAttendance(id); + const [query, setQuery] = createSignal(""); + const debouncedQuery = createDebounced(query, 300); + const [page, setPage] = createSignal(0); + const [viewUser, setViewUser] = createSignal(null); + const [error, setError] = createSignal(""); + + const searchKey = createMemo(() => { + const q = debouncedQuery().trim(); + if (q.length < MIN_QUERY) return null; + return `${q}|${page()}`; }); + const [list] = createResource( + searchKey, + async (key) => { + try { + const q = key.split("|")[0]!; + return await getUserSearch(q, undefined, "student", { + limit: PAGE_SIZE, + offset: page() * PAGE_SIZE, + }); + } catch (err) { + setError(formatApiError(err)); + return emptyPage; + } + }, + { initialValue: emptyPage }, + ); + + const [report, { refetch: refetchReport }] = createResource( + () => viewUser()?.id ?? null, + async (id) => { + if (!id) return null; + try { + return await getUserAttendance(id); + } catch (err) { + if (err instanceof ApiError && err.status === 404) { + setError(t("common.notFound")); + return null; + } + setError(formatApiError(err)); + return null; + } + }, + ); + + const total = () => list().total; + const rows = () => list().items; + const totalPages = createMemo(() => pagesOf(total(), PAGE_SIZE)); + const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); + const canSearch = () => debouncedQuery().trim().length >= MIN_QUERY; + const listLoading = () => canSearch() && list.loading; + return (
- +
+
+ {t("nav.admin")} + / + {t("nav.studentAttendance")} +
+ +
-
-

{t("nav.studentAttendance")}

-

{t("attendance.lookup")}

+
+
+

{t("nav.studentAttendance")}

+

+ {canSearch() ? `${rows().length} / ${total()}` : t("lookup.searchHint")} +

+
-
{ - e.preventDefault(); - const id = userId().trim(); - if (!id) return; - setLookupId(id); - setLookupLabel(personLabel(selectedUser()) === "—" ? id : personLabel(selectedUser())); + + { + setError(""); + setQuery(value); + setPage(0); }} - > - - - + /> - - void refetch()} /> + + {error()} -
- }> - - {(r) => ( -
-

- {t("attendance.forUser", { user: lookupLabel() || lookupId() || "" })} -

- -
- )} + {t("lookup.searchHint")}}> + }> + 0} fallback={{t("form.noStudents")}}> + + + + + {t("admin.username")} + {t("profile.name")} + {t("admin.id")} + {t("common.actions")} + + + + + {(user) => ( + + {user.username} + {user.display_name || "—"} + {user.id} + + , + onSelect: () => { + setError(""); + setViewUser(user); + }, + }, + ]} + /> + + + )} + + +
+
+ PAGE_SIZE}> + + +
+
-
+ + + { + if (!open) { + setViewUser(null); + setError(""); + } + }} + title={t("attendance.forUser", { user: personLabel(viewUser()) })} + description={t("attendance.lookup")} + > +
+ + void refetchReport()} /> + + +

{t("common.loading")}

+
+ {(r) => } +
+
); } diff --git a/src/pages/student-marks-page.tsx b/src/pages/student-marks-page.tsx index c92c08e..de2534c 100644 --- a/src/pages/student-marks-page.tsx +++ b/src/pages/student-marks-page.tsx @@ -1,17 +1,30 @@ -import { Show, Suspense, createResource, createSignal } from "solid-js"; +import { For, Show, createMemo, createResource, createSignal } from "solid-js"; import { getUserMarks } from "@/api/getUserMarks"; -import { formatApiError } from "@/api/client"; +import { getUserSearch } from "@/api/getUserSearch"; +import { ApiError, formatApiError } from "@/api/client"; +import type { Page } from "@/api/page"; import type { PersonRef } from "@/api/types"; import { MarksReportView } from "@/components/marks/marks-report-view"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; -import { UserSearchSelect } from "@/components/users/user-search-select"; -import { Button } from "@/components/ui/button"; +import { Alert } from "@/components/ui/alert"; +import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { DataToolbar } from "@/components/ui/data-toolbar"; import { ErrorAlert } from "@/components/ui/error-alert"; -import { PageSpinner } from "@/components/ui/page-spinner"; +import { IconEye } from "@/components/ui/icons"; +import { PaginationControls } from "@/components/ui/pagination-controls"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { createDebounced } from "@/lib/debounced"; +import { totalPages as pagesOf } from "@/lib/list-page"; import { personLabel } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; +const PAGE_SIZE = 12; +const MIN_QUERY = 2; +const emptyPage: Page = { items: [], total: 0, limit: null, offset: 0 }; + export default function StudentMarksPage() { return ( @@ -22,71 +35,165 @@ export default function StudentMarksPage() { function StudentMarksContent() { const t = useT(); - const [userId, setUserId] = createSignal(""); - const [selectedUser, setSelectedUser] = createSignal(null); - const [lookupId, setLookupId] = createSignal(null); - const [lookupLabel, setLookupLabel] = createSignal(""); - const [report, { refetch }] = createResource(lookupId, async (id) => { - if (!id) return null; - return getUserMarks(id); + const [query, setQuery] = createSignal(""); + const debouncedQuery = createDebounced(query, 300); + const [page, setPage] = createSignal(0); + const [viewUser, setViewUser] = createSignal(null); + const [error, setError] = createSignal(""); + + const searchKey = createMemo(() => { + const q = debouncedQuery().trim(); + if (q.length < MIN_QUERY) return null; + return `${q}|${page()}`; }); + const [list] = createResource( + searchKey, + async (key) => { + try { + const q = key.split("|")[0]!; + return await getUserSearch(q, undefined, "student", { + limit: PAGE_SIZE, + offset: page() * PAGE_SIZE, + }); + } catch (err) { + setError(formatApiError(err)); + return emptyPage; + } + }, + { initialValue: emptyPage }, + ); + + const [report, { refetch: refetchReport }] = createResource( + () => viewUser()?.id ?? null, + async (id) => { + if (!id) return null; + try { + return await getUserMarks(id); + } catch (err) { + if (err instanceof ApiError && err.status === 404) { + setError(t("common.notFound")); + return null; + } + setError(formatApiError(err)); + return null; + } + }, + ); + + const total = () => list().total; + const rows = () => list().items; + const totalPages = createMemo(() => pagesOf(total(), PAGE_SIZE)); + const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); + const canSearch = () => debouncedQuery().trim().length >= MIN_QUERY; + const listLoading = () => canSearch() && list.loading; + return (
- +
+
+ {t("nav.admin")} + / + {t("nav.studentMarks")} +
+ +
-
-

{t("nav.studentMarks")}

-

{t("marks.lookup")}

+
+
+

{t("nav.studentMarks")}

+

+ {canSearch() ? `${rows().length} / ${total()}` : t("lookup.searchHint")} +

+
-
{ - e.preventDefault(); - const id = userId().trim(); - if (!id) return; - setLookupId(id); - setLookupLabel(personLabel(selectedUser()) === "—" ? id : personLabel(selectedUser())); + + { + setError(""); + setQuery(value); + setPage(0); }} - > - - - + /> - - void refetch()} /> + + {error()} -
- }> - - {(r) => ( -
-

- {t("marks.forUser", { user: lookupLabel() || lookupId() || "" })} -

- -
- )} + {t("lookup.searchHint")}}> + }> + 0} fallback={{t("form.noStudents")}}> + + + + + {t("admin.username")} + {t("profile.name")} + {t("admin.id")} + {t("common.actions")} + + + + + {(user) => ( + + {user.username} + {user.display_name || "—"} + {user.id} + + , + onSelect: () => { + setError(""); + setViewUser(user); + }, + }, + ]} + /> + + + )} + + +
+
+ PAGE_SIZE}> + + +
+
-
+ + + { + if (!open) { + setViewUser(null); + setError(""); + } + }} + title={t("marks.forUser", { user: personLabel(viewUser()) })} + description={t("marks.lookup")} + > +
+ + void refetchReport()} /> + + +

{t("common.loading")}

+
+ {(r) => } +
+
); }