♻️ replace detail accordions with tabs
Browse files at this commit9c9b5eaf7fb12e0809312fb5a828db2e51bc569cParent: 5e6085b- refactor
- ♻️ replace detail accordions with tabs
5 changed files +315 -415
- src/components/ui/section-disclosure.tsx +0 -50
- src/components/ui/tabs.tsx +48 -0
- src/pages/course-detail-page.tsx +80 -120
- src/pages/event-detail-page.tsx +80 -115
- src/pages/exam-detail-page.tsx +107 -130
src/components/ui/section-disclosure.tsxdeleted+0 -50
| @@ -1,50 +0,0 @@ | |||
| 1 | -import type { JSX, ParentProps } from "solid-js"; | ||
| 2 | -import { IconChevronRight } from "@/components/ui/icons"; | ||
| 3 | -import { cn } from "@/lib/cn"; | ||
| 4 | - | ||
| 5 | -export function SectionDisclosure(props: ParentProps<{ | ||
| 6 | - open: boolean; | ||
| 7 | - onToggle: () => void; | ||
| 8 | - title: string; | ||
| 9 | - description?: string; | ||
| 10 | - meta?: JSX.Element; | ||
| 11 | - actions?: JSX.Element; | ||
| 12 | - class?: string; | ||
| 13 | -}>) { | ||
| 14 | - return ( | ||
| 15 | - <section class={cn("data-shell overflow-hidden", props.class)}> | ||
| 16 | - <div class="flex flex-wrap items-center gap-2 border-b border-border bg-muted/25 px-4 py-3"> | ||
| 17 | - <button | ||
| 18 | - type="button" | ||
| 19 | - class="flex min-w-0 flex-1 items-center gap-3 text-left outline-none transition-colors hover:text-primary focus-visible:ring-2 focus-visible:ring-ring" | ||
| 20 | - aria-expanded={props.open} | ||
| 21 | - onClick={props.onToggle} | ||
| 22 | - > | ||
| 23 | - <IconChevronRight class={cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-150", props.open && "rotate-90")} /> | ||
| 24 | - <span class="min-w-0 flex-1"> | ||
| 25 | - <span class="block truncate font-display text-lg font-semibold">{props.title}</span> | ||
| 26 | - {props.description && <span class="mt-1 block truncate text-sm text-muted-foreground">{props.description}</span>} | ||
| 27 | - </span> | ||
| 28 | - </button> | ||
| 29 | - <div class="flex items-center gap-2 [&>button]:h-8 [&>button]:min-w-36 [&>button]:justify-center [&>div]:h-8 [&>div]:justify-center"> | ||
| 30 | - {props.meta} | ||
| 31 | - {props.actions} | ||
| 32 | - </div> | ||
| 33 | - </div> | ||
| 34 | - <div | ||
| 35 | - class={cn( | ||
| 36 | - "grid transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none", | ||
| 37 | - props.open ? "grid-rows-[1fr]" : "grid-rows-[0fr]", | ||
| 38 | - )} | ||
| 39 | - aria-hidden={!props.open} | ||
| 40 | - inert={!props.open ? true : undefined} | ||
| 41 | - > | ||
| 42 | - <div class="min-h-0 overflow-hidden"> | ||
| 43 | - <div class={cn("space-y-4 p-4 transition-opacity duration-150 motion-reduce:transition-none", props.open ? "opacity-100" : "opacity-0")}> | ||
| 44 | - {props.children} | ||
| 45 | - </div> | ||
| 46 | - </div> | ||
| 47 | - </div> | ||
| 48 | - </section> | ||
| 49 | - ); | ||
| 50 | -} | ||
src/components/ui/tabs.tsxadded+48 -0
| @@ -0,0 +1,48 @@ | |||
| 1 | +import { Tabs as TabsPrimitive } from "@kobalte/core/tabs"; | ||
| 2 | +import type { ComponentProps, ValidComponent } from "solid-js"; | ||
| 3 | +import { splitProps } from "solid-js"; | ||
| 4 | +import { cn } from "@/lib/cn"; | ||
| 5 | + | ||
| 6 | +export const Tabs = TabsPrimitive; | ||
| 7 | + | ||
| 8 | +export function TabsList<T extends ValidComponent = "div">( | ||
| 9 | + props: ComponentProps<typeof TabsPrimitive.List<T>>, | ||
| 10 | +) { | ||
| 11 | + const [local, rest] = splitProps(props as ComponentProps<typeof TabsPrimitive.List>, ["class"]); | ||
| 12 | + return ( | ||
| 13 | + <TabsPrimitive.List | ||
| 14 | + class={cn( | ||
| 15 | + "inline-flex max-w-full items-center gap-1 overflow-x-auto rounded-2xl border border-black/[0.06] bg-muted/45 p-1 text-muted-foreground shadow-sm dark:border-white/[0.08]", | ||
| 16 | + local.class, | ||
| 17 | + )} | ||
| 18 | + {...rest} | ||
| 19 | + /> | ||
| 20 | + ); | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +export function TabsTrigger<T extends ValidComponent = "button">( | ||
| 24 | + props: ComponentProps<typeof TabsPrimitive.Trigger<T>>, | ||
| 25 | +) { | ||
| 26 | + const [local, rest] = splitProps(props as ComponentProps<typeof TabsPrimitive.Trigger>, ["class"]); | ||
| 27 | + return ( | ||
| 28 | + <TabsPrimitive.Trigger | ||
| 29 | + class={cn( | ||
| 30 | + "inline-flex h-9 min-w-24 items-center justify-center whitespace-nowrap rounded-xl px-3 text-sm font-medium transition-all hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[selected]:bg-background data-[selected]:text-foreground data-[selected]:shadow-sm", | ||
| 31 | + local.class, | ||
| 32 | + )} | ||
| 33 | + {...rest} | ||
| 34 | + /> | ||
| 35 | + ); | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +export function TabsContent<T extends ValidComponent = "div">( | ||
| 39 | + props: ComponentProps<typeof TabsPrimitive.Content<T>>, | ||
| 40 | +) { | ||
| 41 | + const [local, rest] = splitProps(props as ComponentProps<typeof TabsPrimitive.Content>, ["class"]); | ||
| 42 | + return ( | ||
| 43 | + <TabsPrimitive.Content | ||
| 44 | + class={cn("mt-3 hidden rounded-2xl border border-border bg-card p-4 shadow-sm outline-none data-[selected]:block focus-visible:ring-2 focus-visible:ring-ring", local.class)} | ||
| 45 | + {...rest} | ||
| 46 | + /> | ||
| 47 | + ); | ||
| 48 | +} | ||
src/pages/course-detail-page.tsxmodified+80 -120
| @@ -36,7 +36,7 @@ import { Input } from "@/components/ui/input"; | |||
| 36 | import { Label } from "@/components/ui/label"; | 36 | import { Label } from "@/components/ui/label"; |
| 37 | import { PageSpinner } from "@/components/ui/page-spinner"; | 37 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 38 | import { Select } from "@/components/ui/select"; | 38 | import { Select } from "@/components/ui/select"; |
| 39 | -import { SectionDisclosure } from "@/components/ui/section-disclosure"; | 39 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 40 | import { SidePanel } from "@/components/ui/side-panel"; | 40 | import { SidePanel } from "@/components/ui/side-panel"; |
| 41 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 41 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 42 | import { Textarea } from "@/components/ui/textarea"; | 42 | import { Textarea } from "@/components/ui/textarea"; |
| @@ -68,7 +68,7 @@ function CourseDetailContent() { | |||
| 68 | return params().id; | 68 | return params().id; |
| 69 | }); | 69 | }); |
| 70 | 70 | ||
| 71 | - const [openSections, setOpenSections] = createSignal({ teachers: false, subjects: false, exams: false, sessions: false, roster: false }); | 71 | + const [courseTab, setCourseTab] = createSignal("subjects"); |
| 72 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); | 72 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); |
| 73 | const [terms] = createResource(async () => (await getTerms({ limit: 100 })).items); | 73 | const [terms] = createResource(async () => (await getTerms({ limit: 100 })).items); |
| 74 | const [settings] = createResource(() => getSettings()); | 74 | const [settings] = createResource(() => getSettings()); |
| @@ -232,10 +232,6 @@ function CourseDetailContent() { | |||
| 232 | ), | 232 | ), |
| 233 | }, | 233 | }, |
| 234 | ]); | 234 | ]); |
| 235 | - const toggleSection = (section: "teachers" | "subjects" | "exams" | "sessions" | "roster") => { | ||
| 236 | - setOpenSections((current) => ({ ...current, [section]: !current[section] })); | ||
| 237 | - }; | ||
| 238 | - | ||
| 239 | const [flash, setFlash] = createFlash(); | 235 | const [flash, setFlash] = createFlash(); |
| 240 | 236 | ||
| 241 | const wrap = async (fn: () => Promise<void>, ok?: string) => { | 237 | const wrap = async (fn: () => Promise<void>, ok?: string) => { |
| @@ -552,130 +548,94 @@ function CourseDetailContent() { | |||
| 552 | <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> | 548 | <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> |
| 553 | )} | 549 | )} |
| 554 | 550 | ||
| 555 | - <Show when={hasCourseManagementRights()}> | 551 | + <Tabs value={courseTab()} onChange={setCourseTab} class="space-y-3"> |
| 556 | - <SectionDisclosure | 552 | + <TabsList> |
| 557 | - open={openSections().teachers} | 553 | + <Show when={hasCourseManagementRights()}> |
| 558 | - onToggle={() => toggleSection("teachers")} | 554 | + <TabsTrigger value="teachers">{t("courses.teachers")}</TabsTrigger> |
| 559 | - title={t("courses.teachers")} | ||
| 560 | - description={countDescription((c().teachers ?? []).length, t("courses.teachers"))} | ||
| 561 | - actions={ | ||
| 562 | - <Show when={canStaffCourse()}> | ||
| 563 | - <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowTeacherForm(true)}> | ||
| 564 | - <IconPlus class="h-4 w-4" /> | ||
| 565 | - {t("courses.assignTeacher")} | ||
| 566 | - </Button> | ||
| 567 | - </Show> | ||
| 568 | - } | ||
| 569 | - > | ||
| 570 | - <CourseTeachersPanel | ||
| 571 | - courseId={id()} | ||
| 572 | - teachers={c().teachers ?? []} | ||
| 573 | - canStaff={canStaffCourse()} | ||
| 574 | - assignOpen={showTeacherForm()} | ||
| 575 | - onAssignOpenChange={setShowTeacherForm} | ||
| 576 | - onCourseUpdated={refetchCourse} | ||
| 577 | - /> | ||
| 578 | - </SectionDisclosure> | ||
| 579 | - </Show> | ||
| 580 | - | ||
| 581 | - <SectionDisclosure | ||
| 582 | - open={openSections().subjects} | ||
| 583 | - onToggle={() => toggleSection("subjects")} | ||
| 584 | - title={t("subjects.title")} | ||
| 585 | - description={countDescription(subjectCount(), t("subjects.item"))} | ||
| 586 | - actions={ | ||
| 587 | - <Show when={canManage()}> | ||
| 588 | - <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowSubjectForm(true)}> | ||
| 589 | - <IconPlus class="h-4 w-4" /> | ||
| 590 | - {t("subjects.add")} | ||
| 591 | - </Button> | ||
| 592 | </Show> | 555 | </Show> |
| 593 | - } | 556 | + <TabsTrigger value="subjects">{t("subjects.title")}</TabsTrigger> |
| 594 | - > | 557 | + <TabsTrigger value="exams">{t("courses.exams")}</TabsTrigger> |
| 595 | - <CourseSubjectsPanel courseId={id()} canManage={canManage()} active createOpen={showSubjectForm()} onCreateOpenChange={setShowSubjectForm} onCountChange={setSubjectCount} /> | 558 | + <TabsTrigger value="sessions">{t("sessions.title")}</TabsTrigger> |
| 596 | - </SectionDisclosure> | 559 | + <Show when={hasCourseManagementRights()}> |
| 597 | - | 560 | + <TabsTrigger value="roster">{t("courses.roster")}</TabsTrigger> |
| 598 | - <SectionDisclosure | ||
| 599 | - open={openSections().exams} | ||
| 600 | - onToggle={() => toggleSection("exams")} | ||
| 601 | - title={t("courses.exams")} | ||
| 602 | - description={countDescription(examCount(), t("courses.examItem"))} | ||
| 603 | - actions={ | ||
| 604 | - <Show when={canManage()}> | ||
| 605 | - <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowExamForm(true)}> | ||
| 606 | - <IconPlus class="h-4 w-4" /> | ||
| 607 | - {t("courses.addExam")} | ||
| 608 | - </Button> | ||
| 609 | </Show> | 561 | </Show> |
| 610 | - } | 562 | + </TabsList> |
| 611 | - > | ||
| 612 | - <Suspense fallback={<PageSpinner />}> | ||
| 613 | - <DataTable | ||
| 614 | - columns={examColumns()} | ||
| 615 | - data={exams() ?? []} | ||
| 616 | - filterColumn="title" | ||
| 617 | - enablePagination | ||
| 618 | - pageSize={10} | ||
| 619 | - empty={t("exams.empty")} | ||
| 620 | - onRowClick={(exam) => void navigate({ to: "/exams/$id", params: { id: exam.id } })} | ||
| 621 | - /> | ||
| 622 | - </Suspense> | ||
| 623 | - </SectionDisclosure> | ||
| 624 | 563 | ||
| 625 | - <SectionDisclosure | 564 | + <Show when={hasCourseManagementRights()}> |
| 626 | - open={openSections().sessions} | 565 | + <TabsContent value="teachers" forceMount class="space-y-4"> |
| 627 | - onToggle={() => toggleSection("sessions")} | 566 | + <div class="flex flex-wrap items-center justify-between gap-2"> |
| 628 | - title={t("sessions.title")} | 567 | + <p class="text-sm text-muted-foreground">{countDescription((c().teachers ?? []).length, t("courses.teachers"))}</p> |
| 629 | - description={countDescription(sessionCount(), t("sessions.item"))} | 568 | + <Show when={canStaffCourse()}> |
| 630 | - actions={ | 569 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowTeacherForm(true)}> |
| 631 | - <Show when={canManage()}> | 570 | + <IconPlus class="h-4 w-4" /> |
| 632 | - <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowSessionForm(true)}> | 571 | + {t("courses.assignTeacher")} |
| 633 | - <IconPlus class="h-4 w-4" /> | 572 | + </Button> |
| 634 | - {t("sessions.add")} | 573 | + </Show> |
| 635 | - </Button> | 574 | + </div> |
| 636 | - </Show> | 575 | + <CourseTeachersPanel courseId={id()} teachers={c().teachers ?? []} canStaff={canStaffCourse()} assignOpen={showTeacherForm()} onAssignOpenChange={setShowTeacherForm} onCourseUpdated={refetchCourse} /> |
| 637 | - } | 576 | + </TabsContent> |
| 638 | - > | 577 | + </Show> |
| 639 | - <CourseSessionsPanel | ||
| 640 | - courseId={id()} | ||
| 641 | - roster={roster() ?? []} | ||
| 642 | - canManage={canManage()} | ||
| 643 | - active | ||
| 644 | - createOpen={showSessionForm()} | ||
| 645 | - onCreateOpenChange={setShowSessionForm} | ||
| 646 | - onCountChange={setSessionCount} | ||
| 647 | - /> | ||
| 648 | - </SectionDisclosure> | ||
| 649 | 578 | ||
| 650 | - <Show when={hasCourseManagementRights()}> | 579 | + <TabsContent value="subjects" forceMount class="space-y-4"> |
| 651 | - <SectionDisclosure | 580 | + <div class="flex flex-wrap items-center justify-between gap-2"> |
| 652 | - open={openSections().roster} | 581 | + <p class="text-sm text-muted-foreground">{countDescription(subjectCount(), t("subjects.item"))}</p> |
| 653 | - onToggle={() => toggleSection("roster")} | ||
| 654 | - title={t("courses.roster")} | ||
| 655 | - description={countDescription(rosterCount(), t("courses.rosterItem"))} | ||
| 656 | - actions={ | ||
| 657 | <Show when={canManage()}> | 582 | <Show when={canManage()}> |
| 658 | - <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowEnrollPanel(true)}> | 583 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowSubjectForm(true)}> |
| 659 | <IconPlus class="h-4 w-4" /> | 584 | <IconPlus class="h-4 w-4" /> |
| 660 | - {t("courses.enroll")} | 585 | + {t("subjects.add")} |
| 661 | </Button> | 586 | </Button> |
| 662 | </Show> | 587 | </Show> |
| 663 | - } | 588 | + </div> |
| 664 | - > | 589 | + <CourseSubjectsPanel courseId={id()} canManage={canManage()} active createOpen={showSubjectForm()} onCreateOpenChange={setShowSubjectForm} onCountChange={setSubjectCount} /> |
| 665 | - <Suspense fallback={<PageSpinner />}> | 590 | + </TabsContent> |
| 666 | - <Show | 591 | + |
| 667 | - when={(roster() ?? []).length > 0} | 592 | + <TabsContent value="exams" forceMount class="space-y-4"> |
| 668 | - fallback={ | 593 | + <div class="flex flex-wrap items-center justify-between gap-2"> |
| 669 | - <EmptyState | 594 | + <p class="text-sm text-muted-foreground">{countDescription(examCount(), t("courses.examItem"))}</p> |
| 670 | - title={t("exams.emptyRoster")} | 595 | + <Show when={canManage()}> |
| 671 | - /> | 596 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowExamForm(true)}> |
| 672 | - } | 597 | + <IconPlus class="h-4 w-4" /> |
| 673 | - > | 598 | + {t("courses.addExam")} |
| 674 | - <DataTable columns={rosterColumns()} data={roster() ?? []} filterColumn="username" enablePagination pageSize={10} /> | 599 | + </Button> |
| 675 | </Show> | 600 | </Show> |
| 601 | + </div> | ||
| 602 | + <Suspense fallback={<PageSpinner />}> | ||
| 603 | + <DataTable columns={examColumns()} data={exams() ?? []} filterColumn="title" enablePagination pageSize={10} empty={t("exams.empty")} onRowClick={(exam) => void navigate({ to: "/exams/$id", params: { id: exam.id } })} /> | ||
| 676 | </Suspense> | 604 | </Suspense> |
| 677 | - </SectionDisclosure> | 605 | + </TabsContent> |
| 678 | - </Show> | 606 | + |
| 607 | + <TabsContent value="sessions" forceMount class="space-y-4"> | ||
| 608 | + <div class="flex flex-wrap items-center justify-between gap-2"> | ||
| 609 | + <p class="text-sm text-muted-foreground">{countDescription(sessionCount(), t("sessions.item"))}</p> | ||
| 610 | + <Show when={canManage()}> | ||
| 611 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowSessionForm(true)}> | ||
| 612 | + <IconPlus class="h-4 w-4" /> | ||
| 613 | + {t("sessions.add")} | ||
| 614 | + </Button> | ||
| 615 | + </Show> | ||
| 616 | + </div> | ||
| 617 | + <CourseSessionsPanel courseId={id()} roster={roster() ?? []} canManage={canManage()} active createOpen={showSessionForm()} onCreateOpenChange={setShowSessionForm} onCountChange={setSessionCount} /> | ||
| 618 | + </TabsContent> | ||
| 619 | + | ||
| 620 | + <Show when={hasCourseManagementRights()}> | ||
| 621 | + <TabsContent value="roster" forceMount class="space-y-4"> | ||
| 622 | + <div class="flex flex-wrap items-center justify-between gap-2"> | ||
| 623 | + <p class="text-sm text-muted-foreground">{countDescription(rosterCount(), t("courses.rosterItem"))}</p> | ||
| 624 | + <Show when={canManage()}> | ||
| 625 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => setShowEnrollPanel(true)}> | ||
| 626 | + <IconPlus class="h-4 w-4" /> | ||
| 627 | + {t("courses.enroll")} | ||
| 628 | + </Button> | ||
| 629 | + </Show> | ||
| 630 | + </div> | ||
| 631 | + <Suspense fallback={<PageSpinner />}> | ||
| 632 | + <Show when={(roster() ?? []).length > 0} fallback={<EmptyState title={t("exams.emptyRoster")} />}> | ||
| 633 | + <DataTable columns={rosterColumns()} data={roster() ?? []} filterColumn="username" enablePagination pageSize={10} /> | ||
| 634 | + </Show> | ||
| 635 | + </Suspense> | ||
| 636 | + </TabsContent> | ||
| 637 | + </Show> | ||
| 638 | + </Tabs> | ||
| 679 | </div> | 639 | </div> |
| 680 | </Show> | 640 | </Show> |
| 681 | </Show> | 641 | </Show> |
src/pages/event-detail-page.tsxmodified+80 -115
| @@ -25,8 +25,8 @@ import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | |||
| 25 | import { DataTable } from "@/components/ui/data-table"; | 25 | import { DataTable } from "@/components/ui/data-table"; |
| 26 | import { IconChevronLeft, IconEdit, IconTrash } from "@/components/ui/icons"; | 26 | import { IconChevronLeft, IconEdit, IconTrash } from "@/components/ui/icons"; |
| 27 | import { PageSpinner } from "@/components/ui/page-spinner"; | 27 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 28 | -import { SectionDisclosure } from "@/components/ui/section-disclosure"; | ||
| 29 | import { SidePanel } from "@/components/ui/side-panel"; | 28 | import { SidePanel } from "@/components/ui/side-panel"; |
| 29 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
| 30 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 30 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 31 | import { UserSearchSelect } from "@/components/users/user-search-select"; | 31 | import { UserSearchSelect } from "@/components/users/user-search-select"; |
| 32 | import { getAttendanceStatusMeta } from "@/lib/attendance-status"; | 32 | import { getAttendanceStatusMeta } from "@/lib/attendance-status"; |
| @@ -70,10 +70,8 @@ function EventDetailContent() { | |||
| 70 | const [registrationUserId, setRegistrationUserId] = createSignal(""); | 70 | const [registrationUserId, setRegistrationUserId] = createSignal(""); |
| 71 | const [editing, setEditing] = createSignal(false); | 71 | const [editing, setEditing] = createSignal(false); |
| 72 | const [deleteOpen, setDeleteOpen] = createSignal(false); | 72 | const [deleteOpen, setDeleteOpen] = createSignal(false); |
| 73 | - const [registrationOpen, setRegistrationOpen] = createSignal(false); | ||
| 74 | const [registrationTarget, setRegistrationTarget] = createSignal<string | null>(null); | 73 | const [registrationTarget, setRegistrationTarget] = createSignal<string | null>(null); |
| 75 | - const [studentAttendanceOpen, setStudentAttendanceOpen] = createSignal(false); | 74 | + const [eventTab, setEventTab] = createSignal("studentAttendance"); |
| 76 | - const [attendanceOpen, setAttendanceOpen] = createSignal(false); | ||
| 77 | const [error, setError] = createSignal(""); | 75 | const [error, setError] = createSignal(""); |
| 78 | const [pending, setPending] = createSignal(false); | 76 | const [pending, setPending] = createSignal(false); |
| 79 | 77 | ||
| @@ -81,11 +79,11 @@ function EventDetailContent() { | |||
| 81 | 79 | ||
| 82 | const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId)); | 80 | const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId)); |
| 83 | const [roster, { refetch: refetchRoster }] = createResource( | 81 | const [roster, { refetch: refetchRoster }] = createResource( |
| 84 | - () => (isTeacherPlus() && event()?.audience.kind === "registration" && registrationOpen() ? id() : null), | 82 | + () => (isTeacherPlus() && event()?.audience.kind === "registration" ? id() : null), |
| 85 | async (eventId) => (eventId ? (await getEventRoster(eventId)).items : []), | 83 | async (eventId) => (eventId ? (await getEventRoster(eventId)).items : []), |
| 86 | ); | 84 | ); |
| 87 | const [attendance, { refetch: refetchAttendance }] = createResource( | 85 | const [attendance, { refetch: refetchAttendance }] = createResource( |
| 88 | - () => (isTeacherPlus() && attendanceOpen() ? id() : null), | 86 | + () => (isTeacherPlus() ? id() : null), |
| 89 | async (eventId) => (eventId ? (await getEventAttendance(eventId)).items : []), | 87 | async (eventId) => (eventId ? (await getEventAttendance(eventId)).items : []), |
| 90 | ); | 88 | ); |
| 91 | 89 | ||
| @@ -270,107 +268,101 @@ function EventDetailContent() { | |||
| 270 | }} | 268 | }} |
| 271 | /> | 269 | /> |
| 272 | 270 | ||
| 273 | - <Show when={isTeacherPlus() && ev().audience.kind === "registration"}> | 271 | + <Show when={isTeacherPlus()}> |
| 274 | - <SectionDisclosure | 272 | + <Tabs value={eventTab()} onChange={setEventTab} class="space-y-3"> |
| 275 | - open={registrationOpen()} | 273 | + <TabsList> |
| 276 | - onToggle={() => setRegistrationOpen((open) => !open)} | 274 | + <Show when={ev().audience.kind === "registration"}> |
| 277 | - title={t("events.registrationRoster")} | 275 | + <TabsTrigger value="registration">{t("events.registrationRoster")}</TabsTrigger> |
| 278 | - description={t("events.registrationRosterHelp")} | 276 | + </Show> |
| 279 | - > | 277 | + <TabsTrigger value="studentAttendance">{t("events.studentAttendance")}</TabsTrigger> |
| 280 | - <div class="space-y-3"> | 278 | + <TabsTrigger value="attendanceRecords">{t("events.attendanceRecords")}</TabsTrigger> |
| 281 | - <div class="grid gap-3 rounded-lg border bg-muted/20 p-3 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-end"> | 279 | + </TabsList> |
| 282 | - <UserSearchSelect | 280 | + |
| 283 | - id="registration-user" | 281 | + <Show when={ev().audience.kind === "registration"}> |
| 284 | - label={t("events.attendee")} | 282 | + <TabsContent value="registration" forceMount class="space-y-3"> |
| 285 | - value={registrationUserId()} | 283 | + <p class="text-sm text-muted-foreground">{t("events.registrationRosterHelp")}</p> |
| 286 | - placeholder={t("events.selectAttendee")} | 284 | + <div class="grid gap-3 rounded-lg border bg-muted/20 p-3 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-end"> |
| 287 | - emptyMessage={t("events.noAttendees")} | 285 | + <UserSearchSelect id="registration-user" label={t("events.attendee")} value={registrationUserId()} placeholder={t("events.selectAttendee")} emptyMessage={t("events.noAttendees")} role="student" onChange={setRegistrationUserId} /> |
| 288 | - role="student" | 286 | + <Button |
| 289 | - onChange={setRegistrationUserId} | 287 | + type="button" |
| 290 | - /> | 288 | + class="rounded-xl" |
| 289 | + disabled={pending()} | ||
| 290 | + onClick={() => { | ||
| 291 | + const uid = registrationUserId().trim(); | ||
| 292 | + if (!uid) { | ||
| 293 | + setError(t("events.userIdRequired")); | ||
| 294 | + return; | ||
| 295 | + } | ||
| 296 | + void wrap(async () => { | ||
| 297 | + await postEventRegister(id(), { user_id: uid }); | ||
| 298 | + setRegistrationUserId(""); | ||
| 299 | + await refetchRoster(); | ||
| 300 | + }, t("common.saved")); | ||
| 301 | + }} | ||
| 302 | + > | ||
| 303 | + {t("events.registerStudent")} | ||
| 304 | + </Button> | ||
| 305 | + </div> | ||
| 306 | + <Suspense fallback={<PageSpinner />}> | ||
| 307 | + <Show when={roster()}> | ||
| 308 | + {(rows) => ( | ||
| 309 | + <Show when={rows().length > 0} fallback={<p class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground">{t("events.noRoster")}</p>}> | ||
| 310 | + <DataTable columns={rosterColumns()} data={rows()} filterColumn="attendee" enablePagination pageSize={10} /> | ||
| 311 | + </Show> | ||
| 312 | + )} | ||
| 313 | + </Show> | ||
| 314 | + </Suspense> | ||
| 315 | + </TabsContent> | ||
| 316 | + </Show> | ||
| 317 | + | ||
| 318 | + <TabsContent value="studentAttendance" forceMount class="space-y-3"> | ||
| 319 | + <p class="text-sm text-muted-foreground">{t("events.studentAttendanceHelp")}</p> | ||
| 320 | + <div class="grid gap-3"> | ||
| 321 | + <UserSearchSelect id="other-user" label={t("events.attendee")} value={otherUserId()} placeholder={t("events.selectAttendee")} emptyMessage={t("events.noAttendees")} role="student" onChange={setOtherUserId} /> | ||
| 322 | + <AttendanceStatusPicker id="other-status" value={status()} onChange={setStatus} label={t("events.status")} /> | ||
| 291 | <Button | 323 | <Button |
| 292 | type="button" | 324 | type="button" |
| 293 | - class="rounded-xl" | 325 | + class="w-full rounded-xl sm:w-auto" |
| 294 | disabled={pending()} | 326 | disabled={pending()} |
| 295 | onClick={() => { | 327 | onClick={() => { |
| 296 | - const uid = registrationUserId().trim(); | 328 | + const uid = otherUserId().trim(); |
| 297 | if (!uid) { | 329 | if (!uid) { |
| 298 | setError(t("events.userIdRequired")); | 330 | setError(t("events.userIdRequired")); |
| 299 | return; | 331 | return; |
| 300 | } | 332 | } |
| 301 | void wrap(async () => { | 333 | void wrap(async () => { |
| 302 | - await postEventRegister(id(), { user_id: uid }); | 334 | + await postEventAttendance(id(), { status: status(), user_id: uid }); |
| 303 | - setRegistrationUserId(""); | 335 | + setOtherUserId(""); |
| 304 | - await refetchRoster(); | 336 | + await refetchAttendance(); |
| 305 | }, t("common.saved")); | 337 | }, t("common.saved")); |
| 306 | }} | 338 | }} |
| 307 | > | 339 | > |
| 308 | - {t("events.registerStudent")} | 340 | + {t("events.saveStudentAttendance")} |
| 309 | </Button> | 341 | </Button> |
| 310 | </div> | 342 | </div> |
| 343 | + </TabsContent> | ||
| 344 | + | ||
| 345 | + <TabsContent value="attendanceRecords" forceMount class="space-y-3"> | ||
| 346 | + <p class="text-sm text-muted-foreground">{t("events.attendanceRecordsHelp")}</p> | ||
| 311 | <Suspense fallback={<PageSpinner />}> | 347 | <Suspense fallback={<PageSpinner />}> |
| 312 | - <Show when={roster()}> | 348 | + <Show when={attendance()}> |
| 313 | {(rows) => ( | 349 | {(rows) => ( |
| 314 | - <Show | 350 | + <AttendanceTable |
| 315 | - when={rows().length > 0} | 351 | + rows={rows()} |
| 316 | - fallback={<p class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground">{t("events.noRoster")}</p>} | 352 | + emptyLabel={t("events.noAttendance")} |
| 317 | - > | 353 | + canRemove={isTeacherPlus()} |
| 318 | - <DataTable columns={rosterColumns()} data={rows()} filterColumn="attendee" enablePagination pageSize={10} /> | 354 | + onRemove={async (userId) => { |
| 319 | - </Show> | 355 | + await wrap(async () => { |
| 356 | + await deleteEventAttendanceByUserId(id(), userId); | ||
| 357 | + await refetchAttendance(); | ||
| 358 | + }, t("common.deleted")); | ||
| 359 | + }} | ||
| 360 | + /> | ||
| 320 | )} | 361 | )} |
| 321 | </Show> | 362 | </Show> |
| 322 | </Suspense> | 363 | </Suspense> |
| 323 | - </div> | 364 | + </TabsContent> |
| 324 | - </SectionDisclosure> | 365 | + </Tabs> |
| 325 | - </Show> | ||
| 326 | - | ||
| 327 | - <Show when={isTeacherPlus()}> | ||
| 328 | - <SectionDisclosure | ||
| 329 | - open={studentAttendanceOpen()} | ||
| 330 | - onToggle={() => setStudentAttendanceOpen((open) => !open)} | ||
| 331 | - title={t("events.studentAttendance")} | ||
| 332 | - description={t("events.studentAttendanceHelp")} | ||
| 333 | - > | ||
| 334 | - <div class="grid gap-3"> | ||
| 335 | - <UserSearchSelect | ||
| 336 | - id="other-user" | ||
| 337 | - label={t("events.attendee")} | ||
| 338 | - value={otherUserId()} | ||
| 339 | - placeholder={t("events.selectAttendee")} | ||
| 340 | - emptyMessage={t("events.noAttendees")} | ||
| 341 | - role="student" | ||
| 342 | - onChange={setOtherUserId} | ||
| 343 | - /> | ||
| 344 | - <AttendanceStatusPicker | ||
| 345 | - id="other-status" | ||
| 346 | - value={status()} | ||
| 347 | - onChange={setStatus} | ||
| 348 | - label={t("events.status")} | ||
| 349 | - /> | ||
| 350 | - <Button | ||
| 351 | - type="button" | ||
| 352 | - class="w-full rounded-xl sm:w-auto" | ||
| 353 | - disabled={pending()} | ||
| 354 | - onClick={() => { | ||
| 355 | - const uid = otherUserId().trim(); | ||
| 356 | - if (!uid) { | ||
| 357 | - setError(t("events.userIdRequired")); | ||
| 358 | - return; | ||
| 359 | - } | ||
| 360 | - void wrap(async () => { | ||
| 361 | - await postEventAttendance(id(), { | ||
| 362 | - status: status(), | ||
| 363 | - user_id: uid, | ||
| 364 | - }); | ||
| 365 | - setOtherUserId(""); | ||
| 366 | - if (attendanceOpen()) await refetchAttendance(); | ||
| 367 | - }, t("common.saved")); | ||
| 368 | - }} | ||
| 369 | - > | ||
| 370 | - {t("events.saveStudentAttendance")} | ||
| 371 | - </Button> | ||
| 372 | - </div> | ||
| 373 | - </SectionDisclosure> | ||
| 374 | </Show> | 366 | </Show> |
| 375 | 367 | ||
| 376 | <Show when={flash()}> | 368 | <Show when={flash()}> |
| @@ -379,33 +371,6 @@ function EventDetailContent() { | |||
| 379 | {error() && ( | 371 | {error() && ( |
| 380 | <p class="rounded-sm bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> | 372 | <p class="rounded-sm bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> |
| 381 | )} | 373 | )} |
| 382 | - | ||
| 383 | - <Show when={isTeacherPlus()}> | ||
| 384 | - <SectionDisclosure | ||
| 385 | - open={attendanceOpen()} | ||
| 386 | - onToggle={() => setAttendanceOpen((open) => !open)} | ||
| 387 | - title={t("events.attendanceRecords")} | ||
| 388 | - description={t("events.attendanceRecordsHelp")} | ||
| 389 | - > | ||
| 390 | - <Suspense fallback={<PageSpinner />}> | ||
| 391 | - <Show when={attendance()}> | ||
| 392 | - {(rows) => ( | ||
| 393 | - <AttendanceTable | ||
| 394 | - rows={rows()} | ||
| 395 | - emptyLabel={t("events.noAttendance")} | ||
| 396 | - canRemove={isTeacherPlus()} | ||
| 397 | - onRemove={async (userId) => { | ||
| 398 | - await wrap(async () => { | ||
| 399 | - await deleteEventAttendanceByUserId(id(), userId); | ||
| 400 | - await refetchAttendance(); | ||
| 401 | - }, t("common.deleted")); | ||
| 402 | - }} | ||
| 403 | - /> | ||
| 404 | - )} | ||
| 405 | - </Show> | ||
| 406 | - </Suspense> | ||
| 407 | - </SectionDisclosure> | ||
| 408 | - </Show> | ||
| 409 | </div> | 374 | </div> |
| 410 | )} | 375 | )} |
| 411 | </Show> | 376 | </Show> |
src/pages/exam-detail-page.tsxmodified+107 -130
| @@ -31,7 +31,7 @@ import { IconChevronDown, IconChevronLeft, IconEdit, IconExam, IconEye, IconPlus | |||
| 31 | import { Input } from "@/components/ui/input"; | 31 | import { Input } from "@/components/ui/input"; |
| 32 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 32 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 33 | import { PageSpinner } from "@/components/ui/page-spinner"; | 33 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 34 | -import { SectionDisclosure } from "@/components/ui/section-disclosure"; | 34 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 35 | import { SidePanel } from "@/components/ui/side-panel"; | 35 | import { SidePanel } from "@/components/ui/side-panel"; |
| 36 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 36 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 37 | import { hasMinRole } from "@/lib/roles"; | 37 | import { hasMinRole } from "@/lib/roles"; |
| @@ -93,13 +93,7 @@ function ExamDetailContent() { | |||
| 93 | const [answerError, setAnswerError] = createSignal(""); | 93 | const [answerError, setAnswerError] = createSignal(""); |
| 94 | const [answerPending, setAnswerPending] = createSignal(false); | 94 | const [answerPending, setAnswerPending] = createSignal(false); |
| 95 | const [questionCreateOpen, setQuestionCreateOpen] = createSignal(false); | 95 | const [questionCreateOpen, setQuestionCreateOpen] = createSignal(false); |
| 96 | - const [openSections, setOpenSections] = createSignal({ | 96 | + const [examTab, setExamTab] = createSignal("schedule"); |
| 97 | - schedule: false, | ||
| 98 | - ownResult: false, | ||
| 99 | - statistics: false, | ||
| 100 | - questions: false, | ||
| 101 | - results: false, | ||
| 102 | - }); | ||
| 103 | const isSittable = () => { | 97 | const isSittable = () => { |
| 104 | const e = exam(); | 98 | const e = exam(); |
| 105 | return e ? isSittableExam(e) : false; | 99 | return e ? isSittableExam(e) : false; |
| @@ -345,10 +339,6 @@ function ExamDetailContent() { | |||
| 345 | setPending(false); | 339 | setPending(false); |
| 346 | } | 340 | } |
| 347 | }; | 341 | }; |
| 348 | - const toggleSection = (section: "schedule" | "ownResult" | "statistics" | "questions" | "results") => { | ||
| 349 | - setOpenSections((current) => ({ ...current, [section]: !current[section] })); | ||
| 350 | - }; | ||
| 351 | - | ||
| 352 | return ( | 342 | return ( |
| 353 | <Suspense fallback={<PageSpinner />}> | 343 | <Suspense fallback={<PageSpinner />}> |
| 354 | <Show | 344 | <Show |
| @@ -564,32 +554,6 @@ function ExamDetailContent() { | |||
| 564 | /> | 554 | /> |
| 565 | </SidePanel> | 555 | </SidePanel> |
| 566 | 556 | ||
| 567 | - <SectionDisclosure | ||
| 568 | - open={openSections().schedule} | ||
| 569 | - onToggle={() => toggleSection("schedule")} | ||
| 570 | - title={t("exams.schedule")} | ||
| 571 | - description={t("exams.details")} | ||
| 572 | - > | ||
| 573 | - <div class="grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-4"> | ||
| 574 | - <div class="detail-metric-card"> | ||
| 575 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.mode")}</p> | ||
| 576 | - <p class="mt-1 font-medium">{examModeLabel(ex().mode)}</p> | ||
| 577 | - </div> | ||
| 578 | - <div class="detail-metric-card"> | ||
| 579 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.starts")}</p> | ||
| 580 | - <p class="mono mt-1 font-medium">{formatDateTime(ex().starts_at, locale())}</p> | ||
| 581 | - </div> | ||
| 582 | - <div class="detail-metric-card"> | ||
| 583 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.ends")}</p> | ||
| 584 | - <p class="mono mt-1 font-medium">{formatDateTime(ex().ends_at, locale())}</p> | ||
| 585 | - </div> | ||
| 586 | - <div class="detail-metric-card"> | ||
| 587 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.durationMinutes")}</p> | ||
| 588 | - <p class="mono mt-1 font-medium">{formatDurationMinutes(examDurationMs(ex().duration_ms, ex().starts_at, ex().ends_at), locale())}</p> | ||
| 589 | - </div> | ||
| 590 | - </div> | ||
| 591 | - </SectionDisclosure> | ||
| 592 | - | ||
| 593 | <Show when={isStudent() && ownAttempt()?.status && (ownAttempt()!.status === "submitted" || ownAttempt()!.status === "expired")}> | 557 | <Show when={isStudent() && ownAttempt()?.status && (ownAttempt()!.status === "submitted" || ownAttempt()!.status === "expired")}> |
| 594 | <Alert variant={ownAttempt()!.status === "submitted" ? "default" : "destructive"} class="border"> | 558 | <Alert variant={ownAttempt()!.status === "submitted" ? "default" : "destructive"} class="border"> |
| 595 | <p class="text-sm font-medium"> | 559 | <p class="text-sm font-medium"> |
| @@ -605,75 +569,93 @@ function ExamDetailContent() { | |||
| 605 | </Alert> | 569 | </Alert> |
| 606 | </Show> | 570 | </Show> |
| 607 | 571 | ||
| 608 | - <Show when={isStudent() && !isScheduled()}> | 572 | + <Tabs value={examTab()} onChange={setExamTab} class="space-y-3"> |
| 609 | - <SectionDisclosure | 573 | + <TabsList> |
| 610 | - open={openSections().ownResult} | 574 | + <TabsTrigger value="schedule">{t("exams.schedule")}</TabsTrigger> |
| 611 | - onToggle={() => toggleSection("ownResult")} | 575 | + <Show when={isStudent() && !isScheduled()}> |
| 612 | - title={t("exams.yourResult")} | 576 | + <TabsTrigger value="ownResult">{t("exams.yourResult")}</TabsTrigger> |
| 613 | - description={ownResult() ? `${t("form.mark")}: ${ownResult()!.mark}` : t("exams.notGraded")} | 577 | + </Show> |
| 614 | - > | 578 | + <Show when={hasCourseManagementRights()}> |
| 615 | - <Suspense fallback={<PageSpinner />}> | 579 | + <TabsTrigger value="statistics">{t("exams.statistics")}</TabsTrigger> |
| 616 | - <Show when={ownResult()} fallback={<ExamResultBadge notGraded />}> | 580 | + <TabsTrigger value="questions">{t("questions.title")}</TabsTrigger> |
| 617 | - {(r) => <ExamResultBadge mark={r().mark} />} | 581 | + <TabsTrigger value="results">{t("exams.results")}</TabsTrigger> |
| 618 | - </Show> | 582 | + </Show> |
| 619 | - </Suspense> | 583 | + </TabsList> |
| 620 | - </SectionDisclosure> | ||
| 621 | - </Show> | ||
| 622 | 584 | ||
| 623 | - <Show when={hasCourseManagementRights()}> | 585 | + <TabsContent value="schedule" forceMount> |
| 624 | - <SectionDisclosure open={openSections().statistics} onToggle={() => toggleSection("statistics")} title={t("exams.statistics")} description={t("exams.examStatistics")}> | 586 | + <div class="mb-4 text-sm text-muted-foreground">{t("exams.details")}</div> |
| 625 | - <Suspense fallback={<PageSpinner />}> | 587 | + <div class="grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-4"> |
| 626 | - <Show when={stats()}> | 588 | + <div class="detail-metric-card"> |
| 627 | - {(s) => ( | 589 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.mode")}</p> |
| 628 | - <div class="grid gap-3 text-sm sm:grid-cols-4"> | 590 | + <p class="mt-1 font-medium">{examModeLabel(ex().mode)}</p> |
| 629 | - <div class="detail-metric-card"> | 591 | + </div> |
| 630 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.graded")}</p> | 592 | + <div class="detail-metric-card"> |
| 631 | - <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().graded}</p> | 593 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.starts")}</p> |
| 632 | - </div> | 594 | + <p class="mono mt-1 font-medium">{formatDateTime(ex().starts_at, locale())}</p> |
| 633 | - <div class="detail-metric-card"> | 595 | + </div> |
| 634 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.average")}</p> | 596 | + <div class="detail-metric-card"> |
| 635 | - <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().average == null ? "—" : s().average}</p> | 597 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("events.ends")}</p> |
| 636 | - </div> | 598 | + <p class="mono mt-1 font-medium">{formatDateTime(ex().ends_at, locale())}</p> |
| 637 | - <div class="detail-metric-card"> | 599 | + </div> |
| 638 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.min")}</p> | 600 | + <div class="detail-metric-card"> |
| 639 | - <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().min == null ? "—" : s().min}</p> | 601 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.durationMinutes")}</p> |
| 640 | - </div> | 602 | + <p class="mono mt-1 font-medium">{formatDurationMinutes(examDurationMs(ex().duration_ms, ex().starts_at, ex().ends_at), locale())}</p> |
| 641 | - <div class="detail-metric-card"> | 603 | + </div> |
| 642 | - <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.max")}</p> | 604 | + </div> |
| 643 | - <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().max == null ? "—" : s().max}</p> | 605 | + </TabsContent> |
| 606 | + | ||
| 607 | + <Show when={isStudent() && !isScheduled()}> | ||
| 608 | + <TabsContent value="ownResult" forceMount> | ||
| 609 | + <div class="mb-4 text-sm text-muted-foreground">{ownResult() ? `${t("form.mark")}: ${ownResult()!.mark}` : t("exams.notGraded")}</div> | ||
| 610 | + <Suspense fallback={<PageSpinner />}> | ||
| 611 | + <Show when={ownResult()} fallback={<ExamResultBadge notGraded />}> | ||
| 612 | + {(r) => <ExamResultBadge mark={r().mark} />} | ||
| 613 | + </Show> | ||
| 614 | + </Suspense> | ||
| 615 | + </TabsContent> | ||
| 616 | + </Show> | ||
| 617 | + | ||
| 618 | + <Show when={hasCourseManagementRights()}> | ||
| 619 | + <TabsContent value="statistics" forceMount> | ||
| 620 | + <div class="mb-4 text-sm text-muted-foreground">{t("exams.examStatistics")}</div> | ||
| 621 | + <Suspense fallback={<PageSpinner />}> | ||
| 622 | + <Show when={stats()}> | ||
| 623 | + {(s) => ( | ||
| 624 | + <div class="grid gap-3 text-sm sm:grid-cols-4"> | ||
| 625 | + <div class="detail-metric-card"> | ||
| 626 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.graded")}</p> | ||
| 627 | + <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().graded}</p> | ||
| 628 | + </div> | ||
| 629 | + <div class="detail-metric-card"> | ||
| 630 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.average")}</p> | ||
| 631 | + <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().average == null ? "—" : s().average}</p> | ||
| 632 | + </div> | ||
| 633 | + <div class="detail-metric-card"> | ||
| 634 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.min")}</p> | ||
| 635 | + <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().min == null ? "—" : s().min}</p> | ||
| 636 | + </div> | ||
| 637 | + <div class="detail-metric-card"> | ||
| 638 | + <p class="text-xs font-medium uppercase tracking-[0.08em] text-muted-foreground">{t("exams.max")}</p> | ||
| 639 | + <p class="mono mt-1 text-2xl font-semibold tabular-nums">{s().max == null ? "—" : s().max}</p> | ||
| 640 | + </div> | ||
| 644 | </div> | 641 | </div> |
| 645 | - </div> | 642 | + )} |
| 646 | - )} | 643 | + </Show> |
| 647 | - </Show> | 644 | + </Suspense> |
| 648 | - </Suspense> | 645 | + </TabsContent> |
| 649 | - </SectionDisclosure> | ||
| 650 | 646 | ||
| 651 | - <SectionDisclosure | 647 | + <TabsContent value="questions" forceMount class="space-y-4"> |
| 652 | - open={openSections().questions} | 648 | + <div class="flex flex-wrap items-center justify-between gap-2"> |
| 653 | - onToggle={() => toggleSection("questions")} | 649 | + <p class="text-sm text-muted-foreground">{t("exams.examQuestions")}</p> |
| 654 | - title={t("questions.title")} | 650 | + <Show when={hasCourseManagementRights() && !isFinished()}> |
| 655 | - description={t("exams.examQuestions")} | 651 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={() => { setExamTab("questions"); setQuestionCreateOpen(true); }}> |
| 656 | - actions={ | 652 | + <IconPlus class="h-4 w-4" /> |
| 657 | - <Show when={hasCourseManagementRights() && !isFinished()}> | 653 | + {t("questions.add")} |
| 658 | - <Button | 654 | + </Button> |
| 659 | - type="button" | 655 | + </Show> |
| 660 | - variant="outline" | 656 | + </div> |
| 661 | - size="sm" | 657 | + <ExamQuestionsPanel examId={id()} courseId={ex().course} readOnly={isFinished()} embedded createOpen={questionCreateOpen()} onCreateOpenChange={setQuestionCreateOpen} /> |
| 662 | - class="rounded-lg" | 658 | + </TabsContent> |
| 663 | - onClick={(event) => { | ||
| 664 | - event.stopPropagation(); | ||
| 665 | - setOpenSections((current) => ({ ...current, questions: true })); | ||
| 666 | - setQuestionCreateOpen(true); | ||
| 667 | - }} | ||
| 668 | - > | ||
| 669 | - <IconPlus class="h-4 w-4" /> | ||
| 670 | - {t("questions.add")} | ||
| 671 | - </Button> | ||
| 672 | - </Show> | ||
| 673 | - } | ||
| 674 | - > | ||
| 675 | - <ExamQuestionsPanel examId={id()} courseId={ex().course} readOnly={isFinished()} embedded createOpen={questionCreateOpen()} onCreateOpenChange={setQuestionCreateOpen} /> | ||
| 676 | - </SectionDisclosure> | ||
| 677 | 659 | ||
| 678 | <SidePanel | 660 | <SidePanel |
| 679 | open={gradeOpen()} | 661 | open={gradeOpen()} |
| @@ -695,37 +677,32 @@ function ExamDetailContent() { | |||
| 695 | /> | 677 | /> |
| 696 | </SidePanel> | 678 | </SidePanel> |
| 697 | 679 | ||
| 698 | - <SectionDisclosure | 680 | + <TabsContent value="results" forceMount class="space-y-4"> |
| 699 | - open={openSections().results} | 681 | + <div class="flex flex-wrap items-center justify-between gap-2"> |
| 700 | - onToggle={() => toggleSection("results")} | 682 | + <p class="text-sm text-muted-foreground">{`${resultTotal()} ${t("exams.studentResults")}`}</p> |
| 701 | - title={t("exams.results")} | ||
| 702 | - description={`${resultTotal()} ${t("exams.studentResults")}`} | ||
| 703 | - actions={ | ||
| 704 | - <Show when={hasCourseManagementRights()}> | ||
| 705 | <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={isDraft()} onClick={() => setGradeOpen(true)}> | 683 | <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={isDraft()} onClick={() => setGradeOpen(true)}> |
| 706 | <IconEdit class="h-4 w-4" /> | 684 | <IconEdit class="h-4 w-4" /> |
| 707 | {t("exams.gradeStudent")} | 685 | {t("exams.gradeStudent")} |
| 708 | </Button> | 686 | </Button> |
| 709 | - </Show> | 687 | + </div> |
| 710 | - } | 688 | + <Suspense fallback={<PageSpinner />}> |
| 711 | - > | 689 | + <Show |
| 712 | - <Suspense fallback={<PageSpinner />}> | 690 | + when={(results()?.items ?? []).length > 0} |
| 713 | - <Show | 691 | + fallback={ |
| 714 | - when={(results()?.items ?? []).length > 0} | 692 | + <p class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground"> |
| 715 | - fallback={ | 693 | + {t("exams.noResults")} |
| 716 | - <p class="rounded-lg border border-dashed border-border/80 bg-muted/20 px-4 py-8 text-center text-sm text-muted-foreground"> | 694 | + </p> |
| 717 | - {t("exams.noResults")} | 695 | + } |
| 718 | - </p> | 696 | + > |
| 719 | - } | 697 | + <DataTable columns={resultColumns()} data={results()?.items ?? []} filterColumn="user" /> |
| 720 | - > | 698 | + <Show when={resultTotal() > RESULT_PAGE_SIZE}> |
| 721 | - <DataTable columns={resultColumns()} data={results()?.items ?? []} filterColumn="user" /> | 699 | + <PaginationControls page={Math.min(resultPage(), resultTotalPages() - 1)} totalPages={resultTotalPages()} onPageChange={setResultPage} /> |
| 722 | - <Show when={resultTotal() > RESULT_PAGE_SIZE}> | 700 | + </Show> |
| 723 | - <PaginationControls page={Math.min(resultPage(), resultTotalPages() - 1)} totalPages={resultTotalPages()} onPageChange={setResultPage} /> | ||
| 724 | </Show> | 701 | </Show> |
| 725 | - </Show> | 702 | + </Suspense> |
| 726 | - </Suspense> | 703 | + </TabsContent> |
| 727 | - </SectionDisclosure> | 704 | + </Show> |
| 728 | - </Show> | 705 | + </Tabs> |
| 729 | 706 | ||
| 730 | <Show when={flash()}> | 707 | <Show when={flash()}> |
| 731 | <Alert variant="success">{flash()}</Alert> | 708 | <Alert variant="success">{flash()}</Alert> |