♻️ staff-work, student-marks, student-attendance pages use search-table + SidePanel pattern
Browse files at this commit54f8f1c57ff93bcb7bd1f7df939a6d624b532093Parent: 52be1ae- refactor
- ♻️ staff-work, student-marks, student-attendance pages use search-table + SidePanel pattern
8 changed files +671 -287
- src/components/attendance/attendance-report-view.tsx +67 -45
- src/components/marks/marks-report-view.tsx +49 -35
- src/components/ui/side-panel.tsx +26 -12
- src/i18n/messages.ts +7 -1
- src/lib/debounced.ts +12 -0
- src/pages/staff-work-page.tsx +180 -83
- src/pages/student-attendance-page.tsx +165 -53
- src/pages/student-marks-page.tsx +165 -58
src/components/attendance/attendance-report-view.tsxmodified+67 -45
| @@ -17,100 +17,122 @@ function customEntries(counts: AttendanceCounts) { | |||
| 17 | return Object.entries(counts.custom ?? {}).filter(([, count]) => count > 0); | 17 | return Object.entries(counts.custom ?? {}).filter(([, count]) => count > 0); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | -function CountsCard(props: { title: string; counts: AttendanceCounts }) { | 20 | +function CountsCard(props: { title: string; counts: AttendanceCounts; compact?: boolean }) { |
| 21 | const t = useT(); | 21 | const t = useT(); |
| 22 | return ( | 22 | return ( |
| 23 | - <article class="data-shell space-y-4 p-4"> | 23 | + <article class={cn("space-y-3 rounded-xl border border-border/80 bg-card", props.compact ? "p-3" : "data-shell space-y-4 p-4")}> |
| 24 | <div class="flex items-center justify-between gap-3"> | 24 | <div class="flex items-center justify-between gap-3"> |
| 25 | - <h3 class="font-display text-lg font-semibold">{props.title}</h3> | 25 | + <h3 class={cn("font-display font-semibold", props.compact ? "text-sm" : "text-lg")}>{props.title}</h3> |
| 26 | - <Badge variant="secondary" class="mono rounded-full px-3 py-1">{percent(props.counts.rate)}</Badge> | 26 | + <Badge variant="secondary" class="mono rounded-full px-2.5 py-0.5 text-xs"> |
| 27 | + {percent(props.counts.rate)} | ||
| 28 | + </Badge> | ||
| 27 | </div> | 29 | </div> |
| 28 | - <dl class="grid grid-cols-1 gap-2 text-sm sm:grid-cols-2"> | 30 | + <dl class={cn("grid gap-2 text-sm", props.compact ? "grid-cols-2" : "grid-cols-1 sm:grid-cols-2")}> |
| 29 | <For each={ATTENDANCE_STATUSES}> | 31 | <For each={ATTENDANCE_STATUSES}> |
| 30 | - {(status) => <StatusStat label={t(status.key)} detail={t(status.detailKey)} value={props.counts[status.value]} class={status.class} />} | 32 | + {(status) => ( |
| 33 | + <StatusStat | ||
| 34 | + label={t(status.key)} | ||
| 35 | + detail={props.compact ? undefined : t(status.detailKey)} | ||
| 36 | + value={props.counts[status.value]} | ||
| 37 | + class={status.class} | ||
| 38 | + compact={props.compact} | ||
| 39 | + /> | ||
| 40 | + )} | ||
| 31 | </For> | 41 | </For> |
| 32 | </dl> | 42 | </dl> |
| 33 | <dl class="grid grid-cols-2 gap-2 text-sm"> | 43 | <dl class="grid grid-cols-2 gap-2 text-sm"> |
| 34 | - <Stat label={t("common.all")} value={props.counts.total} /> | 44 | + <Stat label={t("common.all")} value={props.counts.total} compact={props.compact} /> |
| 35 | - <Stat label={t("attendance.rate")} value={percent(props.counts.rate)} /> | 45 | + <Stat label={t("attendance.rate")} value={percent(props.counts.rate)} compact={props.compact} /> |
| 36 | </dl> | 46 | </dl> |
| 37 | <Show when={customEntries(props.counts).length > 0}> | 47 | <Show when={customEntries(props.counts).length > 0}> |
| 38 | - <div class="flex flex-wrap gap-2 pt-1"> | 48 | + <div class="flex flex-wrap gap-1.5 pt-0.5"> |
| 39 | - <For each={customEntries(props.counts)}>{([label, count]) => <Badge variant="outline" class="rounded-full">{label}: {count}</Badge>}</For> | 49 | + <For each={customEntries(props.counts)}> |
| 50 | + {([label, count]) => ( | ||
| 51 | + <Badge variant="outline" class="rounded-full text-[11px]"> | ||
| 52 | + {label}: {count} | ||
| 53 | + </Badge> | ||
| 54 | + )} | ||
| 55 | + </For> | ||
| 40 | </div> | 56 | </div> |
| 41 | </Show> | 57 | </Show> |
| 42 | </article> | 58 | </article> |
| 43 | ); | 59 | ); |
| 44 | } | 60 | } |
| 45 | 61 | ||
| 46 | -function Stat(props: { label: string; value: string | number }) { | 62 | +function Stat(props: { label: string; value: string | number; compact?: boolean }) { |
| 47 | return ( | 63 | return ( |
| 48 | - <div class="rounded-xl border bg-background/60 p-3"> | 64 | + <div class={cn("rounded-xl border bg-background/60", props.compact ? "p-2.5" : "p-3")}> |
| 49 | - <dt class="text-xs text-muted-foreground">{props.label}</dt> | 65 | + <dt class="text-[11px] text-muted-foreground">{props.label}</dt> |
| 50 | - <dd class="mono mt-1 text-xl font-semibold tabular-nums">{props.value}</dd> | 66 | + <dd class={cn("mono font-semibold tabular-nums", props.compact ? "mt-0.5 text-lg" : "mt-1 text-xl")}>{props.value}</dd> |
| 51 | </div> | 67 | </div> |
| 52 | ); | 68 | ); |
| 53 | } | 69 | } |
| 54 | 70 | ||
| 55 | -function StatusStat(props: { label: string; detail: string; value: number; class: string }) { | 71 | +function StatusStat(props: { label: string; detail?: string; value: number; class: string; compact?: boolean }) { |
| 56 | return ( | 72 | return ( |
| 57 | - <div class={cn("rounded-xl border p-3", props.class)}> | 73 | + <div class={cn("rounded-xl border", props.class, props.compact ? "p-2.5" : "p-3")}> |
| 58 | - <dt class="flex items-center justify-between gap-2 text-xs font-semibold"> | 74 | + <dt class="flex items-center justify-between gap-1 text-[11px] font-semibold"> |
| 59 | - <span>{props.label}</span> | 75 | + <span class="truncate">{props.label}</span> |
| 60 | - <span class="font-normal opacity-75">{props.detail}</span> | 76 | + <Show when={props.detail}> |
| 77 | + <span class="hidden truncate font-normal opacity-75 sm:inline">{props.detail}</span> | ||
| 78 | + </Show> | ||
| 61 | </dt> | 79 | </dt> |
| 62 | - <dd class="mono mt-1 text-2xl font-semibold tabular-nums">{props.value}</dd> | 80 | + <dd class={cn("mono font-semibold tabular-nums", props.compact ? "mt-0.5 text-xl" : "mt-1 text-2xl")}>{props.value}</dd> |
| 63 | </div> | 81 | </div> |
| 64 | ); | 82 | ); |
| 65 | } | 83 | } |
| 66 | 84 | ||
| 67 | -export function AttendanceReportView(props: { report: AttendanceReport }) { | 85 | +export function AttendanceReportView(props: { report: AttendanceReport; compact?: boolean }) { |
| 68 | const t = useT(); | 86 | const t = useT(); |
| 87 | + const compact = () => props.compact === true; | ||
| 88 | + | ||
| 69 | return ( | 89 | return ( |
| 70 | - <div class="space-y-4"> | 90 | + <div class={cn("min-w-0 space-y-3", !compact() && "space-y-4")}> |
| 71 | - <div class="grid gap-4 lg:grid-cols-2"> | 91 | + <div class={cn("grid gap-3", compact() ? "grid-cols-1" : "gap-4 lg:grid-cols-2")}> |
| 72 | - <CountsCard title={t("attendance.events")} counts={props.report.events} /> | 92 | + <CountsCard title={t("attendance.events")} counts={props.report.events} compact={compact()} /> |
| 73 | - <CountsCard title={t("attendance.sessions")} counts={props.report.sessions} /> | 93 | + <CountsCard title={t("attendance.sessions")} counts={props.report.sessions} compact={compact()} /> |
| 74 | </div> | 94 | </div> |
| 75 | 95 | ||
| 76 | - <section class="data-shell space-y-4 p-4"> | 96 | + <section class={cn("space-y-3 rounded-xl border border-border/80 bg-card", compact() ? "p-3" : "data-shell space-y-4 p-4")}> |
| 77 | - <h3 class="font-display text-lg font-semibold">{t("attendance.courseBreakdown")}</h3> | 97 | + <h3 class={cn("font-display font-semibold", compact() ? "text-sm" : "text-lg")}>{t("attendance.courseBreakdown")}</h3> |
| 78 | <Show | 98 | <Show |
| 79 | when={props.report.courses.length > 0} | 99 | when={props.report.courses.length > 0} |
| 80 | - fallback={<DataTableEmpty>{t("attendance.emptyCourses")}</DataTableEmpty>} | 100 | + fallback={<DataTableEmpty class="py-6">{t("attendance.emptyCourses")}</DataTableEmpty>} |
| 81 | > | 101 | > |
| 82 | - <DataTableFrame> | 102 | + <DataTableFrame class="min-w-0"> |
| 83 | - <Table class="data-table table-fixed min-w-[48rem]"> | 103 | + <Table class={cn("data-table w-full", compact() ? "text-xs" : "table-fixed min-w-[40rem]")}> |
| 84 | - <colgroup> | ||
| 85 | - <col class="w-[30%]" /> | ||
| 86 | - <col class="w-[7rem]" /> | ||
| 87 | - <col class="w-[7rem]" /> | ||
| 88 | - <col class="w-[7rem]" /> | ||
| 89 | - <col class="w-[7rem]" /> | ||
| 90 | - <col class="w-[7rem]" /> | ||
| 91 | - <col class="w-[7rem]" /> | ||
| 92 | - </colgroup> | ||
| 93 | <TableHeader> | 104 | <TableHeader> |
| 94 | <TableRow> | 105 | <TableRow> |
| 95 | <TableHead>{t("nav.courses")}</TableHead> | 106 | <TableHead>{t("nav.courses")}</TableHead> |
| 96 | <For each={ATTENDANCE_STATUSES}> | 107 | <For each={ATTENDANCE_STATUSES}> |
| 97 | - {(status) => <TableHead class="text-right" title={t(status.detailKey)}>{t(status.key)}</TableHead>} | 108 | + {(status) => ( |
| 109 | + <TableHead class="text-right" title={t(status.detailKey)}> | ||
| 110 | + {compact() ? t(status.key).slice(0, 1) : t(status.key)} | ||
| 111 | + </TableHead> | ||
| 112 | + )} | ||
| 98 | </For> | 113 | </For> |
| 99 | - <TableHead class="text-right">{t("common.all")}</TableHead> | 114 | + <TableHead class="text-right">{compact() ? "Σ" : t("common.all")}</TableHead> |
| 100 | - <TableHead class="text-right">{t("attendance.rate")}</TableHead> | 115 | + <TableHead class="text-right">%</TableHead> |
| 101 | </TableRow> | 116 | </TableRow> |
| 102 | </TableHeader> | 117 | </TableHeader> |
| 103 | <TableBody> | 118 | <TableBody> |
| 104 | <For each={props.report.courses}> | 119 | <For each={props.report.courses}> |
| 105 | {(block) => ( | 120 | {(block) => ( |
| 106 | <TableRow> | 121 | <TableRow> |
| 107 | - <TableCell class="font-medium"> | 122 | + <TableCell class="min-w-0 font-medium"> |
| 108 | - <Link to="/courses/$id" params={{ id: block.course.id }} class="hover:underline">{block.course.title}</Link> | 123 | + <Link to="/courses/$id" params={{ id: block.course.id }} class="block truncate hover:underline"> |
| 124 | + {block.course.title} | ||
| 125 | + </Link> | ||
| 109 | </TableCell> | 126 | </TableCell> |
| 110 | <For each={ATTENDANCE_STATUSES}> | 127 | <For each={ATTENDANCE_STATUSES}> |
| 111 | {(status) => ( | 128 | {(status) => ( |
| 112 | <TableCell class="text-right"> | 129 | <TableCell class="text-right"> |
| 113 | - <span class={cn("mono inline-flex min-w-8 justify-center rounded-full border px-2 py-0.5 text-xs font-semibold tabular-nums", status.class)}> | 130 | + <span |
| 131 | + class={cn( | ||
| 132 | + "mono inline-flex min-w-7 justify-center rounded-full border px-1.5 py-0.5 text-[11px] font-semibold tabular-nums", | ||
| 133 | + status.class, | ||
| 134 | + )} | ||
| 135 | + > | ||
| 114 | {block.counts[status.value]} | 136 | {block.counts[status.value]} |
| 115 | </span> | 137 | </span> |
| 116 | </TableCell> | 138 | </TableCell> |
src/components/marks/marks-report-view.tsxmodified+49 -35
| @@ -6,6 +6,7 @@ import { Badge } from "@/components/ui/badge"; | |||
| 6 | import { DataTableEmpty, DataTableFrame } from "@/components/ui/data-table"; | 6 | import { DataTableEmpty, DataTableFrame } from "@/components/ui/data-table"; |
| 7 | import { ExamLink } from "@/components/exams/exam-link"; | 7 | import { ExamLink } from "@/components/exams/exam-link"; |
| 8 | import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; | 8 | import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; |
| 9 | +import { cn } from "@/lib/cn"; | ||
| 9 | import { examKindLabel } from "@/lib/exam-labels"; | 10 | import { examKindLabel } from "@/lib/exam-labels"; |
| 10 | import { examWeight } from "@/lib/exam-weight"; | 11 | import { examWeight } from "@/lib/exam-weight"; |
| 11 | import { useT } from "@/stores/preferences-context"; | 12 | import { useT } from "@/stores/preferences-context"; |
| @@ -17,59 +18,67 @@ function markWithGrade(mark: number | null, grade?: string | null) { | |||
| 17 | return grade ? `${round(mark)} / ${grade}` : round(mark); | 18 | return grade ? `${round(mark)} / ${grade}` : round(mark); |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | -export function MarksReportView(props: { report: MarksReport }) { | 21 | +export function MarksReportView(props: { report: MarksReport; compact?: boolean }) { |
| 21 | const t = useT(); | 22 | const t = useT(); |
| 22 | const [settings] = createResource(() => getSettings()); | 23 | const [settings] = createResource(() => getSettings()); |
| 24 | + const compact = () => props.compact === true; | ||
| 25 | + | ||
| 23 | return ( | 26 | return ( |
| 24 | - <Show | 27 | + <Show when={props.report.courses.length > 0} fallback={<DataTableEmpty>{t("marks.empty")}</DataTableEmpty>}> |
| 25 | - when={props.report.courses.length > 0} | 28 | + <div class={cn("space-y-3", compact() ? "min-w-0" : "space-y-4")}> |
| 26 | - fallback={ | 29 | + <div |
| 27 | - <DataTableEmpty>{t("marks.empty")}</DataTableEmpty> | 30 | + class={cn( |
| 28 | - } | 31 | + "flex flex-wrap items-center justify-between gap-3 rounded-xl border border-border/80 bg-card", |
| 29 | - > | 32 | + compact() ? "px-3 py-3" : "data-shell p-4", |
| 30 | - <div class="space-y-4"> | 33 | + )} |
| 31 | - <div class="data-shell flex flex-wrap items-center justify-between gap-3 p-4"> | 34 | + > |
| 32 | - <span class="text-sm font-medium text-muted-foreground">{t("marks.overall")}</span> | 35 | + <span class="text-xs font-medium text-muted-foreground sm:text-sm">{t("marks.overall")}</span> |
| 33 | - <p class="font-display text-3xl font-semibold tabular-nums"> | 36 | + <p class={cn("font-display font-semibold tabular-nums", compact() ? "text-2xl" : "text-3xl")}> |
| 34 | {markWithGrade(props.report.overall_average, props.report.overall_grade)} | 37 | {markWithGrade(props.report.overall_average, props.report.overall_grade)} |
| 35 | <Show when={props.report.overall_average != null}> | 38 | <Show when={props.report.overall_average != null}> |
| 36 | - <span class="text-base font-medium text-muted-foreground"> / 100</span> | 39 | + <span class="text-sm font-medium text-muted-foreground"> / 100</span> |
| 37 | </Show> | 40 | </Show> |
| 38 | </p> | 41 | </p> |
| 39 | </div> | 42 | </div> |
| 40 | 43 | ||
| 41 | <For each={props.report.courses}> | 44 | <For each={props.report.courses}> |
| 42 | {(block) => ( | 45 | {(block) => ( |
| 43 | - <article class="data-shell space-y-4 p-4"> | 46 | + <article |
| 44 | - <header class="flex flex-wrap items-center justify-between gap-2"> | 47 | + class={cn( |
| 45 | - <h3 class="font-display text-lg font-semibold"> | 48 | + "space-y-3 rounded-xl border border-border/80 bg-card", |
| 46 | - <Link to="/courses/$id" params={{ id: block.course.id }} class="hover:text-primary hover:underline"> | 49 | + compact() ? "p-3" : "data-shell space-y-4 p-4", |
| 50 | + )} | ||
| 51 | + > | ||
| 52 | + <header class="flex min-w-0 flex-wrap items-center justify-between gap-2"> | ||
| 53 | + <h3 class={cn("min-w-0 font-display font-semibold", compact() ? "text-sm" : "text-lg")}> | ||
| 54 | + <Link | ||
| 55 | + to="/courses/$id" | ||
| 56 | + params={{ id: block.course.id }} | ||
| 57 | + class="block truncate hover:text-primary hover:underline" | ||
| 58 | + > | ||
| 47 | {block.course.title} | 59 | {block.course.title} |
| 48 | </Link> | 60 | </Link> |
| 49 | </h3> | 61 | </h3> |
| 50 | - <Badge variant="secondary" class="mono rounded-sm px-3 py-1" title={t("marks.courseAvg")}> | 62 | + <Badge variant="secondary" class="mono shrink-0 rounded-sm px-2.5 py-0.5 text-xs" title={t("marks.courseAvg")}> |
| 51 | {markWithGrade(block.average, block.average_grade)} | 63 | {markWithGrade(block.average, block.average_grade)} |
| 52 | </Badge> | 64 | </Badge> |
| 53 | </header> | 65 | </header> |
| 54 | 66 | ||
| 55 | - <Show | 67 | + <Show when={block.results.length > 0} fallback={<DataTableEmpty class="py-6">{t("exams.noResults")}</DataTableEmpty>}> |
| 56 | - when={block.results.length > 0} | 68 | + <DataTableFrame class="min-w-0"> |
| 57 | - fallback={ | 69 | + <Table class={cn("data-table w-full", compact() ? "text-xs" : "table-fixed min-w-[36rem]")}> |
| 58 | - <DataTableEmpty>{t("exams.noResults")}</DataTableEmpty> | 70 | + <Show when={!compact()}> |
| 59 | - } | 71 | + <colgroup> |
| 60 | - > | 72 | + <col class="w-[42%]" /> |
| 61 | - <DataTableFrame> | 73 | + <col class="w-[18%]" /> |
| 62 | - <Table class="data-table table-fixed min-w-[42rem]"> | 74 | + <col class="w-[8rem]" /> |
| 63 | - <colgroup> | 75 | + <col class="w-[10rem]" /> |
| 64 | - <col class="w-[42%]" /> | 76 | + </colgroup> |
| 65 | - <col class="w-[18%]" /> | 77 | + </Show> |
| 66 | - <col class="w-[8rem]" /> | ||
| 67 | - <col class="w-[10rem]" /> | ||
| 68 | - </colgroup> | ||
| 69 | <TableHeader> | 78 | <TableHeader> |
| 70 | <TableRow> | 79 | <TableRow> |
| 71 | <TableHead>{t("marks.exam")}</TableHead> | 80 | <TableHead>{t("marks.exam")}</TableHead> |
| 72 | - <TableHead>{t("exams.kind")}</TableHead> | 81 | + <TableHead class={compact() ? "hidden sm:table-cell" : undefined}>{t("exams.kind")}</TableHead> |
| 73 | <TableHead class="text-right">{t("marks.weight")}</TableHead> | 82 | <TableHead class="text-right">{t("marks.weight")}</TableHead> |
| 74 | <TableHead class="text-right">{t("marks.mark")}</TableHead> | 83 | <TableHead class="text-right">{t("marks.mark")}</TableHead> |
| 75 | </TableRow> | 84 | </TableRow> |
| @@ -78,12 +87,17 @@ export function MarksReportView(props: { report: MarksReport }) { | |||
| 78 | <For each={block.results}> | 87 | <For each={block.results}> |
| 79 | {(entry) => ( | 88 | {(entry) => ( |
| 80 | <TableRow> | 89 | <TableRow> |
| 81 | - <TableCell> | 90 | + <TableCell class="min-w-0"> |
| 82 | - <ExamLink examId={entry.exam} class="font-medium hover:underline"> | 91 | + <ExamLink examId={entry.exam} class="block truncate font-medium hover:underline"> |
| 83 | {entry.title} | 92 | {entry.title} |
| 84 | </ExamLink> | 93 | </ExamLink> |
| 94 | + <Show when={compact()}> | ||
| 95 | + <p class="mt-0.5 truncate text-[11px] text-muted-foreground sm:hidden"> | ||
| 96 | + {examKindLabel(entry.kind, t)} | ||
| 97 | + </p> | ||
| 98 | + </Show> | ||
| 85 | </TableCell> | 99 | </TableCell> |
| 86 | - <TableCell> | 100 | + <TableCell class={compact() ? "hidden sm:table-cell" : undefined}> |
| 87 | <Badge variant="outline" class="rounded-sm capitalize"> | 101 | <Badge variant="outline" class="rounded-sm capitalize"> |
| 88 | {examKindLabel(entry.kind, t)} | 102 | {examKindLabel(entry.kind, t)} |
| 89 | </Badge> | 103 | </Badge> |
src/components/ui/side-panel.tsxmodified+26 -12
| @@ -3,30 +3,42 @@ import type { ParentProps } from "solid-js"; | |||
| 3 | import { IconX } from "@/components/ui/icons"; | 3 | import { IconX } from "@/components/ui/icons"; |
| 4 | import { cn } from "@/lib/cn"; | 4 | import { cn } from "@/lib/cn"; |
| 5 | 5 | ||
| 6 | -export function SidePanel(props: ParentProps<{ | 6 | +export function SidePanel( |
| 7 | - open: boolean; | 7 | + props: ParentProps<{ |
| 8 | - onOpenChange: (open: boolean) => void; | 8 | + open: boolean; |
| 9 | - title: string; | 9 | + onOpenChange: (open: boolean) => void; |
| 10 | - description?: string; | 10 | + title: string; |
| 11 | - class?: string; | 11 | + description?: string; |
| 12 | -}>) { | 12 | + class?: string; |
| 13 | + /** default ~34rem, wide ~42rem, xl ~48rem — for report tables */ | ||
| 14 | + size?: "default" | "wide" | "xl"; | ||
| 15 | + }>, | ||
| 16 | +) { | ||
| 17 | + const width = () => { | ||
| 18 | + if (props.size === "xl") return "max-w-[min(48rem,100vw)]"; | ||
| 19 | + if (props.size === "wide") return "max-w-[min(42rem,100vw)]"; | ||
| 20 | + return "max-w-[min(34rem,100vw)]"; | ||
| 21 | + }; | ||
| 22 | + | ||
| 13 | return ( | 23 | return ( |
| 14 | <DialogPrimitive open={props.open} onOpenChange={props.onOpenChange}> | 24 | <DialogPrimitive open={props.open} onOpenChange={props.onOpenChange}> |
| 15 | <DialogPrimitive.Portal> | 25 | <DialogPrimitive.Portal> |
| 16 | <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/25 backdrop-blur-[1px] dark:bg-black/55" /> | 26 | <DialogPrimitive.Overlay class="fixed inset-0 z-50 bg-black/25 backdrop-blur-[1px] dark:bg-black/55" /> |
| 17 | <DialogPrimitive.Content | 27 | <DialogPrimitive.Content |
| 18 | class={cn( | 28 | class={cn( |
| 19 | - "fixed inset-y-0 right-0 z-50 flex w-full max-w-[34rem] flex-col border-l border-border/80 bg-background text-foreground shadow-[0_20px_70px_hsl(var(--foreground)/0.18)] outline-none transition-transform duration-200 sm:inset-y-3 sm:right-3 sm:rounded-2xl sm:border sm:border-border/80", | 29 | + "fixed inset-y-0 right-0 z-50 flex h-full w-full flex-col border-l border-border/80 bg-background text-foreground shadow-[0_20px_70px_hsl(var(--foreground)/0.18)] outline-none", |
| 30 | + "sm:inset-y-3 sm:right-3 sm:h-auto sm:max-h-[calc(100vh-1.5rem)] sm:rounded-2xl sm:border sm:border-border/80", | ||
| 31 | + width(), | ||
| 20 | props.class, | 32 | props.class, |
| 21 | )} | 33 | )} |
| 22 | > | 34 | > |
| 23 | - <div class="flex items-start justify-between gap-4 border-b border-border/80 bg-card px-6 py-5 sm:rounded-t-2xl"> | 35 | + <div class="flex shrink-0 items-start justify-between gap-4 border-b border-border/80 bg-card px-5 py-4 sm:rounded-t-2xl sm:px-6 sm:py-5"> |
| 24 | - <div class="min-w-0 space-y-1"> | 36 | + <div class="min-w-0 flex-1 space-y-1"> |
| 25 | <DialogPrimitive.Title class="truncate font-display text-base font-semibold leading-6 tracking-tight"> | 37 | <DialogPrimitive.Title class="truncate font-display text-base font-semibold leading-6 tracking-tight"> |
| 26 | {props.title} | 38 | {props.title} |
| 27 | </DialogPrimitive.Title> | 39 | </DialogPrimitive.Title> |
| 28 | {props.description && ( | 40 | {props.description && ( |
| 29 | - <DialogPrimitive.Description class="text-sm leading-5 text-muted-foreground"> | 41 | + <DialogPrimitive.Description class="line-clamp-2 text-sm leading-5 text-muted-foreground"> |
| 30 | {props.description} | 42 | {props.description} |
| 31 | </DialogPrimitive.Description> | 43 | </DialogPrimitive.Description> |
| 32 | )} | 44 | )} |
| @@ -35,7 +47,9 @@ export function SidePanel(props: ParentProps<{ | |||
| 35 | <IconX class="h-4 w-4" /> | 47 | <IconX class="h-4 w-4" /> |
| 36 | </DialogPrimitive.CloseButton> | 48 | </DialogPrimitive.CloseButton> |
| 37 | </div> | 49 | </div> |
| 38 | - <div class="side-panel-body min-h-0 flex-1 overflow-y-auto bg-muted/20 px-6 pt-5">{props.children}</div> | 50 | + <div class="side-panel-body min-h-0 flex-1 overflow-x-hidden overflow-y-auto bg-muted/20 px-5 py-5 sm:px-6 sm:pb-6"> |
| 51 | + {props.children} | ||
| 52 | + </div> | ||
| 39 | </DialogPrimitive.Content> | 53 | </DialogPrimitive.Content> |
| 40 | </DialogPrimitive.Portal> | 54 | </DialogPrimitive.Portal> |
| 41 | </DialogPrimitive> | 55 | </DialogPrimitive> |
src/i18n/messages.tsmodified+7 -1
| @@ -496,7 +496,9 @@ export type MessageKey = | |||
| 496 | | "work.timesRequired" | 496 | | "work.timesRequired" |
| 497 | | "work.deleteSummary" | 497 | | "work.deleteSummary" |
| 498 | | "work.teacherIdentity" | 498 | | "work.teacherIdentity" |
| 499 | - | "work.noTeachers"; | 499 | + | "work.noTeachers" |
| 500 | + | "lookup.searchHint" | ||
| 501 | + | "work.userNotFound"; | ||
| 500 | 502 | ||
| 501 | type Dict = Record<MessageKey, string>; | 503 | type Dict = Record<MessageKey, string>; |
| 502 | 504 | ||
| @@ -1003,6 +1005,8 @@ const en: Dict = { | |||
| 1003 | "work.staffSubtitle": "Look up a teacher, correct closed stints, or delete entries.", | 1005 | "work.staffSubtitle": "Look up a teacher, correct closed stints, or delete entries.", |
| 1004 | "work.teacherIdentity": "Teacher", | 1006 | "work.teacherIdentity": "Teacher", |
| 1005 | "work.noTeachers": "No teachers found.", | 1007 | "work.noTeachers": "No teachers found.", |
| 1008 | + "lookup.searchHint": "Type at least 2 characters to search.", | ||
| 1009 | + "work.userNotFound": "No work log found for this user.", | ||
| 1006 | "work.show": "Show log", | 1010 | "work.show": "Show log", |
| 1007 | "work.forUser": "Log for {user}", | 1011 | "work.forUser": "Log for {user}", |
| 1008 | "work.correct": "Correct entry", | 1012 | "work.correct": "Correct entry", |
| @@ -1515,6 +1519,8 @@ const tr: Dict = { | |||
| 1515 | "work.staffSubtitle": "Öğretmen ara, kapalı mesaileri düzelt veya kayıt sil.", | 1519 | "work.staffSubtitle": "Öğretmen ara, kapalı mesaileri düzelt veya kayıt sil.", |
| 1516 | "work.teacherIdentity": "Öğretmen", | 1520 | "work.teacherIdentity": "Öğretmen", |
| 1517 | "work.noTeachers": "Öğretmen bulunamadı.", | 1521 | "work.noTeachers": "Öğretmen bulunamadı.", |
| 1522 | + "lookup.searchHint": "Aramak için en az 2 karakter yaz.", | ||
| 1523 | + "work.userNotFound": "Bu kullanıcı için mesai kaydı bulunamadı.", | ||
| 1518 | "work.show": "Kaydı göster", | 1524 | "work.show": "Kaydı göster", |
| 1519 | "work.forUser": "{user} için kayıtlar", | 1525 | "work.forUser": "{user} için kayıtlar", |
| 1520 | "work.correct": "Kaydı düzelt", | 1526 | "work.correct": "Kaydı düzelt", |
src/lib/debounced.tsadded+12 -0
| @@ -0,0 +1,12 @@ | |||
| 1 | +import { createEffect, createSignal, onCleanup, type Accessor } from "solid-js"; | ||
| 2 | + | ||
| 3 | +/** Debounce an accessor value; useful for search inputs. */ | ||
| 4 | +export function createDebounced<T>(source: Accessor<T>, ms = 300): Accessor<T> { | ||
| 5 | + const [value, setValue] = createSignal(source()); | ||
| 6 | + createEffect(() => { | ||
| 7 | + const next = source(); | ||
| 8 | + const timer = window.setTimeout(() => setValue(() => next), ms); | ||
| 9 | + onCleanup(() => window.clearTimeout(timer)); | ||
| 10 | + }); | ||
| 11 | + return value; | ||
| 12 | +} | ||
src/pages/staff-work-page.tsxmodified+180 -83
| @@ -1,33 +1,36 @@ | |||
| 1 | -import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | 1 | +import { For, Show, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | import { deleteWorkEntryById } from "@/api/deleteWorkEntryById"; | 2 | import { deleteWorkEntryById } from "@/api/deleteWorkEntryById"; |
| 3 | +import { getUserSearch } from "@/api/getUserSearch"; | ||
| 3 | import { getUserWorkLog } from "@/api/getUserWorkLog"; | 4 | import { getUserWorkLog } from "@/api/getUserWorkLog"; |
| 4 | import { patchWorkEntryById } from "@/api/patchWorkEntryById"; | 5 | import { patchWorkEntryById } from "@/api/patchWorkEntryById"; |
| 5 | -import { formatApiError } from "@/api/client"; | 6 | +import { ApiError, formatApiError } from "@/api/client"; |
| 7 | +import type { Page } from "@/api/page"; | ||
| 6 | import type { PersonRef, WorkEntry } from "@/api/types"; | 8 | import type { PersonRef, WorkEntry } from "@/api/types"; |
| 7 | import { RouteGuard } from "@/components/layout/route-guard"; | 9 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 8 | import { PageHeader } from "@/components/layout/page-header"; | 10 | import { PageHeader } from "@/components/layout/page-header"; |
| 9 | -import { UserSearchSelect } from "@/components/users/user-search-select"; | ||
| 10 | import { Alert } from "@/components/ui/alert"; | 11 | import { Alert } from "@/components/ui/alert"; |
| 11 | import { Badge } from "@/components/ui/badge"; | 12 | import { Badge } from "@/components/ui/badge"; |
| 12 | import { Button } from "@/components/ui/button"; | 13 | import { Button } from "@/components/ui/button"; |
| 13 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 14 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 14 | -import { DataTableFrame } from "@/components/ui/data-table"; | 15 | +import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; |
| 16 | +import { DataToolbar } from "@/components/ui/data-toolbar"; | ||
| 15 | import { DatePicker } from "@/components/ui/date-picker"; | 17 | import { DatePicker } from "@/components/ui/date-picker"; |
| 16 | -import { ErrorAlert } from "@/components/ui/error-alert"; | 18 | +import { IconEdit, IconEye, IconTrash } from "@/components/ui/icons"; |
| 17 | -import { IconEdit, IconTrash } from "@/components/ui/icons"; | ||
| 18 | import { Input } from "@/components/ui/input"; | 19 | import { Input } from "@/components/ui/input"; |
| 19 | import { Label } from "@/components/ui/label"; | 20 | import { Label } from "@/components/ui/label"; |
| 20 | -import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 21 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 21 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 22 | import { SidePanel } from "@/components/ui/side-panel"; | 22 | import { SidePanel } from "@/components/ui/side-panel"; |
| 23 | import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; | 23 | import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; |
| 24 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 24 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 25 | +import { createDebounced } from "@/lib/debounced"; | ||
| 25 | import { formatDateTime, formatDurationMinutes } from "@/lib/format"; | 26 | import { formatDateTime, formatDurationMinutes } from "@/lib/format"; |
| 26 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; | 27 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; |
| 27 | import { personLabel } from "@/lib/person"; | 28 | import { personLabel } from "@/lib/person"; |
| 28 | import { usePreferences, useT } from "@/stores/preferences-context"; | 29 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 29 | 30 | ||
| 31 | +const PEOPLE_PAGE_SIZE = 12; | ||
| 30 | const WORK_PAGE_SIZE = 15; | 32 | const WORK_PAGE_SIZE = 15; |
| 33 | +const MIN_QUERY = 2; | ||
| 31 | 34 | ||
| 32 | function msToDateInput(ms: number): string { | 35 | function msToDateInput(ms: number): string { |
| 33 | const d = new Date(ms); | 36 | const d = new Date(ms); |
| @@ -57,6 +60,9 @@ function dateInputToMs(date: string, time: string): number | null { | |||
| 57 | return d.getTime(); | 60 | return d.getTime(); |
| 58 | } | 61 | } |
| 59 | 62 | ||
| 63 | +const emptyPeople: Page<PersonRef> = { items: [], total: 0, limit: null, offset: 0 }; | ||
| 64 | +const emptyEntries = { items: [] as WorkEntry[], total: 0 }; | ||
| 65 | + | ||
| 60 | export default function StaffWorkPage() { | 66 | export default function StaffWorkPage() { |
| 61 | return ( | 67 | return ( |
| 62 | <RouteGuard minRole="manager"> | 68 | <RouteGuard minRole="manager"> |
| @@ -68,11 +74,11 @@ export default function StaffWorkPage() { | |||
| 68 | function StaffWorkContent() { | 74 | function StaffWorkContent() { |
| 69 | const t = useT(); | 75 | const t = useT(); |
| 70 | const { locale } = usePreferences(); | 76 | const { locale } = usePreferences(); |
| 71 | - const [userId, setUserId] = createSignal(""); | 77 | + const [query, setQuery] = createSignal(""); |
| 72 | - const [selectedUser, setSelectedUser] = createSignal<PersonRef | null>(null); | 78 | + const debouncedQuery = createDebounced(query, 300); |
| 73 | - const [lookupId, setLookupId] = createSignal<string | null>(null); | ||
| 74 | - const [lookupLabel, setLookupLabel] = createSignal(""); | ||
| 75 | const [page, setPage] = createSignal(0); | 79 | const [page, setPage] = createSignal(0); |
| 80 | + const [viewUser, setViewUser] = createSignal<PersonRef | null>(null); | ||
| 81 | + const [entryPage, setEntryPage] = createSignal(0); | ||
| 76 | const [error, setError] = createSignal(""); | 82 | const [error, setError] = createSignal(""); |
| 77 | const [editTarget, setEditTarget] = createSignal<WorkEntry | null>(null); | 83 | const [editTarget, setEditTarget] = createSignal<WorkEntry | null>(null); |
| 78 | const [deleteTarget, setDeleteTarget] = createSignal<WorkEntry | null>(null); | 84 | const [deleteTarget, setDeleteTarget] = createSignal<WorkEntry | null>(null); |
| @@ -82,24 +88,70 @@ function StaffWorkContent() { | |||
| 82 | const [checkOutTime, setCheckOutTime] = createSignal(""); | 88 | const [checkOutTime, setCheckOutTime] = createSignal(""); |
| 83 | const [pending, setPending] = createSignal(false); | 89 | const [pending, setPending] = createSignal(false); |
| 84 | 90 | ||
| 85 | - const [list, { refetch }] = createResource( | 91 | + const searchKey = createMemo(() => { |
| 86 | - () => (lookupId() ? `${lookupId()}|${page()}` : null), | 92 | + const q = debouncedQuery().trim(); |
| 93 | + if (q.length < MIN_QUERY) return null; | ||
| 94 | + return `${q}|${page()}`; | ||
| 95 | + }); | ||
| 96 | + | ||
| 97 | + // initialValue prevents Suspense remount of the page (which steals input focus). | ||
| 98 | + const [people] = createResource( | ||
| 99 | + searchKey, | ||
| 100 | + async (key) => { | ||
| 101 | + try { | ||
| 102 | + const q = key.split("|")[0]!; | ||
| 103 | + return await getUserSearch(q, undefined, "teacher", { | ||
| 104 | + limit: PEOPLE_PAGE_SIZE, | ||
| 105 | + offset: page() * PEOPLE_PAGE_SIZE, | ||
| 106 | + }); | ||
| 107 | + } catch (err) { | ||
| 108 | + setError(formatApiError(err)); | ||
| 109 | + return emptyPeople; | ||
| 110 | + } | ||
| 111 | + }, | ||
| 112 | + { initialValue: emptyPeople }, | ||
| 113 | + ); | ||
| 114 | + | ||
| 115 | + const [entries, { refetch: refetchEntries }] = createResource( | ||
| 116 | + () => { | ||
| 117 | + const user = viewUser(); | ||
| 118 | + if (!user) return null; | ||
| 119 | + return `${user.id}|${entryPage()}`; | ||
| 120 | + }, | ||
| 87 | async (key) => { | 121 | async (key) => { |
| 88 | - if (!key) return { items: [] as WorkEntry[], total: 0 }; | 122 | + try { |
| 89 | - const id = key.split("|")[0]!; | 123 | + const id = key.split("|")[0]!; |
| 90 | - return loadListPage({ | 124 | + return await loadListPage({ |
| 91 | - page: page(), | 125 | + page: entryPage(), |
| 92 | - pageSize: WORK_PAGE_SIZE, | 126 | + pageSize: WORK_PAGE_SIZE, |
| 93 | - clientMode: false, | 127 | + clientMode: false, |
| 94 | - fetch: (params) => getUserWorkLog(id, params), | 128 | + fetch: (params) => getUserWorkLog(id, params), |
| 95 | - }); | 129 | + }); |
| 130 | + } catch (err) { | ||
| 131 | + if (err instanceof ApiError && err.status === 404) { | ||
| 132 | + setError(t("work.userNotFound")); | ||
| 133 | + return emptyEntries; | ||
| 134 | + } | ||
| 135 | + setError(formatApiError(err)); | ||
| 136 | + return emptyEntries; | ||
| 137 | + } | ||
| 96 | }, | 138 | }, |
| 139 | + { initialValue: emptyEntries }, | ||
| 97 | ); | 140 | ); |
| 98 | 141 | ||
| 99 | - const total = () => list()?.total ?? 0; | 142 | + const peopleTotal = () => people().total; |
| 100 | - const pageItems = () => list()?.items ?? []; | 143 | + const peopleRows = () => people().items; |
| 101 | - const totalPages = createMemo(() => pagesOf(total(), WORK_PAGE_SIZE)); | 144 | + const peoplePages = createMemo(() => pagesOf(peopleTotal(), PEOPLE_PAGE_SIZE)); |
| 102 | - const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | 145 | + const safePeoplePage = createMemo(() => Math.min(page(), peoplePages() - 1)); |
| 146 | + | ||
| 147 | + const entryTotal = () => entries().total; | ||
| 148 | + const entryRows = () => entries().items; | ||
| 149 | + const entryPages = createMemo(() => pagesOf(entryTotal(), WORK_PAGE_SIZE)); | ||
| 150 | + const safeEntryPage = createMemo(() => Math.min(entryPage(), entryPages() - 1)); | ||
| 151 | + | ||
| 152 | + const canSearch = () => debouncedQuery().trim().length >= MIN_QUERY; | ||
| 153 | + const hasPeople = () => peopleRows().length > 0; | ||
| 154 | + const peopleLoading = () => canSearch() && people.loading; | ||
| 103 | 155 | ||
| 104 | const startEdit = (entry: WorkEntry) => { | 156 | const startEdit = (entry: WorkEntry) => { |
| 105 | if (entry.check_out == null) { | 157 | if (entry.check_out == null) { |
| @@ -133,7 +185,7 @@ function StaffWorkContent() { | |||
| 133 | try { | 185 | try { |
| 134 | await patchWorkEntryById(entry.id, { check_in, check_out }); | 186 | await patchWorkEntryById(entry.id, { check_in, check_out }); |
| 135 | setEditTarget(null); | 187 | setEditTarget(null); |
| 136 | - await refetch(); | 188 | + await refetchEntries(); |
| 137 | } catch (err) { | 189 | } catch (err) { |
| 138 | setError(formatApiError(err)); | 190 | setError(formatApiError(err)); |
| 139 | } finally { | 191 | } finally { |
| @@ -153,57 +205,102 @@ function StaffWorkContent() { | |||
| 153 | </div> | 205 | </div> |
| 154 | 206 | ||
| 155 | <section class="data-shell space-y-4 p-4"> | 207 | <section class="data-shell space-y-4 p-4"> |
| 156 | - <form | 208 | + <div class="flex flex-wrap items-center justify-between gap-3"> |
| 157 | - class="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end" | 209 | + <div> |
| 158 | - onSubmit={(e) => { | 210 | + <h2 class="font-display text-lg font-semibold">{t("work.teacherIdentity")}</h2> |
| 159 | - e.preventDefault(); | 211 | + <p class="mt-1 text-sm text-muted-foreground"> |
| 160 | - const id = userId().trim(); | 212 | + {canSearch() ? `${peopleRows().length} / ${peopleTotal()}` : t("lookup.searchHint")} |
| 161 | - if (!id) return; | 213 | + </p> |
| 162 | - setLookupId(id); | 214 | + </div> |
| 163 | - setLookupLabel(personLabel(selectedUser()) === "—" ? id : personLabel(selectedUser())); | 215 | + </div> |
| 216 | + | ||
| 217 | + <DataToolbar | ||
| 218 | + searchValue={query()} | ||
| 219 | + searchPlaceholder={t("common.searchPlaceholder")} | ||
| 220 | + onSearchInput={(value) => { | ||
| 221 | + setError(""); | ||
| 222 | + setQuery(value); | ||
| 164 | setPage(0); | 223 | setPage(0); |
| 165 | }} | 224 | }} |
| 166 | - > | 225 | + /> |
| 167 | - <UserSearchSelect | 226 | + |
| 168 | - id="staff-work-user" | 227 | + <Show when={error() && !viewUser() && !editTarget()}> |
| 169 | - label={t("work.teacherIdentity")} | ||
| 170 | - value={userId()} | ||
| 171 | - onChange={setUserId} | ||
| 172 | - onSelectUser={setSelectedUser} | ||
| 173 | - placeholder={t("common.searchPlaceholder")} | ||
| 174 | - selectPlaceholder={t("work.teacherIdentity")} | ||
| 175 | - emptyMessage={t("work.noTeachers")} | ||
| 176 | - allowManualValue | ||
| 177 | - role={["teacher", "manager", "admin"]} | ||
| 178 | - /> | ||
| 179 | - <Button type="submit" class="h-9 w-full rounded-lg sm:w-auto"> | ||
| 180 | - {t("work.show")} | ||
| 181 | - </Button> | ||
| 182 | - </form> | ||
| 183 | - <Show when={error() && !editTarget()}> | ||
| 184 | <Alert variant="destructive">{error()}</Alert> | 228 | <Alert variant="destructive">{error()}</Alert> |
| 185 | </Show> | 229 | </Show> |
| 186 | - </section> | ||
| 187 | 230 | ||
| 188 | - <Show when={lookupId()}> | 231 | + <Show when={canSearch()} fallback={<DataTableEmpty>{t("lookup.searchHint")}</DataTableEmpty>}> |
| 189 | - <section class="data-shell space-y-4 p-4"> | 232 | + <Show when={!peopleLoading()} fallback={<DataTableSkeleton columns={4} rows={6} />}> |
| 190 | - <div class="flex flex-wrap items-center justify-between gap-2"> | 233 | + <Show when={hasPeople()} fallback={<DataTableEmpty>{t("work.noTeachers")}</DataTableEmpty>}> |
| 191 | - <div> | 234 | + <DataTableFrame> |
| 192 | - <h2 class="font-display text-lg font-semibold">{t("work.entries")}</h2> | 235 | + <Table class="data-table min-w-[36rem]"> |
| 193 | - <p class="mt-1 text-sm text-muted-foreground">{t("work.forUser", { user: lookupLabel() || lookupId() || "" })}</p> | 236 | + <TableHeader> |
| 194 | - </div> | 237 | + <TableRow> |
| 195 | - <Badge variant="secondary" class="mono rounded-sm px-3 py-1"> | 238 | + <TableHead>{t("admin.username")}</TableHead> |
| 196 | - {total()} | 239 | + <TableHead>{t("profile.name")}</TableHead> |
| 197 | - </Badge> | 240 | + <TableHead>{t("admin.id")}</TableHead> |
| 198 | - </div> | 241 | + <TableHead class="w-14 text-center">{t("common.actions")}</TableHead> |
| 199 | - <Suspense fallback={<PageSpinner />}> | 242 | + </TableRow> |
| 200 | - <Show when={list.error}> | 243 | + </TableHeader> |
| 201 | - <ErrorAlert message={formatApiError(list.error)} onRetry={() => void refetch()} /> | 244 | + <TableBody> |
| 245 | + <For each={peopleRows()}> | ||
| 246 | + {(user) => ( | ||
| 247 | + <TableRow> | ||
| 248 | + <TableCell class="font-medium">{user.username}</TableCell> | ||
| 249 | + <TableCell class="text-muted-foreground">{user.display_name || "—"}</TableCell> | ||
| 250 | + <TableCell class="mono text-xs text-muted-foreground">{user.id}</TableCell> | ||
| 251 | + <TableCell> | ||
| 252 | + <TableRowActions | ||
| 253 | + label={t("common.actions")} | ||
| 254 | + actions={[ | ||
| 255 | + { | ||
| 256 | + label: t("common.view"), | ||
| 257 | + icon: <IconEye class="h-4 w-4" />, | ||
| 258 | + onSelect: () => { | ||
| 259 | + setError(""); | ||
| 260 | + setEntryPage(0); | ||
| 261 | + setViewUser(user); | ||
| 262 | + }, | ||
| 263 | + }, | ||
| 264 | + ]} | ||
| 265 | + /> | ||
| 266 | + </TableCell> | ||
| 267 | + </TableRow> | ||
| 268 | + )} | ||
| 269 | + </For> | ||
| 270 | + </TableBody> | ||
| 271 | + </Table> | ||
| 272 | + </DataTableFrame> | ||
| 273 | + <Show when={peopleTotal() > PEOPLE_PAGE_SIZE}> | ||
| 274 | + <PaginationControls page={safePeoplePage()} totalPages={peoplePages()} onPageChange={setPage} /> | ||
| 275 | + </Show> | ||
| 202 | </Show> | 276 | </Show> |
| 203 | - <Show | 277 | + </Show> |
| 204 | - when={pageItems().length > 0} | 278 | + </Show> |
| 205 | - fallback={<div class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground">{t("work.empty")}</div>} | 279 | + </section> |
| 206 | - > | 280 | + |
| 281 | + <SidePanel | ||
| 282 | + size="wide" | ||
| 283 | + open={viewUser() != null} | ||
| 284 | + onOpenChange={(open) => { | ||
| 285 | + if (!open) { | ||
| 286 | + setViewUser(null); | ||
| 287 | + setError(""); | ||
| 288 | + } | ||
| 289 | + }} | ||
| 290 | + title={t("work.forUser", { user: personLabel(viewUser()) })} | ||
| 291 | + description={t("work.entries")} | ||
| 292 | + > | ||
| 293 | + <Show when={error() && !editTarget()}> | ||
| 294 | + <Alert variant="destructive" class="mb-3"> | ||
| 295 | + {error()} | ||
| 296 | + </Alert> | ||
| 297 | + </Show> | ||
| 298 | + <Show when={!entries.loading} fallback={<DataTableSkeleton columns={5} rows={4} />}> | ||
| 299 | + <Show | ||
| 300 | + when={entryRows().length > 0} | ||
| 301 | + fallback={<div class="rounded-lg border border-dashed px-4 py-8 text-center text-sm text-muted-foreground">{t("work.empty")}</div>} | ||
| 302 | + > | ||
| 303 | + <div class="space-y-3"> | ||
| 207 | <DataTableFrame> | 304 | <DataTableFrame> |
| 208 | <Table class="data-table"> | 305 | <Table class="data-table"> |
| 209 | <TableHeader> | 306 | <TableHeader> |
| @@ -216,12 +313,12 @@ function StaffWorkContent() { | |||
| 216 | </TableRow> | 313 | </TableRow> |
| 217 | </TableHeader> | 314 | </TableHeader> |
| 218 | <TableBody> | 315 | <TableBody> |
| 219 | - <For each={pageItems()}> | 316 | + <For each={entryRows()}> |
| 220 | {(entry) => ( | 317 | {(entry) => ( |
| 221 | <TableRow> | 318 | <TableRow> |
| 222 | - <TableCell class="mono">{formatDateTime(entry.check_in, locale())}</TableCell> | 319 | + <TableCell class="mono text-xs">{formatDateTime(entry.check_in, locale())}</TableCell> |
| 223 | - <TableCell class="mono">{formatDateTime(entry.check_out, locale())}</TableCell> | 320 | + <TableCell class="mono text-xs">{formatDateTime(entry.check_out, locale())}</TableCell> |
| 224 | - <TableCell class="mono">{formatDurationMinutes(entry.duration_ms, locale())}</TableCell> | 321 | + <TableCell class="mono text-xs">{formatDurationMinutes(entry.duration_ms, locale())}</TableCell> |
| 225 | <TableCell> | 322 | <TableCell> |
| 226 | <Badge variant={entry.check_out == null ? "default" : "secondary"} class="rounded-sm"> | 323 | <Badge variant={entry.check_out == null ? "default" : "secondary"} class="rounded-sm"> |
| 227 | {entry.check_out == null ? t("work.open") : t("work.closed")} | 324 | {entry.check_out == null ? t("work.open") : t("work.closed")} |
| @@ -252,13 +349,13 @@ function StaffWorkContent() { | |||
| 252 | </TableBody> | 349 | </TableBody> |
| 253 | </Table> | 350 | </Table> |
| 254 | </DataTableFrame> | 351 | </DataTableFrame> |
| 255 | - <Show when={total() > WORK_PAGE_SIZE}> | 352 | + <Show when={entryTotal() > WORK_PAGE_SIZE}> |
| 256 | - <PaginationControls page={safePage()} totalPages={totalPages()} onPageChange={setPage} /> | 353 | + <PaginationControls page={safeEntryPage()} totalPages={entryPages()} onPageChange={setEntryPage} /> |
| 257 | </Show> | 354 | </Show> |
| 258 | - </Show> | 355 | + </div> |
| 259 | - </Suspense> | 356 | + </Show> |
| 260 | - </section> | 357 | + </Show> |
| 261 | - </Show> | 358 | + </SidePanel> |
| 262 | 359 | ||
| 263 | <SidePanel | 360 | <SidePanel |
| 264 | open={editTarget() != null} | 361 | open={editTarget() != null} |
| @@ -293,7 +390,7 @@ function StaffWorkContent() { | |||
| 293 | <Button type="button" variant="outline" class="h-10 rounded-lg" onClick={() => setEditTarget(null)}> | 390 | <Button type="button" variant="outline" class="h-10 rounded-lg" onClick={() => setEditTarget(null)}> |
| 294 | {t("common.cancel")} | 391 | {t("common.cancel")} |
| 295 | </Button> | 392 | </Button> |
| 296 | - <Button type="submit" class="h-10 rounded-lg" disabled={pending()}> | 393 | + <Button type="submit" class="h-10 rounded-lg" disabled={pending() || !checkInDate().trim() || !checkInTime().trim() || !checkOutDate().trim() || !checkOutTime().trim()}> |
| 297 | {t("common.update")} | 394 | {t("common.update")} |
| 298 | </Button> | 395 | </Button> |
| 299 | </div> | 396 | </div> |
| @@ -313,7 +410,7 @@ function StaffWorkContent() { | |||
| 313 | if (!entry) return; | 410 | if (!entry) return; |
| 314 | try { | 411 | try { |
| 315 | await deleteWorkEntryById(entry.id); | 412 | await deleteWorkEntryById(entry.id); |
| 316 | - await refetch(); | 413 | + await refetchEntries(); |
| 317 | } catch (err) { | 414 | } catch (err) { |
| 318 | setError(formatApiError(err)); | 415 | setError(formatApiError(err)); |
| 319 | } finally { | 416 | } finally { |
src/pages/student-attendance-page.tsxmodified+165 -53
| @@ -1,17 +1,30 @@ | |||
| 1 | -import { Show, Suspense, createResource, createSignal } from "solid-js"; | 1 | +import { For, Show, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | import { getUserAttendance } from "@/api/getUserAttendance"; | 2 | import { getUserAttendance } from "@/api/getUserAttendance"; |
| 3 | -import { formatApiError } from "@/api/client"; | 3 | +import { getUserSearch } from "@/api/getUserSearch"; |
| 4 | +import { ApiError, formatApiError } from "@/api/client"; | ||
| 5 | +import type { Page } from "@/api/page"; | ||
| 4 | import type { PersonRef } from "@/api/types"; | 6 | import type { PersonRef } from "@/api/types"; |
| 5 | import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; | 7 | import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; |
| 6 | import { RouteGuard } from "@/components/layout/route-guard"; | 8 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 7 | import { PageHeader } from "@/components/layout/page-header"; | 9 | import { PageHeader } from "@/components/layout/page-header"; |
| 8 | -import { UserSearchSelect } from "@/components/users/user-search-select"; | 10 | +import { Alert } from "@/components/ui/alert"; |
| 9 | -import { Button } from "@/components/ui/button"; | 11 | +import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; |
| 12 | +import { DataToolbar } from "@/components/ui/data-toolbar"; | ||
| 10 | import { ErrorAlert } from "@/components/ui/error-alert"; | 13 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 11 | -import { PageSpinner } from "@/components/ui/page-spinner"; | 14 | +import { IconEye } from "@/components/ui/icons"; |
| 15 | +import { PaginationControls } from "@/components/ui/pagination-controls"; | ||
| 16 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 17 | +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; | ||
| 18 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 19 | +import { createDebounced } from "@/lib/debounced"; | ||
| 20 | +import { totalPages as pagesOf } from "@/lib/list-page"; | ||
| 12 | import { personLabel } from "@/lib/person"; | 21 | import { personLabel } from "@/lib/person"; |
| 13 | import { useT } from "@/stores/preferences-context"; | 22 | import { useT } from "@/stores/preferences-context"; |
| 14 | 23 | ||
| 24 | +const PAGE_SIZE = 12; | ||
| 25 | +const MIN_QUERY = 2; | ||
| 26 | +const emptyPage: Page<PersonRef> = { items: [], total: 0, limit: null, offset: 0 }; | ||
| 27 | + | ||
| 15 | export default function StudentAttendancePage() { | 28 | export default function StudentAttendancePage() { |
| 16 | return ( | 29 | return ( |
| 17 | <RouteGuard minRole="teacher"> | 30 | <RouteGuard minRole="teacher"> |
| @@ -22,66 +35,165 @@ export default function StudentAttendancePage() { | |||
| 22 | 35 | ||
| 23 | function StudentAttendanceContent() { | 36 | function StudentAttendanceContent() { |
| 24 | const t = useT(); | 37 | const t = useT(); |
| 25 | - const [userId, setUserId] = createSignal(""); | 38 | + const [query, setQuery] = createSignal(""); |
| 26 | - const [selectedUser, setSelectedUser] = createSignal<PersonRef | null>(null); | 39 | + const debouncedQuery = createDebounced(query, 300); |
| 27 | - const [lookupId, setLookupId] = createSignal<string | null>(null); | 40 | + const [page, setPage] = createSignal(0); |
| 28 | - const [lookupLabel, setLookupLabel] = createSignal(""); | 41 | + const [viewUser, setViewUser] = createSignal<PersonRef | null>(null); |
| 29 | - const [report, { refetch }] = createResource(lookupId, async (id) => { | 42 | + const [error, setError] = createSignal(""); |
| 30 | - if (!id) return null; | 43 | + |
| 31 | - return getUserAttendance(id); | 44 | + const searchKey = createMemo(() => { |
| 45 | + const q = debouncedQuery().trim(); | ||
| 46 | + if (q.length < MIN_QUERY) return null; | ||
| 47 | + return `${q}|${page()}`; | ||
| 32 | }); | 48 | }); |
| 33 | 49 | ||
| 50 | + const [list] = createResource( | ||
| 51 | + searchKey, | ||
| 52 | + async (key) => { | ||
| 53 | + try { | ||
| 54 | + const q = key.split("|")[0]!; | ||
| 55 | + return await getUserSearch(q, undefined, "student", { | ||
| 56 | + limit: PAGE_SIZE, | ||
| 57 | + offset: page() * PAGE_SIZE, | ||
| 58 | + }); | ||
| 59 | + } catch (err) { | ||
| 60 | + setError(formatApiError(err)); | ||
| 61 | + return emptyPage; | ||
| 62 | + } | ||
| 63 | + }, | ||
| 64 | + { initialValue: emptyPage }, | ||
| 65 | + ); | ||
| 66 | + | ||
| 67 | + const [report, { refetch: refetchReport }] = createResource( | ||
| 68 | + () => viewUser()?.id ?? null, | ||
| 69 | + async (id) => { | ||
| 70 | + if (!id) return null; | ||
| 71 | + try { | ||
| 72 | + return await getUserAttendance(id); | ||
| 73 | + } catch (err) { | ||
| 74 | + if (err instanceof ApiError && err.status === 404) { | ||
| 75 | + setError(t("common.notFound")); | ||
| 76 | + return null; | ||
| 77 | + } | ||
| 78 | + setError(formatApiError(err)); | ||
| 79 | + return null; | ||
| 80 | + } | ||
| 81 | + }, | ||
| 82 | + ); | ||
| 83 | + | ||
| 84 | + const total = () => list().total; | ||
| 85 | + const rows = () => list().items; | ||
| 86 | + const totalPages = createMemo(() => pagesOf(total(), PAGE_SIZE)); | ||
| 87 | + const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | ||
| 88 | + const canSearch = () => debouncedQuery().trim().length >= MIN_QUERY; | ||
| 89 | + const listLoading = () => canSearch() && list.loading; | ||
| 90 | + | ||
| 34 | return ( | 91 | return ( |
| 35 | <div class="space-y-6"> | 92 | <div class="space-y-6"> |
| 36 | - <PageHeader accent="sky" eyebrow={t("nav.admin")} title={t("nav.studentAttendance")} description={t("attendance.lookup")} /> | 93 | + <div class="space-y-2"> |
| 94 | + <div class="flex flex-wrap items-center gap-1 text-xs text-muted-foreground"> | ||
| 95 | + <span>{t("nav.admin")}</span> | ||
| 96 | + <span>/</span> | ||
| 97 | + <span>{t("nav.studentAttendance")}</span> | ||
| 98 | + </div> | ||
| 99 | + <PageHeader accent="sky" eyebrow={t("nav.admin")} title={t("nav.studentAttendance")} description={t("attendance.lookup")} /> | ||
| 100 | + </div> | ||
| 37 | 101 | ||
| 38 | <section class="data-shell space-y-4 p-4"> | 102 | <section class="data-shell space-y-4 p-4"> |
| 39 | - <div> | 103 | + <div class="flex flex-wrap items-center justify-between gap-3"> |
| 40 | - <h2 class="font-display text-lg font-semibold">{t("nav.studentAttendance")}</h2> | 104 | + <div> |
| 41 | - <p class="mt-1 text-sm text-muted-foreground">{t("attendance.lookup")}</p> | 105 | + <h2 class="font-display text-lg font-semibold">{t("nav.studentAttendance")}</h2> |
| 106 | + <p class="mt-1 text-sm text-muted-foreground"> | ||
| 107 | + {canSearch() ? `${rows().length} / ${total()}` : t("lookup.searchHint")} | ||
| 108 | + </p> | ||
| 109 | + </div> | ||
| 42 | </div> | 110 | </div> |
| 43 | - <form | 111 | + |
| 44 | - class="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end" | 112 | + <DataToolbar |
| 45 | - onSubmit={(e) => { | 113 | + searchValue={query()} |
| 46 | - e.preventDefault(); | 114 | + searchPlaceholder={t("common.searchPlaceholder")} |
| 47 | - const id = userId().trim(); | 115 | + onSearchInput={(value) => { |
| 48 | - if (!id) return; | 116 | + setError(""); |
| 49 | - setLookupId(id); | 117 | + setQuery(value); |
| 50 | - setLookupLabel(personLabel(selectedUser()) === "—" ? id : personLabel(selectedUser())); | 118 | + setPage(0); |
| 51 | }} | 119 | }} |
| 52 | - > | 120 | + /> |
| 53 | - <UserSearchSelect | ||
| 54 | - id="student-attendance-user" | ||
| 55 | - label={t("marks.userIdentity")} | ||
| 56 | - value={userId()} | ||
| 57 | - onChange={setUserId} | ||
| 58 | - onSelectUser={setSelectedUser} | ||
| 59 | - placeholder={t("common.searchPlaceholder")} | ||
| 60 | - selectPlaceholder={t("marks.userIdentity")} | ||
| 61 | - emptyMessage={t("form.noStudents")} | ||
| 62 | - allowManualValue | ||
| 63 | - role="student" | ||
| 64 | - /> | ||
| 65 | - <Button type="submit" class="h-9 w-full rounded-lg sm:w-auto">{t("attendance.show")}</Button> | ||
| 66 | - </form> | ||
| 67 | 121 | ||
| 68 | - <Show when={report.error}> | 122 | + <Show when={error() && !viewUser()}> |
| 69 | - <ErrorAlert message={formatApiError(report.error)} onRetry={() => void refetch()} /> | 123 | + <Alert variant="destructive">{error()}</Alert> |
| 70 | </Show> | 124 | </Show> |
| 71 | - </section> | ||
| 72 | 125 | ||
| 73 | - <Suspense fallback={<PageSpinner />}> | 126 | + <Show when={canSearch()} fallback={<DataTableEmpty>{t("lookup.searchHint")}</DataTableEmpty>}> |
| 74 | - <Show when={report()}> | 127 | + <Show when={!listLoading()} fallback={<DataTableSkeleton columns={4} rows={6} />}> |
| 75 | - {(r) => ( | 128 | + <Show when={rows().length > 0} fallback={<DataTableEmpty>{t("form.noStudents")}</DataTableEmpty>}> |
| 76 | - <div class="space-y-4"> | 129 | + <DataTableFrame> |
| 77 | - <p class="data-shell px-4 py-3 text-sm text-muted-foreground"> | 130 | + <Table class="data-table min-w-[36rem]"> |
| 78 | - {t("attendance.forUser", { user: lookupLabel() || lookupId() || "" })} | 131 | + <TableHeader> |
| 79 | - </p> | 132 | + <TableRow> |
| 80 | - <AttendanceReportView report={r()} /> | 133 | + <TableHead>{t("admin.username")}</TableHead> |
| 81 | - </div> | 134 | + <TableHead>{t("profile.name")}</TableHead> |
| 82 | - )} | 135 | + <TableHead>{t("admin.id")}</TableHead> |
| 136 | + <TableHead class="w-14 text-center">{t("common.actions")}</TableHead> | ||
| 137 | + </TableRow> | ||
| 138 | + </TableHeader> | ||
| 139 | + <TableBody> | ||
| 140 | + <For each={rows()}> | ||
| 141 | + {(user) => ( | ||
| 142 | + <TableRow> | ||
| 143 | + <TableCell class="font-medium">{user.username}</TableCell> | ||
| 144 | + <TableCell class="text-muted-foreground">{user.display_name || "—"}</TableCell> | ||
| 145 | + <TableCell class="mono text-xs text-muted-foreground">{user.id}</TableCell> | ||
| 146 | + <TableCell> | ||
| 147 | + <TableRowActions | ||
| 148 | + label={t("common.actions")} | ||
| 149 | + actions={[ | ||
| 150 | + { | ||
| 151 | + label: t("common.view"), | ||
| 152 | + icon: <IconEye class="h-4 w-4" />, | ||
| 153 | + onSelect: () => { | ||
| 154 | + setError(""); | ||
| 155 | + setViewUser(user); | ||
| 156 | + }, | ||
| 157 | + }, | ||
| 158 | + ]} | ||
| 159 | + /> | ||
| 160 | + </TableCell> | ||
| 161 | + </TableRow> | ||
| 162 | + )} | ||
| 163 | + </For> | ||
| 164 | + </TableBody> | ||
| 165 | + </Table> | ||
| 166 | + </DataTableFrame> | ||
| 167 | + <Show when={total() > PAGE_SIZE}> | ||
| 168 | + <PaginationControls page={safePage()} totalPages={totalPages()} onPageChange={setPage} /> | ||
| 169 | + </Show> | ||
| 170 | + </Show> | ||
| 171 | + </Show> | ||
| 83 | </Show> | 172 | </Show> |
| 84 | - </Suspense> | 173 | + </section> |
| 174 | + | ||
| 175 | + <SidePanel | ||
| 176 | + size="wide" | ||
| 177 | + open={viewUser() != null} | ||
| 178 | + onOpenChange={(open) => { | ||
| 179 | + if (!open) { | ||
| 180 | + setViewUser(null); | ||
| 181 | + setError(""); | ||
| 182 | + } | ||
| 183 | + }} | ||
| 184 | + title={t("attendance.forUser", { user: personLabel(viewUser()) })} | ||
| 185 | + description={t("attendance.lookup")} | ||
| 186 | + > | ||
| 187 | + <div class="min-w-0 space-y-3"> | ||
| 188 | + <Show when={error()}> | ||
| 189 | + <ErrorAlert message={error()} onRetry={() => void refetchReport()} /> | ||
| 190 | + </Show> | ||
| 191 | + <Show when={report.loading}> | ||
| 192 | + <p class="text-sm text-muted-foreground">{t("common.loading")}</p> | ||
| 193 | + </Show> | ||
| 194 | + <Show when={report()}>{(r) => <AttendanceReportView report={r()} compact />}</Show> | ||
| 195 | + </div> | ||
| 196 | + </SidePanel> | ||
| 85 | </div> | 197 | </div> |
| 86 | ); | 198 | ); |
| 87 | } | 199 | } |
src/pages/student-marks-page.tsxmodified+165 -58
| @@ -1,17 +1,30 @@ | |||
| 1 | -import { Show, Suspense, createResource, createSignal } from "solid-js"; | 1 | +import { For, Show, createMemo, createResource, createSignal } from "solid-js"; |
| 2 | import { getUserMarks } from "@/api/getUserMarks"; | 2 | import { getUserMarks } from "@/api/getUserMarks"; |
| 3 | -import { formatApiError } from "@/api/client"; | 3 | +import { getUserSearch } from "@/api/getUserSearch"; |
| 4 | +import { ApiError, formatApiError } from "@/api/client"; | ||
| 5 | +import type { Page } from "@/api/page"; | ||
| 4 | import type { PersonRef } from "@/api/types"; | 6 | import type { PersonRef } from "@/api/types"; |
| 5 | import { MarksReportView } from "@/components/marks/marks-report-view"; | 7 | import { MarksReportView } from "@/components/marks/marks-report-view"; |
| 6 | import { RouteGuard } from "@/components/layout/route-guard"; | 8 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 7 | import { PageHeader } from "@/components/layout/page-header"; | 9 | import { PageHeader } from "@/components/layout/page-header"; |
| 8 | -import { UserSearchSelect } from "@/components/users/user-search-select"; | 10 | +import { Alert } from "@/components/ui/alert"; |
| 9 | -import { Button } from "@/components/ui/button"; | 11 | +import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; |
| 12 | +import { DataToolbar } from "@/components/ui/data-toolbar"; | ||
| 10 | import { ErrorAlert } from "@/components/ui/error-alert"; | 13 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 11 | -import { PageSpinner } from "@/components/ui/page-spinner"; | 14 | +import { IconEye } from "@/components/ui/icons"; |
| 15 | +import { PaginationControls } from "@/components/ui/pagination-controls"; | ||
| 16 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 17 | +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; | ||
| 18 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 19 | +import { createDebounced } from "@/lib/debounced"; | ||
| 20 | +import { totalPages as pagesOf } from "@/lib/list-page"; | ||
| 12 | import { personLabel } from "@/lib/person"; | 21 | import { personLabel } from "@/lib/person"; |
| 13 | import { useT } from "@/stores/preferences-context"; | 22 | import { useT } from "@/stores/preferences-context"; |
| 14 | 23 | ||
| 24 | +const PAGE_SIZE = 12; | ||
| 25 | +const MIN_QUERY = 2; | ||
| 26 | +const emptyPage: Page<PersonRef> = { items: [], total: 0, limit: null, offset: 0 }; | ||
| 27 | + | ||
| 15 | export default function StudentMarksPage() { | 28 | export default function StudentMarksPage() { |
| 16 | return ( | 29 | return ( |
| 17 | <RouteGuard minRole="teacher"> | 30 | <RouteGuard minRole="teacher"> |
| @@ -22,71 +35,165 @@ export default function StudentMarksPage() { | |||
| 22 | 35 | ||
| 23 | function StudentMarksContent() { | 36 | function StudentMarksContent() { |
| 24 | const t = useT(); | 37 | const t = useT(); |
| 25 | - const [userId, setUserId] = createSignal(""); | 38 | + const [query, setQuery] = createSignal(""); |
| 26 | - const [selectedUser, setSelectedUser] = createSignal<PersonRef | null>(null); | 39 | + const debouncedQuery = createDebounced(query, 300); |
| 27 | - const [lookupId, setLookupId] = createSignal<string | null>(null); | 40 | + const [page, setPage] = createSignal(0); |
| 28 | - const [lookupLabel, setLookupLabel] = createSignal(""); | 41 | + const [viewUser, setViewUser] = createSignal<PersonRef | null>(null); |
| 29 | - const [report, { refetch }] = createResource(lookupId, async (id) => { | 42 | + const [error, setError] = createSignal(""); |
| 30 | - if (!id) return null; | 43 | + |
| 31 | - return getUserMarks(id); | 44 | + const searchKey = createMemo(() => { |
| 45 | + const q = debouncedQuery().trim(); | ||
| 46 | + if (q.length < MIN_QUERY) return null; | ||
| 47 | + return `${q}|${page()}`; | ||
| 32 | }); | 48 | }); |
| 33 | 49 | ||
| 50 | + const [list] = createResource( | ||
| 51 | + searchKey, | ||
| 52 | + async (key) => { | ||
| 53 | + try { | ||
| 54 | + const q = key.split("|")[0]!; | ||
| 55 | + return await getUserSearch(q, undefined, "student", { | ||
| 56 | + limit: PAGE_SIZE, | ||
| 57 | + offset: page() * PAGE_SIZE, | ||
| 58 | + }); | ||
| 59 | + } catch (err) { | ||
| 60 | + setError(formatApiError(err)); | ||
| 61 | + return emptyPage; | ||
| 62 | + } | ||
| 63 | + }, | ||
| 64 | + { initialValue: emptyPage }, | ||
| 65 | + ); | ||
| 66 | + | ||
| 67 | + const [report, { refetch: refetchReport }] = createResource( | ||
| 68 | + () => viewUser()?.id ?? null, | ||
| 69 | + async (id) => { | ||
| 70 | + if (!id) return null; | ||
| 71 | + try { | ||
| 72 | + return await getUserMarks(id); | ||
| 73 | + } catch (err) { | ||
| 74 | + if (err instanceof ApiError && err.status === 404) { | ||
| 75 | + setError(t("common.notFound")); | ||
| 76 | + return null; | ||
| 77 | + } | ||
| 78 | + setError(formatApiError(err)); | ||
| 79 | + return null; | ||
| 80 | + } | ||
| 81 | + }, | ||
| 82 | + ); | ||
| 83 | + | ||
| 84 | + const total = () => list().total; | ||
| 85 | + const rows = () => list().items; | ||
| 86 | + const totalPages = createMemo(() => pagesOf(total(), PAGE_SIZE)); | ||
| 87 | + const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | ||
| 88 | + const canSearch = () => debouncedQuery().trim().length >= MIN_QUERY; | ||
| 89 | + const listLoading = () => canSearch() && list.loading; | ||
| 90 | + | ||
| 34 | return ( | 91 | return ( |
| 35 | <div class="space-y-6"> | 92 | <div class="space-y-6"> |
| 36 | - <PageHeader | 93 | + <div class="space-y-2"> |
| 37 | - accent="violet" | 94 | + <div class="flex flex-wrap items-center gap-1 text-xs text-muted-foreground"> |
| 38 | - eyebrow={t("nav.admin")} | 95 | + <span>{t("nav.admin")}</span> |
| 39 | - title={t("nav.studentMarks")} | 96 | + <span>/</span> |
| 40 | - description={t("marks.lookup")} | 97 | + <span>{t("nav.studentMarks")}</span> |
| 41 | - /> | 98 | + </div> |
| 99 | + <PageHeader accent="violet" eyebrow={t("nav.admin")} title={t("nav.studentMarks")} description={t("marks.lookup")} /> | ||
| 100 | + </div> | ||
| 42 | 101 | ||
| 43 | <section class="data-shell space-y-4 p-4"> | 102 | <section class="data-shell space-y-4 p-4"> |
| 44 | - <div> | 103 | + <div class="flex flex-wrap items-center justify-between gap-3"> |
| 45 | - <h2 class="font-display text-lg font-semibold">{t("nav.studentMarks")}</h2> | 104 | + <div> |
| 46 | - <p class="mt-1 text-sm text-muted-foreground">{t("marks.lookup")}</p> | 105 | + <h2 class="font-display text-lg font-semibold">{t("nav.studentMarks")}</h2> |
| 106 | + <p class="mt-1 text-sm text-muted-foreground"> | ||
| 107 | + {canSearch() ? `${rows().length} / ${total()}` : t("lookup.searchHint")} | ||
| 108 | + </p> | ||
| 109 | + </div> | ||
| 47 | </div> | 110 | </div> |
| 48 | - <form | 111 | + |
| 49 | - class="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end" | 112 | + <DataToolbar |
| 50 | - onSubmit={(e) => { | 113 | + searchValue={query()} |
| 51 | - e.preventDefault(); | 114 | + searchPlaceholder={t("common.searchPlaceholder")} |
| 52 | - const id = userId().trim(); | 115 | + onSearchInput={(value) => { |
| 53 | - if (!id) return; | 116 | + setError(""); |
| 54 | - setLookupId(id); | 117 | + setQuery(value); |
| 55 | - setLookupLabel(personLabel(selectedUser()) === "—" ? id : personLabel(selectedUser())); | 118 | + setPage(0); |
| 56 | }} | 119 | }} |
| 57 | - > | 120 | + /> |
| 58 | - <UserSearchSelect | ||
| 59 | - id="student-marks-user" | ||
| 60 | - label={t("marks.userIdentity")} | ||
| 61 | - value={userId()} | ||
| 62 | - onChange={setUserId} | ||
| 63 | - onSelectUser={setSelectedUser} | ||
| 64 | - placeholder={t("common.searchPlaceholder")} | ||
| 65 | - selectPlaceholder={t("marks.userIdentity")} | ||
| 66 | - emptyMessage={t("form.noStudents")} | ||
| 67 | - allowManualValue | ||
| 68 | - role="student" | ||
| 69 | - /> | ||
| 70 | - <Button type="submit" class="h-9 w-full rounded-lg sm:w-auto">{t("marks.show")}</Button> | ||
| 71 | - </form> | ||
| 72 | 121 | ||
| 73 | - <Show when={report.error}> | 122 | + <Show when={error() && !viewUser()}> |
| 74 | - <ErrorAlert message={formatApiError(report.error)} onRetry={() => void refetch()} /> | 123 | + <Alert variant="destructive">{error()}</Alert> |
| 75 | </Show> | 124 | </Show> |
| 76 | - </section> | ||
| 77 | 125 | ||
| 78 | - <Suspense fallback={<PageSpinner />}> | 126 | + <Show when={canSearch()} fallback={<DataTableEmpty>{t("lookup.searchHint")}</DataTableEmpty>}> |
| 79 | - <Show when={report()}> | 127 | + <Show when={!listLoading()} fallback={<DataTableSkeleton columns={4} rows={6} />}> |
| 80 | - {(r) => ( | 128 | + <Show when={rows().length > 0} fallback={<DataTableEmpty>{t("form.noStudents")}</DataTableEmpty>}> |
| 81 | - <div class="space-y-4"> | 129 | + <DataTableFrame> |
| 82 | - <p class="data-shell px-4 py-3 text-sm text-muted-foreground"> | 130 | + <Table class="data-table min-w-[36rem]"> |
| 83 | - {t("marks.forUser", { user: lookupLabel() || lookupId() || "" })} | 131 | + <TableHeader> |
| 84 | - </p> | 132 | + <TableRow> |
| 85 | - <MarksReportView report={r()} /> | 133 | + <TableHead>{t("admin.username")}</TableHead> |
| 86 | - </div> | 134 | + <TableHead>{t("profile.name")}</TableHead> |
| 87 | - )} | 135 | + <TableHead>{t("admin.id")}</TableHead> |
| 136 | + <TableHead class="w-14 text-center">{t("common.actions")}</TableHead> | ||
| 137 | + </TableRow> | ||
| 138 | + </TableHeader> | ||
| 139 | + <TableBody> | ||
| 140 | + <For each={rows()}> | ||
| 141 | + {(user) => ( | ||
| 142 | + <TableRow> | ||
| 143 | + <TableCell class="font-medium">{user.username}</TableCell> | ||
| 144 | + <TableCell class="text-muted-foreground">{user.display_name || "—"}</TableCell> | ||
| 145 | + <TableCell class="mono text-xs text-muted-foreground">{user.id}</TableCell> | ||
| 146 | + <TableCell> | ||
| 147 | + <TableRowActions | ||
| 148 | + label={t("common.actions")} | ||
| 149 | + actions={[ | ||
| 150 | + { | ||
| 151 | + label: t("common.view"), | ||
| 152 | + icon: <IconEye class="h-4 w-4" />, | ||
| 153 | + onSelect: () => { | ||
| 154 | + setError(""); | ||
| 155 | + setViewUser(user); | ||
| 156 | + }, | ||
| 157 | + }, | ||
| 158 | + ]} | ||
| 159 | + /> | ||
| 160 | + </TableCell> | ||
| 161 | + </TableRow> | ||
| 162 | + )} | ||
| 163 | + </For> | ||
| 164 | + </TableBody> | ||
| 165 | + </Table> | ||
| 166 | + </DataTableFrame> | ||
| 167 | + <Show when={total() > PAGE_SIZE}> | ||
| 168 | + <PaginationControls page={safePage()} totalPages={totalPages()} onPageChange={setPage} /> | ||
| 169 | + </Show> | ||
| 170 | + </Show> | ||
| 171 | + </Show> | ||
| 88 | </Show> | 172 | </Show> |
| 89 | - </Suspense> | 173 | + </section> |
| 174 | + | ||
| 175 | + <SidePanel | ||
| 176 | + size="wide" | ||
| 177 | + open={viewUser() != null} | ||
| 178 | + onOpenChange={(open) => { | ||
| 179 | + if (!open) { | ||
| 180 | + setViewUser(null); | ||
| 181 | + setError(""); | ||
| 182 | + } | ||
| 183 | + }} | ||
| 184 | + title={t("marks.forUser", { user: personLabel(viewUser()) })} | ||
| 185 | + description={t("marks.lookup")} | ||
| 186 | + > | ||
| 187 | + <div class="min-w-0 space-y-3"> | ||
| 188 | + <Show when={error()}> | ||
| 189 | + <ErrorAlert message={error()} onRetry={() => void refetchReport()} /> | ||
| 190 | + </Show> | ||
| 191 | + <Show when={report.loading}> | ||
| 192 | + <p class="text-sm text-muted-foreground">{t("common.loading")}</p> | ||
| 193 | + </Show> | ||
| 194 | + <Show when={report()}>{(r) => <MarksReportView report={r()} compact />}</Show> | ||
| 195 | + </div> | ||
| 196 | + </SidePanel> | ||
| 90 | </div> | 197 | </div> |
| 91 | ); | 198 | ); |
| 92 | } | 199 | } |