diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index c13361e..0fe789c 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -40,7 +40,7 @@ interface PortalCard { titleKey: MessageKey; to: string; descKey: MessageKey; - stat: () => string | number; + stat: string | number; statSuffix?: MessageKey; accent: string; minRole?: Role; @@ -140,7 +140,7 @@ function DashboardContent() { const totalExamsCount = createMemo(() => (exams.loading ? null : visibleExams().length)); const totalEventsCount = createMemo(() => (events.loading ? null : events()?.length ?? 0)); const totalNotesCount = createMemo(() => (notes.loading ? null : notes()?.length ?? 0)); - const displayCount = (count: number | null) => count ?? "..."; + const displayCount = (count: number | null) => String(count ?? 0); const overallAvg = createMemo(() => marks()?.overall_average ?? null); @@ -171,88 +171,54 @@ function DashboardContent() { Math.max(1, ...chartData().map((d) => d.value)), ); - const cards = createMemo(() => { + const cards = () => { const roleVal = role(); + const cc = displayCount(courseCount()); + const ec = displayCount(totalExamsCount()); + const evc = displayCount(totalEventsCount()); + const nc = displayCount(totalNotesCount()); + const avg = overallAvg() == null ? "0" : roundAvg(overallAvg()!); const list: PortalCard[] = []; if (roleVal === "student") { list.push( - { - icon: , - titleKey: "nav.courses", - to: "/courses", - descKey: "dashboard.portal.coursesDesc", - stat: () => displayCount(courseCount()), - statSuffix: "dashboard.records", - accent: "violet", - }, - { - icon: , - titleKey: "nav.exams", - to: "/exams", - descKey: "dashboard.portal.examsDesc", - stat: () => displayCount(totalExamsCount()), - statSuffix: "dashboard.records", - accent: "amber", - }, - { - icon: , - titleKey: "nav.events", - to: "/events", - descKey: "dashboard.portal.eventsDesc", - stat: () => displayCount(totalEventsCount()), - statSuffix: "dashboard.records", - accent: "sky", - }, - { - icon: , - titleKey: "nav.marks", - to: "/marks", - descKey: "dashboard.portal.marksDesc", - stat: () => (overallAvg() == null ? "--" : roundAvg(overallAvg()!)), - accent: "mint", - }, - { - icon: , - titleKey: "nav.notes", - to: "/notes", - descKey: "dashboard.portal.notesDesc", - stat: () => displayCount(totalNotesCount()), - statSuffix: "dashboard.records", - accent: "rose", - }, + { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" }, + { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" }, + { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" }, + { icon: , titleKey: "nav.marks", to: "/marks", descKey: "dashboard.portal.marksDesc", stat: avg, accent: "mint" }, + { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "rose" }, ); } if (roleVal === "teacher") { list.push( - { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" }, - { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" }, - { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" }, - { icon: , titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: () => "", accent: "mint", minRole: "teacher" }, - { icon: , titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: () => "", accent: "rose", minRole: "teacher" }, - { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: () => displayCount(totalNotesCount()), statSuffix: "dashboard.records", accent: "sky" }, - { icon: , titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: () => "", accent: "amber", minRole: "teacher" }, + { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" }, + { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" }, + { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" }, + { icon: , titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: "", accent: "mint", minRole: "teacher" }, + { icon: , titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: "", accent: "rose", minRole: "teacher" }, + { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "sky" }, + { icon: , titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "teacher" }, ); } if (hasMinRole(roleVal, "manager")) { list.unshift( - { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" }, - { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" }, - { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky" }, - { icon: , titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: () => "", accent: "mint", minRole: "manager" }, - { icon: , titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: () => "", accent: "rose", minRole: "manager" }, + { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" }, + { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" }, + { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" }, + { icon: , titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: "", accent: "mint", minRole: "manager" }, + { icon: , titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: "", accent: "rose", minRole: "manager" }, ); if (roleVal === "admin") { list.push( - { icon: , titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: () => "", accent: "rose", minRole: "admin" }, + { icon: , titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: "", accent: "rose", minRole: "admin" }, ); } } return list; - }); + }; return (
@@ -272,11 +238,11 @@ function DashboardContent() { }> -
+
{(card) => }
-
+
= { violet: "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300", @@ -314,7 +279,7 @@ function PortalCard(props: { card: PortalCard }) {
-
+

{t(titleKey)}

@@ -358,15 +323,13 @@ function PortalCard(props: { card: PortalCard }) {
- -

- {statValue} - - {(suffix) => {t(suffix())}} - -

-
-

{t(descKey)}

+
+ {statValue || "—"} + + {(suffix) => {t(suffix())}} + +
+

{t(descKey)}

); @@ -378,7 +341,7 @@ function UpcomingTimeline(props: { t: (key: MessageKey, params?: Record) => string; }) { return ( -
+

{props.t("dashboard.upcoming")}

@@ -431,7 +394,7 @@ function ActivityChart(props: { maxValue: number; }) { return ( -
+

{props.label}