📈 unify student reports
Browse files at this commit11c77b1dda6547dcd9983f837a2a4062bc52d97bParent: e096466- feat
- 📈 unify student reports
5 changed files +258 -170
- src/components/attendance/attendance-report-view.tsx +79 -81
- src/components/marks/marks-report-view.tsx +67 -36
- src/pages/attendance-page.tsx +0 -34
- src/pages/marks-page.test.tsx +50 -0
- src/pages/marks-page.tsx +62 -19
src/components/attendance/attendance-report-view.tsxmodified+79 -81
| @@ -9,8 +9,11 @@ import { cn } from "@/lib/cn"; | ||
| 9 | 9 | import { useT } from "@/stores/preferences-context"; |
| 10 | 10 | |
| 11 | 11 | function percent(rate: number | null): string { |
| 12 | - if (rate == null) return "—"; | |
| 13 | - return `${Math.round(rate * 100)}%`; | |
| 12 | + return rate == null ? "—" : `${Math.round(rate * 100)}%`; | |
| 13 | +} | |
| 14 | + | |
| 15 | +function rateWidth(rate: number | null): string { | |
| 16 | + return `${Math.max(0, Math.min(100, Math.round((rate ?? 0) * 100)))}%`; | |
| 14 | 17 | } |
| 15 | 18 | |
| 16 | 19 | function customEntries(counts: AttendanceCounts) { |
| @@ -19,80 +22,19 @@ function customEntries(counts: AttendanceCounts) { | ||
| 19 | 22 | |
| 20 | 23 | type CourseAttendanceRow = AttendanceReport["courses"][number]; |
| 21 | 24 | |
| 22 | -function CountsCard(props: { title: string; counts: AttendanceCounts; compact?: boolean }) { | |
| 23 | - const t = useT(); | |
| 24 | - return ( | |
| 25 | - <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")}> | |
| 26 | - <div class="flex items-center justify-between gap-3"> | |
| 27 | - <h3 class={cn("font-display font-semibold", props.compact ? "text-sm" : "text-lg")}>{props.title}</h3> | |
| 28 | - <Badge variant="secondary" class="mono rounded-full px-2.5 py-0.5 text-xs"> | |
| 29 | - {percent(props.counts.rate)} | |
| 30 | - </Badge> | |
| 31 | - </div> | |
| 32 | - <dl class={cn("grid gap-2 text-sm", props.compact ? "grid-cols-2" : "grid-cols-1 sm:grid-cols-2")}> | |
| 33 | - <For each={ATTENDANCE_STATUSES}> | |
| 34 | - {(status) => ( | |
| 35 | - <StatusStat | |
| 36 | - label={t(status.key)} | |
| 37 | - detail={props.compact ? undefined : t(status.detailKey)} | |
| 38 | - value={props.counts[status.value]} | |
| 39 | - class={status.class} | |
| 40 | - compact={props.compact} | |
| 41 | - /> | |
| 42 | - )} | |
| 43 | - </For> | |
| 44 | - </dl> | |
| 45 | - <dl class="grid grid-cols-2 gap-2 text-sm"> | |
| 46 | - <Stat label={t("common.all")} value={props.counts.total} compact={props.compact} /> | |
| 47 | - <Stat label={t("attendance.rate")} value={percent(props.counts.rate)} compact={props.compact} /> | |
| 48 | - </dl> | |
| 49 | - <Show when={customEntries(props.counts).length > 0}> | |
| 50 | - <div class="flex flex-wrap gap-1.5 pt-0.5"> | |
| 51 | - <For each={customEntries(props.counts)}> | |
| 52 | - {([label, count]) => ( | |
| 53 | - <Badge variant="outline" class="rounded-full text-[11px]"> | |
| 54 | - {label}: {count} | |
| 55 | - </Badge> | |
| 56 | - )} | |
| 57 | - </For> | |
| 58 | - </div> | |
| 59 | - </Show> | |
| 60 | - </article> | |
| 61 | - ); | |
| 62 | -} | |
| 63 | - | |
| 64 | -function Stat(props: { label: string; value: string | number; compact?: boolean }) { | |
| 65 | - return ( | |
| 66 | - <div class={cn("rounded-xl border bg-background/60", props.compact ? "p-2.5" : "p-3")}> | |
| 67 | - <dt class="text-[11px] text-muted-foreground">{props.label}</dt> | |
| 68 | - <dd class={cn("mono font-semibold tabular-nums", props.compact ? "mt-0.5 text-lg" : "mt-1 text-xl")}>{props.value}</dd> | |
| 69 | - </div> | |
| 70 | - ); | |
| 71 | -} | |
| 72 | - | |
| 73 | -function StatusStat(props: { label: string; detail?: string; value: number; class: string; compact?: boolean }) { | |
| 74 | - return ( | |
| 75 | - <div class={cn("rounded-xl border", props.class, props.compact ? "p-2.5" : "p-3")}> | |
| 76 | - <dt class="flex items-center justify-between gap-1 text-[11px] font-semibold"> | |
| 77 | - <span class="truncate">{props.label}</span> | |
| 78 | - <Show when={props.detail}> | |
| 79 | - <span class="hidden truncate font-normal opacity-75 sm:inline">{props.detail}</span> | |
| 80 | - </Show> | |
| 81 | - </dt> | |
| 82 | - <dd class={cn("mono font-semibold tabular-nums", props.compact ? "mt-0.5 text-xl" : "mt-1 text-2xl")}>{props.value}</dd> | |
| 83 | - </div> | |
| 84 | - ); | |
| 85 | -} | |
| 86 | - | |
| 87 | 25 | export function AttendanceReportView(props: { report: AttendanceReport; compact?: boolean }) { |
| 88 | 26 | const t = useT(); |
| 89 | 27 | const compact = () => props.compact === true; |
| 28 | + const blocks = () => [ | |
| 29 | + { title: t("attendance.events"), counts: props.report.events, color: "bg-emerald-500" }, | |
| 30 | + { title: t("attendance.sessions"), counts: props.report.sessions, color: "bg-sky-500" }, | |
| 31 | + ]; | |
| 90 | 32 | const columns = createMemo<ColumnDef<CourseAttendanceRow>[]>(() => [ |
| 91 | 33 | { |
| 92 | 34 | id: "course", |
| 93 | 35 | header: t("nav.courses"), |
| 94 | 36 | cell: (cell) => ( |
| 95 | - <Link to="/courses/$id" params={{ id: cell.row.original.course.id }} class="block truncate font-medium hover:underline"> | |
| 37 | + <Link to="/courses/$id" params={{ id: cell.row.original.course.id }} class="block truncate font-medium hover:text-primary hover:underline"> | |
| 96 | 38 | {cell.row.original.course.title} |
| 97 | 39 | </Link> |
| 98 | 40 | ), |
| @@ -102,7 +44,7 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? | ||
| 102 | 44 | header: () => <span title={t(status.detailKey)}>{compact() ? t(status.key).slice(0, 1) : t(status.key)}</span>, |
| 103 | 45 | meta: { headerClass: "text-right", cellClass: "text-right" }, |
| 104 | 46 | cell: (cell) => ( |
| 105 | - <span class={cn("mono inline-flex min-w-7 justify-center rounded-full border px-1.5 py-0.5 text-[11px] font-semibold tabular-nums", status.class)}> | |
| 47 | + <span class={cn("mono inline-flex min-w-7 justify-center rounded-md border px-1.5 py-0.5 text-[11px] font-semibold tabular-nums", status.class)}> | |
| 106 | 48 | {cell.row.original.counts[status.value]} |
| 107 | 49 | </span> |
| 108 | 50 | ), |
| @@ -122,20 +64,76 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? | ||
| 122 | 64 | ]); |
| 123 | 65 | |
| 124 | 66 | return ( |
| 125 | - <div class={cn("min-w-0 space-y-3", !compact() && "space-y-4")}> | |
| 126 | - <div class={cn("grid gap-3", compact() ? "grid-cols-1" : "gap-4 lg:grid-cols-2")}> | |
| 127 | - <CountsCard title={t("attendance.events")} counts={props.report.events} compact={compact()} /> | |
| 128 | - <CountsCard title={t("attendance.sessions")} counts={props.report.sessions} compact={compact()} /> | |
| 67 | + <div class="min-w-0 space-y-4"> | |
| 68 | + <dl class="grid grid-cols-1 gap-3 sm:grid-cols-3"> | |
| 69 | + <div class="rounded-2xl border border-border bg-card p-4 shadow-xs"> | |
| 70 | + <dt class="text-xs font-medium text-muted-foreground">{t("common.all")}</dt> | |
| 71 | + <dd class="mt-2 font-display text-3xl font-semibold tabular-nums"> | |
| 72 | + {props.report.events.total + props.report.sessions.total} | |
| 73 | + </dd> | |
| 74 | + </div> | |
| 75 | + <div class="rounded-2xl border border-border bg-card p-4 shadow-xs"> | |
| 76 | + <dt class="text-xs font-medium text-muted-foreground">{t("attendance.events")}</dt> | |
| 77 | + <dd class="mt-2 font-display text-3xl font-semibold tabular-nums">{percent(props.report.events.rate)}</dd> | |
| 78 | + </div> | |
| 79 | + <div class="rounded-2xl border border-border bg-card p-4 shadow-xs"> | |
| 80 | + <dt class="text-xs font-medium text-muted-foreground">{t("attendance.sessions")}</dt> | |
| 81 | + <dd class="mt-2 font-display text-3xl font-semibold tabular-nums">{percent(props.report.sessions.rate)}</dd> | |
| 82 | + </div> | |
| 83 | + </dl> | |
| 84 | + | |
| 85 | + <div class={cn("grid gap-3", !compact() && "lg:grid-cols-2")}> | |
| 86 | + <For each={blocks()}> | |
| 87 | + {(block) => ( | |
| 88 | + <article class="rounded-2xl border border-border bg-card p-4 shadow-xs"> | |
| 89 | + <header class="flex items-end justify-between gap-3"> | |
| 90 | + <div> | |
| 91 | + <p class="text-xs font-medium text-muted-foreground">{block.title}</p> | |
| 92 | + <p class="mt-1 font-display text-2xl font-semibold tabular-nums">{percent(block.counts.rate)}</p> | |
| 93 | + </div> | |
| 94 | + <p class="text-xs text-muted-foreground">{block.counts.total} {t("common.all").toLocaleLowerCase()}</p> | |
| 95 | + </header> | |
| 96 | + <div class="mt-3 h-2 overflow-hidden rounded-full bg-muted"> | |
| 97 | + <div class={cn("h-full rounded-full", block.color)} style={{ width: rateWidth(block.counts.rate) }} /> | |
| 98 | + </div> | |
| 99 | + <dl class="mt-4 grid grid-cols-2 gap-2 sm:grid-cols-4"> | |
| 100 | + <For each={ATTENDANCE_STATUSES}> | |
| 101 | + {(status) => ( | |
| 102 | + <div class={cn("rounded-xl border p-3", status.class)}> | |
| 103 | + <dt class="truncate text-[11px] font-medium">{t(status.key)}</dt> | |
| 104 | + <dd class="mt-1 font-display text-xl font-semibold tabular-nums">{block.counts[status.value]}</dd> | |
| 105 | + </div> | |
| 106 | + )} | |
| 107 | + </For> | |
| 108 | + </dl> | |
| 109 | + <Show when={customEntries(block.counts).length > 0}> | |
| 110 | + <div class="mt-3 flex flex-wrap gap-1.5"> | |
| 111 | + <For each={customEntries(block.counts)}> | |
| 112 | + {([label, count]) => <Badge variant="outline" class="rounded-full text-[11px]">{label}: {count}</Badge>} | |
| 113 | + </For> | |
| 114 | + </div> | |
| 115 | + </Show> | |
| 116 | + </article> | |
| 117 | + )} | |
| 118 | + </For> | |
| 129 | 119 | </div> |
| 130 | 120 | |
| 131 | - <section class={cn("space-y-3 rounded-xl border border-border/80 bg-card", compact() ? "p-3" : "data-shell space-y-4 p-4")}> | |
| 132 | - <h3 class={cn("font-display font-semibold", compact() ? "text-sm" : "text-lg")}>{t("attendance.courseBreakdown")}</h3> | |
| 133 | - <Show | |
| 134 | - when={props.report.courses.length > 0} | |
| 135 | - fallback={<DataTableEmpty class="py-6">{t("attendance.emptyCourses")}</DataTableEmpty>} | |
| 136 | - > | |
| 137 | - <DataTable class="min-w-0" columns={columns()} data={props.report.courses} tableClass={cn("w-full", compact() ? "text-xs" : "table-fixed min-w-160")} /> | |
| 138 | - </Show> | |
| 121 | + <section class="rounded-2xl border border-border bg-card p-4 shadow-xs"> | |
| 122 | + <h3 class="font-display text-base font-semibold">{t("attendance.courseBreakdown")}</h3> | |
| 123 | + <div class="mt-3"> | |
| 124 | + <Show | |
| 125 | + when={props.report.courses.length > 0} | |
| 126 | + fallback={<DataTableEmpty class="py-8">{t("attendance.emptyCourses")}</DataTableEmpty>} | |
| 127 | + > | |
| 128 | + <DataTable | |
| 129 | + class="min-w-0" | |
| 130 | + columns={columns()} | |
| 131 | + data={props.report.courses} | |
| 132 | + tableClass={cn("w-full", compact() ? "text-xs" : "table-fixed min-w-160")} | |
| 133 | + enableColumnVisibility={false} | |
| 134 | + /> | |
| 135 | + </Show> | |
| 136 | + </div> | |
| 139 | 137 | </section> |
| 140 | 138 | </div> |
| 141 | 139 | ); |
src/components/marks/marks-report-view.tsxmodified+67 -36
| @@ -6,6 +6,7 @@ import type { MarksReport } from "@/api/client"; | ||
| 6 | 6 | import { Badge } from "@/components/ui/badge"; |
| 7 | 7 | import { DataTable, DataTableEmpty } from "@/components/ui/data-table"; |
| 8 | 8 | import { ExamLink } from "@/components/exams/exam-link"; |
| 9 | +import { IconChevronDown } from "@/components/ui/icons"; | |
| 9 | 10 | import { cn } from "@/lib/cn"; |
| 10 | 11 | import { examKindLabel } from "@/lib/exam-labels"; |
| 11 | 12 | import { examWeight } from "@/lib/exam-weight"; |
| @@ -19,10 +20,15 @@ function markWithGrade(mark: number | null, grade?: string | null) { | ||
| 19 | 20 | return grade ? `${round(mark)} / ${grade}` : round(mark); |
| 20 | 21 | } |
| 21 | 22 | |
| 23 | +function scoreWidth(mark: number | null): string { | |
| 24 | + return `${Math.max(0, Math.min(100, Math.round(mark ?? 0)))}%`; | |
| 25 | +} | |
| 26 | + | |
| 22 | 27 | export function MarksReportView(props: { report: MarksReport; compact?: boolean }) { |
| 23 | 28 | const t = useT(); |
| 24 | 29 | const [settings] = createResource(() => getSettings()); |
| 25 | 30 | const compact = () => props.compact === true; |
| 31 | + const resultCount = createMemo(() => props.report.courses.reduce((total, course) => total + course.results.length, 0)); | |
| 26 | 32 | const columns = createMemo<ColumnDef<MarkRow>[]>(() => [ |
| 27 | 33 | { |
| 28 | 34 | accessorKey: "title", |
| @@ -61,53 +67,78 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | ||
| 61 | 67 | ]); |
| 62 | 68 | |
| 63 | 69 | return ( |
| 64 | - <Show when={props.report.courses.length > 0} fallback={<DataTableEmpty>{t("marks.empty")}</DataTableEmpty>}> | |
| 65 | - <div class={cn("space-y-3", compact() ? "min-w-0" : "space-y-4")}> | |
| 66 | - <div | |
| 67 | - class={cn( | |
| 68 | - "flex flex-wrap items-center justify-between gap-3 rounded-xl border border-border/80 bg-card", | |
| 69 | - compact() ? "px-3 py-3" : "data-shell p-4", | |
| 70 | - )} | |
| 71 | - > | |
| 72 | - <span class="text-xs font-medium text-muted-foreground sm:text-sm">{t("marks.overall")}</span> | |
| 73 | - <p class={cn("font-display font-semibold tabular-nums", compact() ? "text-2xl" : "text-3xl")}> | |
| 70 | + <div class="min-w-0 space-y-4"> | |
| 71 | + <section class="grid gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center"> | |
| 72 | + <div> | |
| 73 | + <p class="text-xs font-medium text-muted-foreground">{t("marks.overall")}</p> | |
| 74 | + <p class={cn("mt-1 font-display font-semibold tabular-nums", compact() ? "text-3xl" : "text-4xl")}> | |
| 74 | 75 | {markWithGrade(props.report.overall_average, props.report.overall_grade)} |
| 75 | 76 | <Show when={props.report.overall_average != null}> |
| 76 | - <span class="text-sm font-medium text-muted-foreground"> / 100</span> | |
| 77 | + <span class="ml-1 text-sm font-medium text-muted-foreground">/ 100</span> | |
| 77 | 78 | </Show> |
| 78 | 79 | </p> |
| 80 | + <div class="mt-3 h-2 max-w-xl overflow-hidden rounded-full bg-muted"> | |
| 81 | + <div class="h-full rounded-full bg-primary" style={{ width: scoreWidth(props.report.overall_average) }} /> | |
| 82 | + </div> | |
| 79 | 83 | </div> |
| 84 | + <dl class="grid grid-cols-2 gap-2 sm:min-w-56"> | |
| 85 | + <div class="rounded-xl bg-muted/45 p-3"> | |
| 86 | + <dt class="text-[11px] text-muted-foreground">{t("nav.courses")}</dt> | |
| 87 | + <dd class="mt-1 font-display text-2xl font-semibold tabular-nums">{props.report.courses.length}</dd> | |
| 88 | + </div> | |
| 89 | + <div class="rounded-xl bg-muted/45 p-3"> | |
| 90 | + <dt class="text-[11px] text-muted-foreground">{t("exams.results")}</dt> | |
| 91 | + <dd class="mt-1 font-display text-2xl font-semibold tabular-nums">{resultCount()}</dd> | |
| 92 | + </div> | |
| 93 | + </dl> | |
| 94 | + </section> | |
| 95 | + | |
| 96 | + <Show when={props.report.courses.length > 0} fallback={<DataTableEmpty class="rounded-2xl border border-border bg-card py-10">{t("marks.empty")}</DataTableEmpty>}> | |
| 97 | + <div class="space-y-3"> | |
| 98 | + <For each={props.report.courses}> | |
| 99 | + {(block) => ( | |
| 100 | + <details name="marks-courses" class="group rounded-2xl border border-border bg-card shadow-xs open:ring-1 open:ring-primary/15"> | |
| 101 | + <summary class="flex min-w-0 cursor-pointer list-none flex-wrap items-center justify-between gap-3 rounded-2xl p-4 outline-hidden transition-colors hover:bg-muted/35 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring [&::-webkit-details-marker]:hidden"> | |
| 102 | + <div class="min-w-0 flex-1"> | |
| 103 | + <p class={cn("truncate font-display font-semibold", compact() ? "text-sm" : "text-lg")}> | |
| 104 | + {block.course.title} | |
| 105 | + </p> | |
| 106 | + <div class="mt-2 h-1.5 overflow-hidden rounded-full bg-muted"> | |
| 107 | + <div class="h-full rounded-full bg-primary/75" style={{ width: scoreWidth(block.average) }} /> | |
| 108 | + </div> | |
| 109 | + </div> | |
| 110 | + <div class="flex shrink-0 items-center gap-3"> | |
| 111 | + <div class="text-right"> | |
| 112 | + <p class="text-[10px] font-medium uppercase tracking-wider text-muted-foreground">{t("marks.courseAvg")}</p> | |
| 113 | + <p class="mt-0.5 font-display text-xl font-semibold tabular-nums">{markWithGrade(block.average, block.average_grade)}</p> | |
| 114 | + </div> | |
| 115 | + <IconChevronDown class="h-4 w-4 text-muted-foreground transition-transform group-open:rotate-180" /> | |
| 116 | + </div> | |
| 117 | + </summary> | |
| 80 | 118 | |
| 81 | - <For each={props.report.courses}> | |
| 82 | - {(block) => ( | |
| 83 | - <article | |
| 84 | - class={cn( | |
| 85 | - "space-y-3 rounded-xl border border-border/80 bg-card", | |
| 86 | - compact() ? "p-3" : "data-shell space-y-4 p-4", | |
| 87 | - )} | |
| 88 | - > | |
| 89 | - <header class="flex min-w-0 flex-wrap items-center justify-between gap-2"> | |
| 90 | - <h3 class={cn("min-w-0 font-display font-semibold", compact() ? "text-sm" : "text-lg")}> | |
| 119 | + <div class="border-t border-border p-4 pt-3"> | |
| 91 | 120 | <Link |
| 92 | 121 | to="/courses/$id" |
| 93 | 122 | params={{ id: block.course.id }} |
| 94 | - class="block truncate hover:text-primary hover:underline" | |
| 123 | + class="mb-3 inline-flex text-xs font-semibold text-primary hover:underline" | |
| 95 | 124 | > |
| 96 | 125 | {block.course.title} |
| 97 | 126 | </Link> |
| 98 | - </h3> | |
| 99 | - <Badge variant="secondary" class="mono shrink-0 rounded-sm px-2.5 py-0.5 text-xs" title={t("marks.courseAvg")}> | |
| 100 | - {markWithGrade(block.average, block.average_grade)} | |
| 101 | - </Badge> | |
| 102 | - </header> | |
| 103 | - | |
| 104 | - <Show when={block.results.length > 0} fallback={<DataTableEmpty class="py-6">{t("exams.noResults")}</DataTableEmpty>}> | |
| 105 | - <DataTable class="min-w-0" columns={columns()} data={block.results} tableClass={cn("w-full", compact() ? "text-xs" : "table-fixed min-w-xl")} /> | |
| 106 | - </Show> | |
| 107 | - </article> | |
| 108 | - )} | |
| 109 | - </For> | |
| 110 | - </div> | |
| 111 | - </Show> | |
| 127 | + <Show when={block.results.length > 0} fallback={<DataTableEmpty class="py-6">{t("exams.noResults")}</DataTableEmpty>}> | |
| 128 | + <DataTable | |
| 129 | + class="min-w-0" | |
| 130 | + columns={columns()} | |
| 131 | + data={block.results} | |
| 132 | + tableClass={cn("w-full", compact() ? "text-xs" : "table-fixed min-w-xl")} | |
| 133 | + enableColumnVisibility={false} | |
| 134 | + /> | |
| 135 | + </Show> | |
| 136 | + </div> | |
| 137 | + </details> | |
| 138 | + )} | |
| 139 | + </For> | |
| 140 | + </div> | |
| 141 | + </Show> | |
| 142 | + </div> | |
| 112 | 143 | ); |
| 113 | 144 | } |
src/pages/attendance-page.tsxdeleted+0 -34
| @@ -1,34 +0,0 @@ | ||
| 1 | -import { Show, Suspense, createResource } from "solid-js"; | |
| 2 | -import { getMyAttendance } from "@/api/reports"; | |
| 3 | -import { formatApiError } from "@/api/client"; | |
| 4 | -import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; | |
| 5 | -import { RouteGuard } from "@/components/layout/route-guard"; | |
| 6 | -import { PageHeader } from "@/components/layout/page-header"; | |
| 7 | -import { Alert } from "@/components/ui/alert"; | |
| 8 | -import { PageSpinner } from "@/components/ui/page-spinner"; | |
| 9 | -import { useT } from "@/stores/preferences-context"; | |
| 10 | - | |
| 11 | -export default function AttendancePage() { | |
| 12 | - return ( | |
| 13 | - <RouteGuard exactRole="student"> | |
| 14 | - <AttendanceContent /> | |
| 15 | - </RouteGuard> | |
| 16 | - ); | |
| 17 | -} | |
| 18 | - | |
| 19 | -function AttendanceContent() { | |
| 20 | - const t = useT(); | |
| 21 | - const [report] = createResource(() => getMyAttendance()); | |
| 22 | - | |
| 23 | - return ( | |
| 24 | - <div class="space-y-6"> | |
| 25 | - <PageHeader accent="sky" eyebrow={t("nav.attendance")} title={t("attendance.title")} description={t("attendance.subtitle")} /> | |
| 26 | - <Suspense fallback={<PageSpinner />}> | |
| 27 | - <Show when={report.error}> | |
| 28 | - <Alert variant="destructive">{formatApiError(report.error)}</Alert> | |
| 29 | - </Show> | |
| 30 | - <Show when={report()}>{(r) => <AttendanceReportView report={r()} />}</Show> | |
| 31 | - </Suspense> | |
| 32 | - </div> | |
| 33 | - ); | |
| 34 | -} |
src/pages/marks-page.test.tsxadded+50 -0
| @@ -0,0 +1,50 @@ | ||
| 1 | +import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; | |
| 2 | +import MarksPage from "@/pages/marks-page"; | |
| 3 | +import { PreferencesProvider } from "@/stores/preferences-context"; | |
| 4 | + | |
| 5 | +const { navigate, search, getMyAttendance, getMyMarks } = vi.hoisted(() => ({ | |
| 6 | + navigate: vi.fn(), | |
| 7 | + search: { tab: "marks" as "marks" | "attendance" }, | |
| 8 | + getMyAttendance: vi.fn(), | |
| 9 | + getMyMarks: vi.fn(), | |
| 10 | +})); | |
| 11 | + | |
| 12 | +vi.mock("@tanstack/solid-router", () => ({ | |
| 13 | + Navigate: () => null, | |
| 14 | + Link: () => null, | |
| 15 | + useNavigate: () => navigate, | |
| 16 | + useSearch: () => () => search, | |
| 17 | +})); | |
| 18 | +vi.mock("@/stores/auth-context", () => ({ | |
| 19 | + useAuth: () => ({ | |
| 20 | + user: () => ({ id: "student-1", username: "student", role: "student" }), | |
| 21 | + loading: () => false, | |
| 22 | + error: () => undefined, | |
| 23 | + }), | |
| 24 | +})); | |
| 25 | +vi.mock("@/api/reports", () => ({ getMyAttendance, getMyMarks })); | |
| 26 | + | |
| 27 | +afterEach(() => { | |
| 28 | + cleanup(); | |
| 29 | + vi.clearAllMocks(); | |
| 30 | + search.tab = "marks"; | |
| 31 | +}); | |
| 32 | + | |
| 33 | +test("progress keeps report card and attendance in tabs", async () => { | |
| 34 | + getMyMarks.mockResolvedValue({ user: "student-1", overall_average: 80, courses: [] }); | |
| 35 | + getMyAttendance.mockResolvedValue({ | |
| 36 | + user: "student-1", | |
| 37 | + events: { total: 0, present: 0, absent: 0, late: 0, excused: 0 }, | |
| 38 | + sessions: { total: 0, present: 0, absent: 0, late: 0, excused: 0 }, | |
| 39 | + courses: [], | |
| 40 | + }); | |
| 41 | + | |
| 42 | + render(() => <PreferencesProvider><MarksPage /></PreferencesProvider>); | |
| 43 | + | |
| 44 | + expect(await screen.findByRole("tab", { name: "Report card" })).toBeTruthy(); | |
| 45 | + const attendanceTab = screen.getByRole("tab", { name: "Attendance" }); | |
| 46 | + fireEvent.click(attendanceTab); | |
| 47 | + await waitFor(() => expect(getMyAttendance).toHaveBeenCalledTimes(1)); | |
| 48 | + expect(attendanceTab.getAttribute("aria-selected")).toBe("true"); | |
| 49 | + expect(navigate).toHaveBeenCalledWith({ to: "/marks", search: { tab: "attendance" } }); | |
| 50 | +}); |
src/pages/marks-page.tsxmodified+62 -19
| @@ -1,12 +1,15 @@ | ||
| 1 | -import { Show, Suspense, createResource } from "solid-js"; | |
| 2 | -import { getMyMarks } from "@/api/reports"; | |
| 1 | +import { Show, Suspense, createEffect, createResource, createSignal } from "solid-js"; | |
| 2 | +import { useNavigate, useSearch } from "@tanstack/solid-router"; | |
| 3 | +import { getMyAttendance, getMyMarks } from "@/api/reports"; | |
| 3 | 4 | import { formatApiError } from "@/api/client"; |
| 4 | 5 | import { Alert } from "@/components/ui/alert"; |
| 6 | +import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; | |
| 5 | 7 | import { MarksReportView } from "@/components/marks/marks-report-view"; |
| 6 | 8 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 7 | -import { PageHeader } from "@/components/layout/page-header"; | |
| 8 | 9 | import { EmptyState } from "@/components/ui/empty-state"; |
| 10 | +import { IconChart, IconClipboardCheck } from "@/components/ui/icons"; | |
| 9 | 11 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 12 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | |
| 10 | 13 | import { useT } from "@/stores/preferences-context"; |
| 11 | 14 | |
| 12 | 15 | export default function MarksPage() { |
| @@ -19,25 +22,65 @@ export default function MarksPage() { | ||
| 19 | 22 | |
| 20 | 23 | function MarksContent() { |
| 21 | 24 | const t = useT(); |
| 22 | - const [mine] = createResource(() => getMyMarks()); | |
| 25 | + const navigate = useNavigate(); | |
| 26 | + const routeSearch = useSearch({ from: "/marks" }); | |
| 27 | + const [tab, setTab] = createSignal<"marks" | "attendance">(routeSearch().tab); | |
| 28 | + createEffect(() => setTab(routeSearch().tab)); | |
| 29 | + const [marks] = createResource(() => tab() === "marks" || null, () => getMyMarks()); | |
| 30 | + const [attendance] = createResource(() => tab() === "attendance" || null, () => getMyAttendance()); | |
| 23 | 31 | |
| 24 | 32 | return ( |
| 25 | - <div class="space-y-6"> | |
| 26 | - <PageHeader | |
| 27 | - accent="amber" | |
| 28 | - eyebrow={t("nav.marks")} | |
| 29 | - title={t("marks.title")} | |
| 30 | - description={t("marks.subtitle")} | |
| 31 | - /> | |
| 33 | + <div class="space-y-5"> | |
| 34 | + <header class="flex items-center gap-3 border-b border-border pb-5"> | |
| 35 | + <span class="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-primary"> | |
| 36 | + <Show when={tab() === "marks"} fallback={<IconClipboardCheck class="h-5 w-5" />}> | |
| 37 | + <IconChart class="h-5 w-5" /> | |
| 38 | + </Show> | |
| 39 | + </span> | |
| 40 | + <div class="min-w-0"> | |
| 41 | + <h1 class="font-display text-2xl font-semibold tracking-tight">{t("nav.progress")}</h1> | |
| 42 | + <p class="mt-0.5 text-sm text-muted-foreground"> | |
| 43 | + {tab() === "marks" ? t("marks.subtitle") : t("attendance.subtitle")} | |
| 44 | + </p> | |
| 45 | + </div> | |
| 46 | + </header> | |
| 32 | 47 | |
| 33 | - <Suspense fallback={<PageSpinner />}> | |
| 34 | - <Show when={mine.error}> | |
| 35 | - <Alert variant="destructive">{formatApiError(mine.error)}</Alert> | |
| 36 | - </Show> | |
| 37 | - <Show when={mine()} fallback={<EmptyState title={t("marks.empty")} />}> | |
| 38 | - {(report) => <MarksReportView report={report()} />} | |
| 39 | - </Show> | |
| 40 | - </Suspense> | |
| 48 | + <Tabs | |
| 49 | + class="space-y-4" | |
| 50 | + value={tab()} | |
| 51 | + onChange={(value) => { | |
| 52 | + const next = value === "attendance" ? "attendance" : "marks"; | |
| 53 | + setTab(next); | |
| 54 | + void navigate({ to: "/marks", search: { tab: next } }); | |
| 55 | + }} | |
| 56 | + > | |
| 57 | + <TabsList class="w-fit max-w-full rounded-xl bg-card p-1 shadow-xs"> | |
| 58 | + <TabsTrigger value="marks" class="h-9 rounded-lg"> | |
| 59 | + <IconChart class="h-4 w-4" /> | |
| 60 | + {t("marks.title")} | |
| 61 | + </TabsTrigger> | |
| 62 | + <TabsTrigger value="attendance" class="h-9 rounded-lg"> | |
| 63 | + <IconClipboardCheck class="h-4 w-4" /> | |
| 64 | + {t("nav.attendance")} | |
| 65 | + </TabsTrigger> | |
| 66 | + </TabsList> | |
| 67 | + <TabsContent value="marks" class="mt-0 border-0 bg-transparent p-0 shadow-none"> | |
| 68 | + <Suspense fallback={<PageSpinner />}> | |
| 69 | + <Show when={!marks.error} fallback={<Alert variant="destructive">{formatApiError(marks.error)}</Alert>}> | |
| 70 | + <Show when={marks()} fallback={<EmptyState title={t("marks.empty")} />}> | |
| 71 | + {(report) => <MarksReportView report={report()} />} | |
| 72 | + </Show> | |
| 73 | + </Show> | |
| 74 | + </Suspense> | |
| 75 | + </TabsContent> | |
| 76 | + <TabsContent value="attendance" class="mt-0 border-0 bg-transparent p-0 shadow-none"> | |
| 77 | + <Suspense fallback={<PageSpinner />}> | |
| 78 | + <Show when={!attendance.error} fallback={<Alert variant="destructive">{formatApiError(attendance.error)}</Alert>}> | |
| 79 | + <Show when={attendance()}>{(report) => <AttendanceReportView report={report()} />}</Show> | |
| 80 | + </Show> | |
| 81 | + </Suspense> | |
| 82 | + </TabsContent> | |
| 83 | + </Tabs> | |
| 41 | 84 | </div> |
| 42 | 85 | ); |
| 43 | 86 | } |