forge
Explore
Log in

Don't you dare go Hollow

✨ Enhance dashboard with new portal cards and statistics

Browse files at this commit

50fd345c74bf42405226513f7160428099065e26Burak BoduroğluParent: 7067ea0
  • feat
    • ✨ Enhance dashboard with new portal cards and statistics
Show full message
feat: ✨ Enhance dashboard with new portal cards and statistics
src/components/dashboard/role-home-panel.tsxdeleted+0 -95
@@ -1,95 +0,0 @@
1-import { Link } from "@tanstack/solid-router";
2-import { For } from "solid-js";
3-import type { Role } from "@/api/types";
4-import type { MessageKey } from "@/i18n/messages";
5-import { useT } from "@/stores/preferences-context";
6-import { cn } from "@/lib/cn";
7-
8-type RoleAction = {
9- to: string;
10- title: MessageKey;
11- hint: MessageKey;
12- marker: string;
13- tone: "mint" | "sky" | "amber" | "violet" | "rose";
14-};
15-
16-const ROLE_KEY: Record<Role, MessageKey> = {
17- student: "role.student",
18- teacher: "role.teacher",
19- manager: "role.manager",
20- admin: "role.admin",
21-};
22-
23-const ROLE_ACTIONS: Record<Role, RoleAction[]> = {
24- student: [
25- { to: "/marks", title: "dashboard.action.marks", hint: "dashboard.action.marksHint", marker: "▤", tone: "mint" },
26- { to: "/exams", title: "dashboard.myExams", hint: "exams.subtitle", marker: "☰", tone: "rose" },
27- { to: "/events", title: "dashboard.action.attend", hint: "dashboard.action.attendHint", marker: "◷", tone: "sky" },
28- ],
29- teacher: [
30- { to: "/courses", title: "dashboard.action.course", hint: "dashboard.action.courseHint", marker: "▣", tone: "violet" },
31- { to: "/courses", title: "dashboard.action.exam", hint: "dashboard.action.examHint", marker: "☰", tone: "rose" },
32- { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "amber" },
33- ],
34- manager: [
35- { to: "/courses", title: "nav.courses", hint: "courses.subtitle", marker: "▣", tone: "violet" },
36- { to: "/events", title: "nav.events", hint: "events.subtitle", marker: "◷", tone: "sky" },
37- { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "amber" },
38- { to: "/marks", title: "dashboard.action.marks", hint: "dashboard.action.marksHint", marker: "▤", tone: "mint" },
39- ],
40- admin: [
41- { to: "/admin/users", title: "nav.users", hint: "admin.subtitle", marker: "◉", tone: "amber" },
42- { to: "/courses", title: "nav.courses", hint: "courses.subtitle", marker: "▣", tone: "violet" },
43- { to: "/events", title: "nav.events", hint: "events.subtitle", marker: "◷", tone: "sky" },
44- { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "rose" },
45- ],
46-};
47-
48-export function RoleHomePanel(props: { role: Role }) {
49- const t = useT();
50- const actions = () => ROLE_ACTIONS[props.role];
51- const markerTone = {
52- mint: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
53- sky: "bg-sky-500/10 text-sky-700 dark:text-sky-300",
54- amber: "bg-amber-500/10 text-amber-700 dark:text-amber-300",
55- violet: "bg-violet-500/10 text-violet-700 dark:text-violet-300",
56- rose: "bg-rose-500/10 text-rose-700 dark:text-rose-300",
57- };
58-
59- return (
60- <section class="surface-card relative overflow-hidden p-4 sm:p-5">
61- <div class="pointer-events-none absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-primary/30 to-transparent" />
62- <div class="mb-4">
63- <div>
64- <p class="text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground">
65- {t("dashboard.overview")}
66- </p>
67- <h2 class="mt-1 font-display text-lg font-semibold">
68- {t("dashboard.stats.role")}: {t(ROLE_KEY[props.role])}
69- </h2>
70- </div>
71- </div>
72-
73- <div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
74- <For each={actions()}>
75- {(action) => (
76- <Link
77- to={action.to}
78- class="group flex min-h-24 items-center gap-3 rounded-lg border border-border/80 bg-gradient-to-br from-card to-muted/20 px-4 py-3 shadow-sm transition-all hover:-translate-y-0.5 hover:border-primary/30 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
79- >
80- <span class={cn("flex h-11 w-11 shrink-0 items-center justify-center rounded-lg text-lg", markerTone[action.tone])}>
81- {action.marker}
82- </span>
83- <span class="min-w-0">
84- <span class="block truncate text-sm font-semibold group-hover:text-primary">{t(action.title)}</span>
85- <span class="mt-0.5 block line-clamp-2 text-xs leading-relaxed text-muted-foreground">
86- {t(action.hint)}
87- </span>
88- </span>
89- </Link>
90- )}
91- </For>
92- </div>
93- </section>
94- );
95-}
src/i18n/messages.tsmodified+93 -0
@@ -117,9 +117,28 @@ export type MessageKey =
117 | "dashboard.stats.notes"117 | "dashboard.stats.notes"
118 | "dashboard.stats.events"118 | "dashboard.stats.events"
119 | "dashboard.stats.exams"119 | "dashboard.stats.exams"
120+ | "dashboard.stats.courses"
120 | "dashboard.stats.role"121 | "dashboard.stats.role"
121 | "dashboard.stats.average"122 | "dashboard.stats.average"
122 | "dashboard.stats.averageHint"123 | "dashboard.stats.averageHint"
124+ | "dashboard.commandCenter"
125+ | "dashboard.observationOnly"
126+ | "dashboard.today"
127+ | "dashboard.reportCard"
128+ | "dashboard.ready"
129+ | "dashboard.attention"
130+ | "dashboard.timeline"
131+ | "dashboard.activeNow"
132+ | "dashboard.upcoming"
133+ | "dashboard.nextEvent"
134+ | "dashboard.courseLoad"
135+ | "dashboard.latestWindow"
136+ | "dashboard.noAttention"
137+ | "dashboard.allClear"
138+ | "dashboard.roleLinks"
139+ | "dashboard.activityGraph"
140+ | "dashboard.activityGraphDesc"
141+ | "dashboard.records"
123 | "dashboard.myExams"142 | "dashboard.myExams"
124 | "dashboard.emptyExamsTitle"143 | "dashboard.emptyExamsTitle"
125 | "dashboard.emptyExamsCta"144 | "dashboard.emptyExamsCta"
@@ -136,6 +155,18 @@ export type MessageKey =
136 | "dashboard.helpTitle"155 | "dashboard.helpTitle"
137 | "dashboard.helpBody"156 | "dashboard.helpBody"
138 | "dashboard.continueGuide"157 | "dashboard.continueGuide"
158+ | "dashboard.portal.sections"
159+ | "dashboard.portal.coursesDesc"
160+ | "dashboard.portal.examsDesc"
161+ | "dashboard.portal.eventsDesc"
162+ | "dashboard.portal.marksDesc"
163+ | "dashboard.portal.notesDesc"
164+ | "dashboard.portal.usersDesc"
165+ | "dashboard.portal.attendanceDesc"
166+ | "dashboard.portal.workDesc"
167+ | "dashboard.portal.studentMarksDesc"
168+ | "dashboard.portal.settingsDesc"
169+ | "dashboard.portal.termsDesc"
139 | "notes.title"170 | "notes.title"
140 | "notes.subtitle"171 | "notes.subtitle"
141 | "notes.new"172 | "notes.new"
@@ -553,9 +584,28 @@ const en: Dict = {
553 "dashboard.stats.notes": "Notes",584 "dashboard.stats.notes": "Notes",
554 "dashboard.stats.events": "Events",585 "dashboard.stats.events": "Events",
555 "dashboard.stats.exams": "Exams",586 "dashboard.stats.exams": "Exams",
587+ "dashboard.stats.courses": "Courses",
556 "dashboard.stats.role": "Your role",588 "dashboard.stats.role": "Your role",
557 "dashboard.stats.average": "Average",589 "dashboard.stats.average": "Average",
558 "dashboard.stats.averageHint": "Overall report card",590 "dashboard.stats.averageHint": "Overall report card",
591+ "dashboard.commandCenter": "Command center",
592+ "dashboard.observationOnly": "A live read-only map of your school day.",
593+ "dashboard.today": "Today",
594+ "dashboard.reportCard": "Report card",
595+ "dashboard.ready": "Ready",
596+ "dashboard.attention": "Needs attention",
597+ "dashboard.timeline": "Upcoming timeline",
598+ "dashboard.activeNow": "Active now",
599+ "dashboard.upcoming": "Upcoming",
600+ "dashboard.nextEvent": "Next event",
601+ "dashboard.courseLoad": "Course load",
602+ "dashboard.latestWindow": "Latest window",
603+ "dashboard.noAttention": "Nothing urgent",
604+ "dashboard.allClear": "No active exam or near event needs action right now.",
605+ "dashboard.roleLinks": "Workspace overview",
606+ "dashboard.activityGraph": "Activity graph",
607+ "dashboard.activityGraphDesc": "Events, exams, and courses at a glance.",
608+ "dashboard.records": "records",
559 "dashboard.myExams": "My exams",609 "dashboard.myExams": "My exams",
560 "dashboard.emptyExamsTitle": "No exams yet",610 "dashboard.emptyExamsTitle": "No exams yet",
561 "dashboard.emptyExamsCta": "Browse exams",611 "dashboard.emptyExamsCta": "Browse exams",
@@ -573,6 +623,18 @@ const en: Dict = {
573 "dashboard.helpBody":623 "dashboard.helpBody":
574 "Home shows live counts and shortcuts for notes, events, courses, exams, and your report card. Open Guide (bottom of the sidebar) for the full walkthrough.",624 "Home shows live counts and shortcuts for notes, events, courses, exams, and your report card. Open Guide (bottom of the sidebar) for the full walkthrough.",
575 "dashboard.continueGuide": "Open the guide",625 "dashboard.continueGuide": "Open the guide",
626+ "dashboard.portal.sections": "Sections",
627+ "dashboard.portal.coursesDesc": "Browse courses and class materials.",
628+ "dashboard.portal.examsDesc": "Upcoming exams, deadlines, and results.",
629+ "dashboard.portal.eventsDesc": "Sessions, meetups, and attendance.",
630+ "dashboard.portal.marksDesc": "Your grades and overall report card.",
631+ "dashboard.portal.notesDesc": "Private scratchpad for quick ideas.",
632+ "dashboard.portal.usersDesc": "Manage user accounts and roles.",
633+ "dashboard.portal.attendanceDesc": "Mark and review attendance records.",
634+ "dashboard.portal.workDesc": "Track your work hours and shifts.",
635+ "dashboard.portal.studentMarksDesc": "View and grade student results.",
636+ "dashboard.portal.settingsDesc": "System preferences and configuration.",
637+ "dashboard.portal.termsDesc": "Manage academic terms and periods.",
576 "notes.title": "Notebook",638 "notes.title": "Notebook",
577 "notes.subtitle": "Private scratchpad for class ideas and reminders.",639 "notes.subtitle": "Private scratchpad for class ideas and reminders.",
578 "notes.new": "New note",640 "notes.new": "New note",
@@ -1002,9 +1064,28 @@ const tr: Dict = {
1002 "dashboard.stats.notes": "Notlar",1064 "dashboard.stats.notes": "Notlar",
1003 "dashboard.stats.events": "Etkinlikler",1065 "dashboard.stats.events": "Etkinlikler",
1004 "dashboard.stats.exams": "Sınavlar",1066 "dashboard.stats.exams": "Sınavlar",
1067+ "dashboard.stats.courses": "Dersler",
1005 "dashboard.stats.role": "Rolün",1068 "dashboard.stats.role": "Rolün",
1006 "dashboard.stats.average": "Ortalama",1069 "dashboard.stats.average": "Ortalama",
1007 "dashboard.stats.averageHint": "Genel karne",1070 "dashboard.stats.averageHint": "Genel karne",
1071+ "dashboard.commandCenter": "Komuta merkezi",
1072+ "dashboard.observationOnly": "Okul gününün canlı ve salt okunur haritası.",
1073+ "dashboard.today": "Bugün",
1074+ "dashboard.reportCard": "Karne",
1075+ "dashboard.ready": "Hazır",
1076+ "dashboard.attention": "Dikkat isteyenler",
1077+ "dashboard.timeline": "Yaklaşan akış",
1078+ "dashboard.activeNow": "Şu an aktif",
1079+ "dashboard.upcoming": "Yaklaşan",
1080+ "dashboard.nextEvent": "Sıradaki etkinlik",
1081+ "dashboard.courseLoad": "Ders yükü",
1082+ "dashboard.latestWindow": "Güncel pencere",
1083+ "dashboard.noAttention": "Acil bir şey yok",
1084+ "dashboard.allClear": "Şu an işlem isteyen aktif sınav veya yakın etkinlik yok.",
1085+ "dashboard.roleLinks": "Çalışma alanı özeti",
1086+ "dashboard.activityGraph": "Aktivite grafiği",
1087+ "dashboard.activityGraphDesc": "Etkinlik, sınav ve ders yoğunluğu tek bakışta.",
1088+ "dashboard.records": "kayıt",
1008 "dashboard.myExams": "Sınavlarım",1089 "dashboard.myExams": "Sınavlarım",
1009 "dashboard.emptyExamsTitle": "Henüz sınav yok",1090 "dashboard.emptyExamsTitle": "Henüz sınav yok",
1010 "dashboard.emptyExamsCta": "Sınavlara git",1091 "dashboard.emptyExamsCta": "Sınavlara git",
@@ -1022,6 +1103,18 @@ const tr: Dict = {
1022 "dashboard.helpBody":1103 "dashboard.helpBody":
1023 "Ana sayfa not, etkinlik, ders, sınav ve karne kısayollarını gösterir. Tam tur için sidebar’ın altındaki Rehber’i aç.",1104 "Ana sayfa not, etkinlik, ders, sınav ve karne kısayollarını gösterir. Tam tur için sidebar’ın altındaki Rehber’i aç.",
1024 "dashboard.continueGuide": "Rehberi aç",1105 "dashboard.continueGuide": "Rehberi aç",
1106+ "dashboard.portal.sections": "Bölümler",
1107+ "dashboard.portal.coursesDesc": "Dersleri ve ders materyallerini görüntüle.",
1108+ "dashboard.portal.examsDesc": "Sınavlar, son teslim tarihleri ve sonuçlar.",
1109+ "dashboard.portal.eventsDesc": "Oturumlar, etkinlikler ve yoklama.",
1110+ "dashboard.portal.marksDesc": "Notların ve genel karnen.",
1111+ "dashboard.portal.notesDesc": "Hızlı fikirler için özel not defteri.",
1112+ "dashboard.portal.usersDesc": "Kullanıcı hesaplarını ve rollerini yönet.",
1113+ "dashboard.portal.attendanceDesc": "Yoklama kayıtlarını işaretle ve incele.",
1114+ "dashboard.portal.workDesc": "Çalışma saatlerini ve mesainizi takip edin.",
1115+ "dashboard.portal.studentMarksDesc": "Öğrenci sonuçlarını görüntüle ve notlandır.",
1116+ "dashboard.portal.settingsDesc": "Sistem tercihleri ve yapılandırma.",
1117+ "dashboard.portal.termsDesc": "Akademik dönemleri ve periyotları yönet.",
1025 "notes.title": "Defter",1118 "notes.title": "Defter",
1026 "notes.subtitle": "Ders fikirleri ve hatırlatmalar için özel defter.",1119 "notes.subtitle": "Ders fikirleri ve hatırlatmalar için özel defter.",
1027 "notes.new": "Yeni not",1120 "notes.new": "Yeni not",
src/pages/dashboard-page.tsxmodified+383 -242
@@ -1,31 +1,75 @@
1+import { For, Show, Suspense, createMemo, createResource, type JSX } from "solid-js";
1 import { Link } from "@tanstack/solid-router";2 import { Link } from "@tanstack/solid-router";
2-import { For, Show, Suspense, createMemo, createResource } from "solid-js";3+import { formatApiError } from "@/api/client";
4+import { getCourses } from "@/api/getCourses";
3 import { getEvents } from "@/api/getEvents";5 import { getEvents } from "@/api/getEvents";
4 import { getExams } from "@/api/getExams";6 import { getExams } from "@/api/getExams";
5 import { getMyCourses } from "@/api/getMyCourses";7 import { getMyCourses } from "@/api/getMyCourses";
6 import { getMyMarks } from "@/api/getMyMarks";8 import { getMyMarks } from "@/api/getMyMarks";
7 import { getNotes } from "@/api/getNotes";9 import { getNotes } from "@/api/getNotes";
8-import { formatApiError } from "@/api/client";10+import type { Role } from "@/api/types";
9-import type { Event, Exam, Note } from "@/api/types";
10-import { ExamLink } from "@/components/exams/exam-link";
11-import { RouteGuard } from "@/components/layout/route-guard";
12 import { PageHeader } from "@/components/layout/page-header";11 import { PageHeader } from "@/components/layout/page-header";
12+import { RouteGuard } from "@/components/layout/route-guard";
13 import { Alert } from "@/components/ui/alert";13 import { Alert } from "@/components/ui/alert";
14 import { Badge } from "@/components/ui/badge";14 import { Badge } from "@/components/ui/badge";
15 import {15 import {
16+ IconBook,
16 IconCalendar,17 IconCalendar,
18+ IconChart,
19+ IconClipboardCheck,
17 IconExam,20 IconExam,
18 IconNote,21 IconNote,
22+ IconReportAnalytics,
23+ IconSchool,
24+ IconSettings,
25+ IconUsers,
19 } from "@/components/ui/icons";26 } from "@/components/ui/icons";
20 import { PageSpinner } from "@/components/ui/page-spinner";27 import { PageSpinner } from "@/components/ui/page-spinner";
21-import { useAuth } from "@/stores/auth-context";28+import type { Locale, MessageKey } from "@/i18n/messages";
22-import { usePreferences, useT } from "@/stores/preferences-context";29+import { cn } from "@/lib/cn";
23 import { examKindLabel } from "@/lib/exam-labels";30 import { examKindLabel } from "@/lib/exam-labels";
24 import { formatDateTime } from "@/lib/format";31 import { formatDateTime } from "@/lib/format";
25-import { cn } from "@/lib/cn";32+import { hasMinRole } from "@/lib/roles";
33+import { useAuth } from "@/stores/auth-context";
34+import { usePreferences, useT } from "@/stores/preferences-context";
26 35
27 const PREVIEW_LIMIT = 5;36 const PREVIEW_LIMIT = 5;
28 37
38+interface PortalCard {
39+ icon: JSX.Element;
40+ titleKey: MessageKey;
41+ to: string;
42+ descKey: MessageKey;
43+ stat: () => string | number;
44+ statSuffix?: MessageKey;
45+ accent: string;
46+ minRole?: Role;
47+}
48+
49+interface TimelineItem {
50+ id: string;
51+ type: "event" | "exam";
52+ title: string;
53+ at: number | null;
54+ subtitle: string;
55+}
56+
57+const ROLE_KEY: Record<Role, MessageKey> = {
58+ student: "role.student",
59+ teacher: "role.teacher",
60+ manager: "role.manager",
61+ admin: "role.admin",
62+};
63+
64+const ROLE_BADGE_TONE: Record<Role, string> = {
65+ student: "border-blue-500/30 bg-blue-500/10 text-blue-700 dark:text-blue-300",
66+ teacher: "border-blue-500/30 bg-blue-500/10 text-blue-700 dark:text-blue-300",
67+ manager: "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300",
68+ admin: "border-red-500/30 bg-red-500/10 text-red-700 dark:text-red-300",
69+};
70+
71+const CHART_TONES = ["bg-violet-500", "bg-amber-500", "bg-sky-500", "bg-emerald-500", "bg-rose-500"];
72+
29 const roundAvg = (n: number) => (Math.round(n * 10) / 10).toString();73 const roundAvg = (n: number) => (Math.round(n * 10) / 10).toString();
30 74
31 export default function DashboardPage() {75 export default function DashboardPage() {
@@ -41,281 +85,378 @@ function DashboardContent() {
41 const t = useT();85 const t = useT();
42 const { locale } = usePreferences();86 const { locale } = usePreferences();
43 const user = () => auth.user()!;87 const user = () => auth.user()!;
88+ const role = () => user().role;
44 89
45- const [notes] = createResource(() => getNotes());90+ const [courses] = createResource(() => getCourses());
91+ const [myCourses] = createResource(async () => getMyCourses().catch(() => []));
46 const [events] = createResource(() => getEvents());92 const [events] = createResource(() => getEvents());
47 const [exams] = createResource(() => getExams());93 const [exams] = createResource(() => getExams());
48- const [myCourses] = createResource(94+ const [notes] = createResource(() => getNotes());
49- () => (user().role === "student" ? true : null),95+ const [marks] = createResource(
50- async (enabled) => (enabled ? getMyCourses() : []),96+ () => (role() === "student" ? true : null),
97+ async (enabled) => (enabled ? getMyMarks() : null),
51 );98 );
52- const [marks] = createResource(() => getMyMarks());
53 99
54 const resourceError = createMemo(() => {100 const resourceError = createMemo(() => {
55- const e = notes.error || events.error || exams.error || myCourses.error || marks.error;101+ const e = courses.error || myCourses.error || events.error || exams.error || notes.error || marks.error;
56 return e ? formatApiError(e, locale()) : null;102 return e ? formatApiError(e, locale()) : null;
57 });103 });
58 104
105+ const fullName = () => [user().name, user().surname].filter(Boolean).join(" ") || user().username;
106+
107+ const now = () => Date.now();
108+
109+ const eventItems = () => (events() ?? []).map((event) => ({
110+ id: event.id,
111+ type: "event" as const,
112+ title: event.title,
113+ at: event.starts_at,
114+ subtitle: event.description || t("nav.events"),
115+ }));
116+
117+ const courseMap = createMemo(() => {
118+ const map = new Map<string, string>();
119+ for (const course of courses() ?? []) map.set(course.id, course.title);
120+ for (const course of myCourses() ?? []) map.set(course.id, course.title);
121+ return map;
122+ });
123+
124+ const hasGlobalDashboardScope = createMemo(() => hasMinRole(role(), "admin"));
125+ const scopedCourses = createMemo(() => (hasGlobalDashboardScope() ? courses() ?? [] : myCourses() ?? []));
126+ const scopedCourseIds = createMemo(() => new Set(scopedCourses().map((course) => course.id)));
127+
59 const visibleExams = createMemo(() => {128 const visibleExams = createMemo(() => {
60- const all = exams() ?? [];129+ if (hasGlobalDashboardScope()) return exams() ?? [];
61- if (user().role !== "student") return all;130+ const allowed = scopedCourseIds();
62- const allowed = new Set((myCourses() ?? []).map((course) => course.id));131+ if (allowed.size === 0) return [];
63- return all.filter((exam) => allowed.has(exam.course));132+ return (exams() ?? []).filter((exam) => allowed.has(exam.course));
133+ });
134+
135+ const courseCount = createMemo(() => {
136+ if (hasGlobalDashboardScope() && courses.loading) return null;
137+ if (!hasGlobalDashboardScope() && myCourses.loading) return null;
138+ return scopedCourses().length;
64 });139 });
140+ const totalExamsCount = createMemo(() => (exams.loading ? null : visibleExams().length));
141+ const totalEventsCount = createMemo(() => (events.loading ? null : events()?.length ?? 0));
142+ const totalNotesCount = createMemo(() => (notes.loading ? null : notes()?.length ?? 0));
143+ const displayCount = (count: number | null) => count ?? "...";
65 144
66- const noteCount = createMemo(() => notes()?.length ?? 0);
67- const eventCount = createMemo(() => events()?.length ?? 0);
68- const examCount = createMemo(() => visibleExams().length);
69 const overallAvg = createMemo(() => marks()?.overall_average ?? null);145 const overallAvg = createMemo(() => marks()?.overall_average ?? null);
70 146
71- const previewNotes = createMemo(() => (notes() ?? []).slice(0, PREVIEW_LIMIT));147+ const timeline = createMemo<TimelineItem[]>(() => {
72- const previewEvents = createMemo(() => (events() ?? []).slice(0, PREVIEW_LIMIT));148+ const examItems: TimelineItem[] = visibleExams().map((exam) => ({
73- const previewExams = createMemo(() => visibleExams().slice(0, PREVIEW_LIMIT));149+ id: exam.id,
150+ type: "exam" as const,
151+ title: exam.title,
152+ at: exam.starts_at,
153+ subtitle: courseMap().get(exam.course) ?? examKindLabel(String(exam.kind), t),
154+ }));
155+ const allItems = [...eventItems(), ...examItems];
156+ const upcomingItems = allItems
157+ .filter((item) => item.at != null && item.at >= now())
158+ .sort((a, b) => (a.at ?? 0) - (b.at ?? 0));
159+ const fallbackItems = allItems
160+ .sort((a, b) => (b.at ?? 0) - (a.at ?? 0));
161+ return (upcomingItems.length > 0 ? upcomingItems : fallbackItems).slice(0, PREVIEW_LIMIT);
162+ });
163+
164+ const chartData = createMemo(() => [
165+ { label: t("dashboard.stats.courses"), value: courseCount() ?? 0 },
166+ { label: t("dashboard.stats.exams"), value: totalExamsCount() ?? 0 },
167+ { label: t("dashboard.stats.events"), value: totalEventsCount() ?? 0 },
168+ ]);
169+
170+ const maxChartValue = createMemo(() =>
171+ Math.max(1, ...chartData().map((d) => d.value)),
172+ );
173+
174+ const cards = createMemo(() => {
175+ const roleVal = role();
176+ const list: PortalCard[] = [];
177+
178+ if (roleVal === "student") {
179+ list.push(
180+ {
181+ icon: <IconSchool class="h-5 w-5" />,
182+ titleKey: "nav.courses",
183+ to: "/courses",
184+ descKey: "dashboard.portal.coursesDesc",
185+ stat: () => displayCount(courseCount()),
186+ statSuffix: "dashboard.records",
187+ accent: "violet",
188+ },
189+ {
190+ icon: <IconExam class="h-5 w-5" />,
191+ titleKey: "nav.exams",
192+ to: "/exams",
193+ descKey: "dashboard.portal.examsDesc",
194+ stat: () => displayCount(totalExamsCount()),
195+ statSuffix: "dashboard.records",
196+ accent: "amber",
197+ },
198+ {
199+ icon: <IconCalendar class="h-5 w-5" />,
200+ titleKey: "nav.events",
201+ to: "/events",
202+ descKey: "dashboard.portal.eventsDesc",
203+ stat: () => displayCount(totalEventsCount()),
204+ statSuffix: "dashboard.records",
205+ accent: "sky",
206+ },
207+ {
208+ icon: <IconReportAnalytics class="h-5 w-5" />,
209+ titleKey: "nav.marks",
210+ to: "/marks",
211+ descKey: "dashboard.portal.marksDesc",
212+ stat: () => (overallAvg() == null ? "--" : roundAvg(overallAvg()!)),
213+ accent: "mint",
214+ },
215+ {
216+ icon: <IconNote class="h-5 w-5" />,
217+ titleKey: "nav.notes",
218+ to: "/notes",
219+ descKey: "dashboard.portal.notesDesc",
220+ stat: () => displayCount(totalNotesCount()),
221+ statSuffix: "dashboard.records",
222+ accent: "rose",
223+ },
224+ );
225+ }
226+
227+ if (roleVal === "teacher") {
228+ list.push(
229+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" },
230+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" },
231+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" },
232+ { icon: <IconChart class="h-5 w-5" />, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: () => "", accent: "mint", minRole: "teacher" },
233+ { icon: <IconClipboardCheck class="h-5 w-5" />, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: () => "", accent: "rose", minRole: "teacher" },
234+ { icon: <IconNote class="h-5 w-5" />, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: () => displayCount(totalNotesCount()), statSuffix: "dashboard.records", accent: "sky" },
235+ { icon: <IconReportAnalytics class="h-5 w-5" />, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: () => "", accent: "amber", minRole: "teacher" },
236+ );
237+ }
238+
239+ if (hasMinRole(roleVal, "manager")) {
240+ list.unshift(
241+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" },
242+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" },
243+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky" },
244+ { icon: <IconSettings class="h-5 w-5" />, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: () => "", accent: "mint", minRole: "manager" },
245+ { icon: <IconBook class="h-5 w-5" />, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: () => "", accent: "rose", minRole: "manager" },
246+ );
247+ if (roleVal === "admin") {
248+ list.push(
249+ { icon: <IconUsers class="h-5 w-5" />, titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: () => "", accent: "rose", minRole: "admin" },
250+ );
251+ }
252+ }
253+
254+ return list;
255+ });
74 256
75 return (257 return (
76 <div class="space-y-5">258 <div class="space-y-5">
77- <PageHeader259+ <PageHeader compact accent="mint" title={t("dashboard.greeting", { name: fullName() })}>
78- compact260+ <div class="flex items-center gap-2">
79- accent="mint"261+ <Badge variant="outline" class="rounded-sm bg-background/60 text-xs font-medium">
80- title={t("dashboard.greeting", { name: user().username })}262+ {t(ROLE_KEY[role()])}
81- description={t("dashboard.subtitle")}263+ </Badge>
82- />264+ <span class="text-xs text-muted-foreground">
265+ {formatDateTime(Date.now(), locale()).split(",")[0]}
266+ </span>
267+ </div>
268+ </PageHeader>
83 269
84 <Show when={resourceError()}>270 <Show when={resourceError()}>
85 {(msg) => <Alert variant="destructive">{msg()}</Alert>}271 {(msg) => <Alert variant="destructive">{msg()}</Alert>}
86 </Show>272 </Show>
87 273
88- {/* KPIs below actions */}
89 <Suspense fallback={<PageSpinner />}>274 <Suspense fallback={<PageSpinner />}>
90- <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">275+ <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
91- <StatTile276+ <For each={cards()}>{(card) => <PortalCard card={card} />}</For>
92- label={t("dashboard.stats.notes")}277+ </div>
93- value={String(noteCount())}278+
94- hint={t("nav.notes")}279+ <div class="grid gap-4 lg:grid-cols-2">
95- tone="mint"280+ <UpcomingTimeline timeline={timeline()} locale={locale()} t={t} />
96- to="/notes"281+ <ActivityChart
97- />282+ label={t("dashboard.activityGraph")}
98- <StatTile283+ items={chartData()}
99- label={t("dashboard.stats.events")}284+ maxValue={maxChartValue()}
100- value={String(eventCount())}
101- hint={t("nav.events")}
102- tone="sky"
103- to="/events"
104- />
105- <StatTile
106- label={t("dashboard.stats.exams")}
107- value={String(examCount())}
108- hint={t("nav.exams")}
109- tone="amber"
110- to="/exams"
111- />
112- <StatTile
113- label={t("dashboard.stats.average")}
114- value={overallAvg() == null ? "—" : roundAvg(overallAvg()!)}
115- hint={t("dashboard.stats.averageHint")}
116- tone="violet"
117- to="/marks"
118- suffix={overallAvg() == null ? undefined : "/100"}
119 />285 />
120- </section>286+ </div>
121 </Suspense>287 </Suspense>
288+ </div>
289+ );
290+}
122 291
123- {/* Summaries */}292+function PortalCard(props: { card: PortalCard }) {
124- <section class="grid items-stretch gap-4 lg:grid-cols-3">293+ const t = useT();
125- <div class="data-shell flex min-h-[18rem] flex-col overflow-hidden">294+ const { icon, titleKey, to, descKey, stat, statSuffix, accent, minRole } = props.card;
126- <div class="flex items-center justify-between gap-2 border-b border-border/70 bg-muted/25 px-4 py-3 sm:px-5">295+ const statValue = stat();
127- <h2 class="font-display text-base font-semibold tracking-tight sm:text-lg">{t("dashboard.recentNotes")}</h2>
128- </div>
129- <div class="flex flex-1 p-4 sm:p-5">
130- <Suspense fallback={<PageSpinner />}>
131- <Show
132- when={previewNotes().length > 0}
133- fallback={
134- <EmptyPanel
135- icon={<IconNote class="h-6 w-6" />}
136- title={t("dashboard.emptyNotesTitle")}
137- description={t("dashboard.noNotes")}
138- tone="amber"
139- />
140- }
141- >
142- <ul class="flex flex-1 flex-col divide-y divide-border/70">
143- <For each={previewNotes()}>
144- {(note: Note) => (
145- <li class="flex min-h-[3.5rem] items-start gap-3 py-3 first:pt-0">
146- <div class="min-w-0 flex-1">
147- <p class="truncate text-sm font-medium">{note.title}</p>
148- <p class="truncate text-xs text-muted-foreground">
149- {note.content || t("notes.noContent")}
150- </p>
151- </div>
152- </li>
153- )}
154- </For>
155- </ul>
156- </Show>
157- </Suspense>
158- </div>
159- </div>
160 296
161- <div class="data-shell flex min-h-[18rem] flex-col overflow-hidden">297+ const iconAccentMap: Record<string, string> = {
162- <div class="flex items-center justify-between gap-2 border-b border-border/70 bg-muted/25 px-4 py-3 sm:px-5">298+ violet: "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",
163- <h2 class="font-display text-base font-semibold tracking-tight sm:text-lg">{t("dashboard.upcomingEvents")}</h2>299+ amber: "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300",
164- </div>300+ sky: "border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",
165- <div class="flex flex-1 p-4 sm:p-5">301+ mint: "border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
166- <Suspense fallback={<PageSpinner />}>302+ rose: "border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-300",
167- <Show303+ };
168- when={previewEvents().length > 0}
169- fallback={
170- <EmptyPanel
171- icon={<IconCalendar class="h-6 w-6" />}
172- title={t("dashboard.emptyEventsTitle")}
173- description={t("dashboard.noEvents")}
174- tone="sky"
175- />
176- }
177- >
178- <ul class="flex flex-1 flex-col gap-2">
179- <For each={previewEvents()}>
180- {(event: Event) => (
181- <li>
182- <Link
183- to="/events/$id"
184- params={{ id: event.id }}
185- class="flex min-h-[3.5rem] items-center justify-between gap-3 rounded-lg border border-border bg-muted/25 px-3 py-2.5 transition-colors hover:border-primary/35 hover:bg-muted/45"
186- >
187- <div class="min-w-0">
188- <p class="truncate text-sm font-medium">{event.title}</p>
189- <p class="text-xs text-muted-foreground">
190- {formatDateTime(event.starts_at, locale())}
191- </p>
192- </div>
193- <span class="text-primary" aria-hidden>
194- →
195- </span>
196- </Link>
197- </li>
198- )}
199- </For>
200- </ul>
201- </Show>
202- </Suspense>
203- </div>
204- </div>
205 304
206- <div class="data-shell flex min-h-[18rem] flex-col overflow-hidden">305+ const dotMap: Record<string, string> = {
207- <div class="flex items-center justify-between gap-2 border-b border-border/70 bg-muted/25 px-4 py-3 sm:px-5">306+ violet: "bg-violet-500",
208- <h2 class="font-display text-base font-semibold tracking-tight sm:text-lg">{t("dashboard.myExams")}</h2>307+ amber: "bg-amber-500",
209- </div>308+ sky: "bg-sky-500",
210- <div class="flex flex-1 p-4 sm:p-5">309+ mint: "bg-emerald-500",
211- <Suspense fallback={<PageSpinner />}>310+ rose: "bg-rose-500",
212- <Show311+ };
213- when={previewExams().length > 0}312+
214- fallback={313+ return (
215- <EmptyPanel314+ <Link
216- icon={<IconExam class="h-6 w-6" />}315+ to={to}
217- title={t("dashboard.emptyExamsTitle")}316+ class={cn(
218- description={t("exams.empty")}317+ "group relative overflow-hidden rounded-xl border border-border/60 bg-card p-5 shadow-xs transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md",
219- tone="rose"318+ )}
220- />319+ >
221- }320+ <div
321+ class={cn(
322+ "pointer-events-none absolute inset-x-0 top-0 h-0.5 transition-colors duration-200",
323+ dotMap[accent],
324+ )}
325+ />
326+ <div class="flex items-start justify-between">
327+ <div
328+ class={cn(
329+ "flex h-10 w-10 items-center justify-center rounded-lg border",
330+ iconAccentMap[accent],
331+ )}
332+ >
333+ {icon}
334+ </div>
335+ <svg
336+ class="h-4 w-4 text-muted-foreground transition-transform duration-200 group-hover:translate-x-0.5"
337+ viewBox="0 0 16 16"
338+ fill="none"
339+ stroke="currentColor"
340+ stroke-width="2"
341+ stroke-linecap="round"
342+ stroke-linejoin="round"
343+ >
344+ <path d="M5 12l4-4-4-4" />
345+ </svg>
346+ </div>
347+ <div class="mt-4 space-y-1">
348+ <div class="flex items-center gap-2">
349+ <h3 class="font-display text-sm font-semibold">{t(titleKey)}</h3>
350+ <Show when={minRole && minRole !== "student"}>
351+ <span
352+ class={cn(
353+ "rounded px-1.5 py-0.5 text-[10px] font-medium uppercase leading-none",
354+ ROLE_BADGE_TONE[minRole!],
355+ )}
222 >356 >
223- <ul class="flex flex-1 flex-col gap-2">357+ {t(ROLE_KEY[minRole!])}
224- <For each={previewExams()}>358+ </span>
225- {(exam: Exam) => (359+ </Show>
226- <li>
227- <ExamLink
228- examId={exam.id}
229- class="flex min-h-[3.5rem] items-center justify-between gap-3 rounded-lg border border-border bg-muted/25 px-3 py-2.5 transition-colors hover:border-primary/35 hover:bg-muted/45"
230- >
231- <div class="min-w-0">
232- <p class="truncate text-sm font-medium">{exam.title}</p>
233- <p class="truncate text-xs text-muted-foreground">
234- {exam.description || "—"}
235- </p>
236- </div>
237- <Badge variant="outline" class="shrink-0 rounded-sm capitalize">
238- {examKindLabel(String(exam.kind), t)}
239- </Badge>
240- </ExamLink>
241- </li>
242- )}
243- </For>
244- </ul>
245- </Show>
246- </Suspense>
247- </div>
248 </div>360 </div>
249- </section>361+ <Show when={statValue !== ""}>
250-362+ <p class="flex items-baseline gap-1 font-display text-2xl font-bold tracking-tight">
251- </div>363+ <span>{statValue}</span>
364+ <Show when={statSuffix}>
365+ {(suffix) => <span class="text-xs font-medium text-muted-foreground">{t(suffix())}</span>}
366+ </Show>
367+ </p>
368+ </Show>
369+ <p class="text-xs leading-relaxed text-muted-foreground">{t(descKey)}</p>
370+ </div>
371+ </Link>
252 );372 );
253 }373 }
254 374
255-function StatTile(props: {375+function UpcomingTimeline(props: {
256- label: string;376+ timeline: TimelineItem[];
257- value: string;377+ locale: Locale;
258- hint: string;378+ t: (key: MessageKey, params?: Record<string, string | number>) => string;
259- tone: "mint" | "sky" | "amber" | "violet";
260- to?: string;
261- suffix?: string;
262 }) {379 }) {
263- const tones = {380+ return (
264- mint: "text-emerald-700 dark:text-emerald-300",381+ <div class="rounded-xl border border-border/60 bg-card p-5 shadow-xs">
265- sky: "text-sky-700 dark:text-sky-300",382+ <div class="mb-4 flex items-center gap-2">
266- amber: "text-amber-700 dark:text-amber-300",383+ <IconCalendar class="h-4 w-4 text-muted-foreground" />
267- violet: "text-violet-700 dark:text-violet-300",384+ <h2 class="font-display text-sm font-semibold">{props.t("dashboard.upcoming")}</h2>
268- };385+ </div>
269-386+ <Show
270- const inner = (387+ when={props.timeline.length > 0}
271- <div class="data-shell h-full min-h-[5.5rem] p-4 transition-colors duration-150 hover:border-primary/35">388+ fallback={
272- <p class="text-[11px] font-semibold uppercase tracking-wider text-muted-foreground">{props.label}</p>389+ <p class="py-6 text-center text-sm text-muted-foreground">{props.t("dashboard.noEvents")}</p>
273- <p class={cn("mono mt-1.5 text-2xl font-semibold tracking-tight tabular-nums sm:text-3xl", tones[props.tone])}>390+ }
274- {props.value}391+ >
275- <Show when={props.suffix}>392+ <div class="space-y-3">
276- <span class="text-sm font-medium text-muted-foreground"> {props.suffix}</span>393+ <For each={props.timeline}>
277- </Show>394+ {(item) => (
278- </p>395+ <Link
279- <p class="mt-1 text-xs text-muted-foreground">{props.hint}</p>396+ to={item.type === "event" ? "/events/$id" : "/exams/$id"}
397+ params={{ id: item.id }}
398+ class="flex items-center gap-3 rounded-lg border border-transparent px-3 py-2 text-sm transition-colors hover:border-border/60 hover:bg-muted/25"
399+ >
400+ <div
401+ class={cn(
402+ "flex h-7 w-7 shrink-0 items-center justify-center rounded-md",
403+ item.type === "exam"
404+ ? "bg-amber-500/10 text-amber-600 dark:text-amber-400"
405+ : "bg-sky-500/10 text-sky-600 dark:text-sky-400",
406+ )}
407+ >
408+ {item.type === "exam"
409+ ? <IconExam class="h-3.5 w-3.5" />
410+ : <IconCalendar class="h-3.5 w-3.5" />}
411+ </div>
412+ <div class="min-w-0 flex-1">
413+ <p class="truncate font-medium">{item.title}</p>
414+ <p class="truncate text-xs text-muted-foreground">{item.subtitle}</p>
415+ </div>
416+ <span class="shrink-0 whitespace-nowrap text-xs tabular-nums text-muted-foreground">
417+ {item.at == null ? props.t("exams.unscheduled") : formatDateTime(item.at, props.locale)}
418+ </span>
419+ </Link>
420+ )}
421+ </For>
422+ </div>
423+ </Show>
280 </div>424 </div>
281 );425 );
282-
283- if (props.to) {
284- return (
285- <Link to={props.to} class="block h-full">
286- {inner}
287- </Link>
288- );
289- }
290- return inner;
291 }426 }
292 427
293-function EmptyPanel(props: {428+function ActivityChart(props: {
294- icon: any;429+ label: string;
295- title: string;430+ items: { label: string; value: number }[];
296- description: string;431+ maxValue: number;
297- tone: "amber" | "sky" | "rose";
298 }) {432 }) {
299- const tones = {
300- amber: "from-amber-500/10 via-transparent to-transparent text-amber-700 dark:text-amber-300",
301- sky: "from-sky-500/10 via-transparent to-transparent text-sky-700 dark:text-sky-300",
302- rose: "from-rose-500/10 via-transparent to-transparent text-rose-700 dark:text-rose-300",
303- };
304-
305 return (433 return (
306- <div434+ <div class="rounded-xl border border-border/60 bg-card p-5 shadow-xs">
307- class={cn(435+ <div class="mb-4 flex items-center gap-2">
308- "flex flex-1 flex-col items-center justify-center rounded-md border border-dashed border-border/80 bg-gradient-to-b px-4 py-8 text-center",436+ <IconChart class="h-4 w-4 text-muted-foreground" />
309- tones[props.tone],437+ <h2 class="font-display text-sm font-semibold">{props.label}</h2>
310- )}438+ </div>
311- >439+ <div class="space-y-3">
312- <div class="mb-3 flex h-12 w-12 items-center justify-center rounded-md border border-border/70 bg-card text-current shadow-sm">440+ <For each={props.items}>
313- {props.icon}441+ {(item, i) => (
442+ <div class="space-y-1">
443+ <div class="flex items-center justify-between text-xs">
444+ <span class="text-muted-foreground">{item.label}</span>
445+ <span class="font-semibold tabular-nums">{item.value}</span>
446+ </div>
447+ <div class="h-2 overflow-hidden rounded-full bg-muted">
448+ <div
449+ class={cn(
450+ "h-full rounded-full transition-all duration-500",
451+ CHART_TONES[i() % CHART_TONES.length],
452+ )}
453+ style={{ width: `${(item.value / props.maxValue) * 100}%` }}
454+ />
455+ </div>
456+ </div>
457+ )}
458+ </For>
314 </div>459 </div>
315- <p class="font-display text-base font-semibold text-foreground">{props.title}</p>
316- <p class="mt-1 max-w-[16rem] text-xs leading-relaxed text-muted-foreground">
317- {props.description}
318- </p>
319 </div>460 </div>
320 );461 );
321 }462 }