From 11c77b1dda6547dcd9983f837a2a4062bc52d97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Tue, 28 Jul 2026 14:24:40 +0300 Subject: [PATCH] =?UTF-8?q?feat(progress):=20=F0=9F=93=88=20unify=20studen?= =?UTF-8?q?t=20reports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - place report card and attendance behind working tabs - add clearer score and attendance summaries - collapse per-course marks into native accordions --- .../attendance/attendance-report-view.tsx | 160 +++++++++--------- src/components/marks/marks-report-view.tsx | 103 +++++++---- src/pages/attendance-page.tsx | 34 ---- src/pages/marks-page.test.tsx | 50 ++++++ src/pages/marks-page.tsx | 81 ++++++--- 5 files changed, 258 insertions(+), 170 deletions(-) delete mode 100644 src/pages/attendance-page.tsx create mode 100644 src/pages/marks-page.test.tsx diff --git a/src/components/attendance/attendance-report-view.tsx b/src/components/attendance/attendance-report-view.tsx index 25c6404..a5db304 100644 --- a/src/components/attendance/attendance-report-view.tsx +++ b/src/components/attendance/attendance-report-view.tsx @@ -9,8 +9,11 @@ import { cn } from "@/lib/cn"; import { useT } from "@/stores/preferences-context"; function percent(rate: number | null): string { - if (rate == null) return "—"; - return `${Math.round(rate * 100)}%`; + return rate == null ? "—" : `${Math.round(rate * 100)}%`; +} + +function rateWidth(rate: number | null): string { + return `${Math.max(0, Math.min(100, Math.round((rate ?? 0) * 100)))}%`; } function customEntries(counts: AttendanceCounts) { @@ -19,80 +22,19 @@ function customEntries(counts: AttendanceCounts) { type CourseAttendanceRow = AttendanceReport["courses"][number]; -function CountsCard(props: { title: string; counts: AttendanceCounts; compact?: boolean }) { - const t = useT(); - return ( -
-
-

{props.title}

- - {percent(props.counts.rate)} - -
-
- - {(status) => ( - - )} - -
-
- - -
- 0}> -
- - {([label, count]) => ( - - {label}: {count} - - )} - -
-
-
- ); -} - -function Stat(props: { label: string; value: string | number; compact?: boolean }) { - return ( -
-
{props.label}
-
{props.value}
-
- ); -} - -function StatusStat(props: { label: string; detail?: string; value: number; class: string; compact?: boolean }) { - return ( -
-
- {props.label} - - - -
-
{props.value}
-
- ); -} - export function AttendanceReportView(props: { report: AttendanceReport; compact?: boolean }) { const t = useT(); const compact = () => props.compact === true; + const blocks = () => [ + { title: t("attendance.events"), counts: props.report.events, color: "bg-emerald-500" }, + { title: t("attendance.sessions"), counts: props.report.sessions, color: "bg-sky-500" }, + ]; const columns = createMemo[]>(() => [ { id: "course", header: t("nav.courses"), cell: (cell) => ( - + {cell.row.original.course.title} ), @@ -102,7 +44,7 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? header: () => {compact() ? t(status.key).slice(0, 1) : t(status.key)}, meta: { headerClass: "text-right", cellClass: "text-right" }, cell: (cell) => ( - + {cell.row.original.counts[status.value]} ), @@ -122,20 +64,76 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? ]); return ( -
-
- - +
+
+
+
{t("common.all")}
+
+ {props.report.events.total + props.report.sessions.total} +
+
+
+
{t("attendance.events")}
+
{percent(props.report.events.rate)}
+
+
+
{t("attendance.sessions")}
+
{percent(props.report.sessions.rate)}
+
+
+ +
+ + {(block) => ( +
+
+
+

{block.title}

+

{percent(block.counts.rate)}

+
+

{block.counts.total} {t("common.all").toLocaleLowerCase()}

+
+
+
+
+
+ + {(status) => ( +
+
{t(status.key)}
+
{block.counts[status.value]}
+
+ )} +
+
+ 0}> +
+ + {([label, count]) => {label}: {count}} + +
+
+
+ )} +
-
-

{t("attendance.courseBreakdown")}

- 0} - fallback={{t("attendance.emptyCourses")}} - > - - +
+

{t("attendance.courseBreakdown")}

+
+ 0} + fallback={{t("attendance.emptyCourses")}} + > + + +
); diff --git a/src/components/marks/marks-report-view.tsx b/src/components/marks/marks-report-view.tsx index b44a86b..4534ae5 100644 --- a/src/components/marks/marks-report-view.tsx +++ b/src/components/marks/marks-report-view.tsx @@ -6,6 +6,7 @@ import type { MarksReport } from "@/api/client"; import { Badge } from "@/components/ui/badge"; import { DataTable, DataTableEmpty } from "@/components/ui/data-table"; import { ExamLink } from "@/components/exams/exam-link"; +import { IconChevronDown } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; import { examKindLabel } from "@/lib/exam-labels"; import { examWeight } from "@/lib/exam-weight"; @@ -19,10 +20,15 @@ function markWithGrade(mark: number | null, grade?: string | null) { return grade ? `${round(mark)} / ${grade}` : round(mark); } +function scoreWidth(mark: number | null): string { + return `${Math.max(0, Math.min(100, Math.round(mark ?? 0)))}%`; +} + export function MarksReportView(props: { report: MarksReport; compact?: boolean }) { const t = useT(); const [settings] = createResource(() => getSettings()); const compact = () => props.compact === true; + const resultCount = createMemo(() => props.report.courses.reduce((total, course) => total + course.results.length, 0)); const columns = createMemo[]>(() => [ { accessorKey: "title", @@ -61,53 +67,78 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean ]); return ( - 0} fallback={{t("marks.empty")}}> -
-
- {t("marks.overall")} -

+

+
+
+

{t("marks.overall")}

+

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

+
+
+
+
+
+
{t("nav.courses")}
+
{props.report.courses.length}
+
+
+
{t("exams.results")}
+
{resultCount()}
+
+
+
+ + 0} fallback={{t("marks.empty")}}> +
+ + {(block) => ( +
+ +
+

+ {block.course.title} +

+
+
+
+
+
+
+

{t("marks.courseAvg")}

+

{markWithGrade(block.average, block.average_grade)}

+
+ +
+
- - {(block) => ( -
-
-

+
{block.course.title} -

- - {markWithGrade(block.average, block.average_grade)} - -
- - 0} fallback={{t("exams.noResults")}}> - - -
- )} -
-
-
+ 0} fallback={{t("exams.noResults")}}> + + +
+ + )} + +
+ +
); } diff --git a/src/pages/attendance-page.tsx b/src/pages/attendance-page.tsx deleted file mode 100644 index be5b00e..0000000 --- a/src/pages/attendance-page.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { Show, Suspense, createResource } from "solid-js"; -import { getMyAttendance } from "@/api/reports"; -import { formatApiError } from "@/api/client"; -import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; -import { RouteGuard } from "@/components/layout/route-guard"; -import { PageHeader } from "@/components/layout/page-header"; -import { Alert } from "@/components/ui/alert"; -import { PageSpinner } from "@/components/ui/page-spinner"; -import { useT } from "@/stores/preferences-context"; - -export default function AttendancePage() { - return ( - - - - ); -} - -function AttendanceContent() { - const t = useT(); - const [report] = createResource(() => getMyAttendance()); - - return ( -
- - }> - - {formatApiError(report.error)} - - {(r) => } - -
- ); -} diff --git a/src/pages/marks-page.test.tsx b/src/pages/marks-page.test.tsx new file mode 100644 index 0000000..134916c --- /dev/null +++ b/src/pages/marks-page.test.tsx @@ -0,0 +1,50 @@ +import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; +import MarksPage from "@/pages/marks-page"; +import { PreferencesProvider } from "@/stores/preferences-context"; + +const { navigate, search, getMyAttendance, getMyMarks } = vi.hoisted(() => ({ + navigate: vi.fn(), + search: { tab: "marks" as "marks" | "attendance" }, + getMyAttendance: vi.fn(), + getMyMarks: vi.fn(), +})); + +vi.mock("@tanstack/solid-router", () => ({ + Navigate: () => null, + Link: () => null, + useNavigate: () => navigate, + useSearch: () => () => search, +})); +vi.mock("@/stores/auth-context", () => ({ + useAuth: () => ({ + user: () => ({ id: "student-1", username: "student", role: "student" }), + loading: () => false, + error: () => undefined, + }), +})); +vi.mock("@/api/reports", () => ({ getMyAttendance, getMyMarks })); + +afterEach(() => { + cleanup(); + vi.clearAllMocks(); + search.tab = "marks"; +}); + +test("progress keeps report card and attendance in tabs", async () => { + getMyMarks.mockResolvedValue({ user: "student-1", overall_average: 80, courses: [] }); + getMyAttendance.mockResolvedValue({ + user: "student-1", + events: { total: 0, present: 0, absent: 0, late: 0, excused: 0 }, + sessions: { total: 0, present: 0, absent: 0, late: 0, excused: 0 }, + courses: [], + }); + + render(() => ); + + expect(await screen.findByRole("tab", { name: "Report card" })).toBeTruthy(); + const attendanceTab = screen.getByRole("tab", { name: "Attendance" }); + fireEvent.click(attendanceTab); + await waitFor(() => expect(getMyAttendance).toHaveBeenCalledTimes(1)); + expect(attendanceTab.getAttribute("aria-selected")).toBe("true"); + expect(navigate).toHaveBeenCalledWith({ to: "/marks", search: { tab: "attendance" } }); +}); diff --git a/src/pages/marks-page.tsx b/src/pages/marks-page.tsx index 2cb59e2..f47b106 100644 --- a/src/pages/marks-page.tsx +++ b/src/pages/marks-page.tsx @@ -1,12 +1,15 @@ -import { Show, Suspense, createResource } from "solid-js"; -import { getMyMarks } from "@/api/reports"; +import { Show, Suspense, createEffect, createResource, createSignal } from "solid-js"; +import { useNavigate, useSearch } from "@tanstack/solid-router"; +import { getMyAttendance, getMyMarks } from "@/api/reports"; import { formatApiError } from "@/api/client"; import { Alert } from "@/components/ui/alert"; +import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; import { MarksReportView } from "@/components/marks/marks-report-view"; import { RouteGuard } from "@/components/layout/route-guard"; -import { PageHeader } from "@/components/layout/page-header"; import { EmptyState } from "@/components/ui/empty-state"; +import { IconChart, IconClipboardCheck } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useT } from "@/stores/preferences-context"; export default function MarksPage() { @@ -19,25 +22,65 @@ export default function MarksPage() { function MarksContent() { const t = useT(); - const [mine] = createResource(() => getMyMarks()); + const navigate = useNavigate(); + const routeSearch = useSearch({ from: "/marks" }); + const [tab, setTab] = createSignal<"marks" | "attendance">(routeSearch().tab); + createEffect(() => setTab(routeSearch().tab)); + const [marks] = createResource(() => tab() === "marks" || null, () => getMyMarks()); + const [attendance] = createResource(() => tab() === "attendance" || null, () => getMyAttendance()); return ( -
- +
+
+ + }> + + + +
+

{t("nav.progress")}

+

+ {tab() === "marks" ? t("marks.subtitle") : t("attendance.subtitle")} +

+
+
- }> - - {formatApiError(mine.error)} - - }> - {(report) => } - - + { + const next = value === "attendance" ? "attendance" : "marks"; + setTab(next); + void navigate({ to: "/marks", search: { tab: next } }); + }} + > + + + + {t("marks.title")} + + + + {t("nav.attendance")} + + + + }> + {formatApiError(marks.error)}}> + }> + {(report) => } + + + + + + }> + {formatApiError(attendance.error)}}> + {(report) => } + + + +
); }