π keep charts truthful
Browse files at this commite0964664ce9a690a5c3f8b4ea95a355892fde297Parent: e7c5b53- fix
- π keep charts truthful
7 changed files +236 -372
- .claude/skills/dashboard-design/SKILL.md +11 -6
- .codex/skills/dashboard-design/SKILL.md +11 -6
- src/components/ui/chart-area-trend.tsx +0 -204
- src/components/ui/chart-bar.tsx +3 -8
- src/components/ui/chart-progress-ring.tsx +3 -9
- src/pages/dashboard-page.test.tsx +149 -0
- src/pages/dashboard-page.tsx +59 -139
.claude/skills/dashboard-design/SKILL.mdmodified+11 -6
| @@ -10,20 +10,25 @@ Reference: `src/pages/dashboard-page.tsx`. The homepage is a **read-only status | |||
| 10 | - **No mutations:** no create/edit/delete buttons, no primary CTAs that open forms. Links only navigate to existing list/detail routes. | 10 | - **No mutations:** no create/edit/delete buttons, no primary CTAs that open forms. Links only navigate to existing list/detail routes. |
| 11 | - **Charts are allowed, on real data only.** The homepage follows the Knowvio-style | 11 | - **Charts are allowed, on real data only.** The homepage follows the Knowvio-style |
| 12 | layout: a Highlights stat-card row, a Progress-overview chart, an Activity/attendance | 12 | layout: a Highlights stat-card row, a Progress-overview chart, an Activity/attendance |
| 13 | - split, and an Upcoming-deadlines table. Charts use the `Chart*` components in | 13 | + split, and an Upcoming-deadlines table. Charts use `ChartBar` and |
| 14 | - `src/components/ui/` (accent = `hsl(var(--primary))`, semantic tints for status). | 14 | + `ChartProgressRing` from `src/components/ui/` (accent = |
| 15 | + `hsl(var(--primary))`, semantic tints for status). | ||
| 15 | **Every chart/stat must be backed by a live API field** β no fabricated trends, | 16 | **Every chart/stat must be backed by a live API field** β no fabricated trends, |
| 16 | - streak counters, or `+%` delta badges the backend can't produce. Hide a panel when | 17 | + streak counters, sparklines, or `+%` delta badges the backend can't produce. |
| 17 | - its data source is empty for the current role rather than faking it. | 18 | + Categorical series use bars, with a plain empty state when no records exist. |
| 18 | - **Layout order (top β bottom):** | 19 | - **Layout order (top β bottom):** |
| 19 | 1. Compact header β greeting, role chip (neutral), date. | 20 | 1. Compact header β greeting, role chip (neutral), date. |
| 20 | 2. **Highlights** β role-scoped stat cards (icon + label + mono value). | 21 | 2. **Highlights** β role-scoped stat cards (icon + label + mono value). |
| 21 | 3. **Progress overview** chart + **Activity split** on `lg+`. | 22 | 3. **Progress overview** chart + **Activity split** on `lg+`. |
| 22 | 4. **Upcoming deadlines** `DataTable` (exams / events / homework / appointments). | 23 | 4. **Upcoming deadlines** `DataTable` (exams / events / homework / appointments). |
| 23 | - 5. Optional role-scoped workspace links / recent list. | 24 | + 5. Optional teacher+ Question Bank / Question Pool links. |
| 24 | - **Grid:** stat row `1 β 2 sm β 4 lg`; charts `lg:grid-cols-3` (progress spans 2). | 25 | - **Grid:** stat row `1 β 2 sm β 4 lg`; charts `lg:grid-cols-3` (progress spans 2). |
| 25 | - **Role scoping:** stat/chart set matches nav/role matrix (student personal tools + | 26 | - **Role scoping:** stat/chart set matches nav/role matrix (student personal tools + |
| 26 | marks/attendance; teacher teaching tools; manager+ management; parent children/meals). | 27 | marks/attendance; teacher teaching tools; manager+ management; parent children/meals). |
| 27 | Show only panels whose data exists for the role. | 28 | Show only panels whose data exists for the role. |
| 28 | - **Deadlines table:** active / today / soon items only, semantic status badge, rows | 29 | - **Deadlines table:** active / today / soon items only, semantic status badge, rows |
| 29 | - navigate to detail. Empty state is plain text, not a create CTA. | 30 | + navigate by pointer, Enter, or Space. Empty state is plain text, not a create CTA. |
| 31 | +- **Semantics:** student progress = per-course averages; staff progress = | ||
| 32 | + `Course.capacity` labeled as course capacity, never enrollment/class size. | ||
| 33 | +- **Role privacy:** question navigation is teacher+ only. Student/parent deadlines | ||
| 34 | + span full width. No inferred priority or manual refresh. | ||
.codex/skills/dashboard-design/SKILL.mdmodified+11 -6
| @@ -10,20 +10,25 @@ Reference: `src/pages/dashboard-page.tsx`. The homepage is a **read-only status | |||
| 10 | - **No mutations:** no create/edit/delete buttons, no primary CTAs that open forms. Links only navigate to existing list/detail routes. | 10 | - **No mutations:** no create/edit/delete buttons, no primary CTAs that open forms. Links only navigate to existing list/detail routes. |
| 11 | - **Charts are allowed, on real data only.** The homepage follows the Knowvio-style | 11 | - **Charts are allowed, on real data only.** The homepage follows the Knowvio-style |
| 12 | layout: a Highlights stat-card row, a Progress-overview chart, an Activity/attendance | 12 | layout: a Highlights stat-card row, a Progress-overview chart, an Activity/attendance |
| 13 | - split, and an Upcoming-deadlines table. Charts use the `Chart*` components in | 13 | + split, and an Upcoming-deadlines table. Charts use `ChartBar` and |
| 14 | - `src/components/ui/` (accent = `hsl(var(--primary))`, semantic tints for status). | 14 | + `ChartProgressRing` from `src/components/ui/` (accent = |
| 15 | + `hsl(var(--primary))`, semantic tints for status). | ||
| 15 | **Every chart/stat must be backed by a live API field** β no fabricated trends, | 16 | **Every chart/stat must be backed by a live API field** β no fabricated trends, |
| 16 | - streak counters, or `+%` delta badges the backend can't produce. Hide a panel when | 17 | + streak counters, sparklines, or `+%` delta badges the backend can't produce. |
| 17 | - its data source is empty for the current role rather than faking it. | 18 | + Categorical series use bars, with a plain empty state when no records exist. |
| 18 | - **Layout order (top β bottom):** | 19 | - **Layout order (top β bottom):** |
| 19 | 1. Compact header β greeting, role chip (neutral), date. | 20 | 1. Compact header β greeting, role chip (neutral), date. |
| 20 | 2. **Highlights** β role-scoped stat cards (icon + label + mono value). | 21 | 2. **Highlights** β role-scoped stat cards (icon + label + mono value). |
| 21 | 3. **Progress overview** chart + **Activity split** on `lg+`. | 22 | 3. **Progress overview** chart + **Activity split** on `lg+`. |
| 22 | 4. **Upcoming deadlines** `DataTable` (exams / events / homework / appointments). | 23 | 4. **Upcoming deadlines** `DataTable` (exams / events / homework / appointments). |
| 23 | - 5. Optional role-scoped workspace links / recent list. | 24 | + 5. Optional teacher+ Question Bank / Question Pool links. |
| 24 | - **Grid:** stat row `1 β 2 sm β 4 lg`; charts `lg:grid-cols-3` (progress spans 2). | 25 | - **Grid:** stat row `1 β 2 sm β 4 lg`; charts `lg:grid-cols-3` (progress spans 2). |
| 25 | - **Role scoping:** stat/chart set matches nav/role matrix (student personal tools + | 26 | - **Role scoping:** stat/chart set matches nav/role matrix (student personal tools + |
| 26 | marks/attendance; teacher teaching tools; manager+ management; parent children/meals). | 27 | marks/attendance; teacher teaching tools; manager+ management; parent children/meals). |
| 27 | Show only panels whose data exists for the role. | 28 | Show only panels whose data exists for the role. |
| 28 | - **Deadlines table:** active / today / soon items only, semantic status badge, rows | 29 | - **Deadlines table:** active / today / soon items only, semantic status badge, rows |
| 29 | - navigate to detail. Empty state is plain text, not a create CTA. | 30 | + navigate by pointer, Enter, or Space. Empty state is plain text, not a create CTA. |
| 31 | +- **Semantics:** student progress = per-course averages; staff progress = | ||
| 32 | + `Course.capacity` labeled as course capacity, never enrollment/class size. | ||
| 33 | +- **Role privacy:** question navigation is teacher+ only. Student/parent deadlines | ||
| 34 | + span full width. No inferred priority or manual refresh. | ||
src/components/ui/chart-area-trend.tsxdeleted+0 -204
| @@ -1,204 +0,0 @@ | |||
| 1 | -import { For, Show, createSignal, type Component } from "solid-js"; | ||
| 2 | -import { cn } from "@/lib/cn"; | ||
| 3 | -import { useT } from "@/stores/preferences-context"; | ||
| 4 | - | ||
| 5 | -export type ChartAreaTrendItem = { | ||
| 6 | - label: string; | ||
| 7 | - value: number; | ||
| 8 | - formattedValue?: string; | ||
| 9 | -}; | ||
| 10 | - | ||
| 11 | -export type ChartAreaTrendProps = { | ||
| 12 | - title: string; | ||
| 13 | - subtitle?: string; | ||
| 14 | - items: ChartAreaTrendItem[]; | ||
| 15 | - class?: string; | ||
| 16 | - minScale?: number; | ||
| 17 | - maxScale?: number; | ||
| 18 | - unit?: string; | ||
| 19 | -}; | ||
| 20 | - | ||
| 21 | -export const ChartAreaTrend: Component<ChartAreaTrendProps> = (props) => { | ||
| 22 | - const [hoverIndex, setHoverIndex] = createSignal<number | null>(null); | ||
| 23 | - const t = useT(); | ||
| 24 | - | ||
| 25 | - const values = () => props.items.map((i) => i.value); | ||
| 26 | - const minVal = () => props.minScale ?? Math.min(0, ...values()); | ||
| 27 | - const maxVal = () => props.maxScale ?? Math.max(1, ...values()); | ||
| 28 | - | ||
| 29 | - const width = 360; | ||
| 30 | - const height = 120; | ||
| 31 | - const paddingX = 20; | ||
| 32 | - const paddingTop = 15; | ||
| 33 | - const paddingBottom = 25; | ||
| 34 | - | ||
| 35 | - const points = () => { | ||
| 36 | - const list = props.items; | ||
| 37 | - if (list.length === 0) return []; | ||
| 38 | - const min = minVal(); | ||
| 39 | - const max = maxVal(); | ||
| 40 | - const range = max - min || 1; | ||
| 41 | - const stepX = (width - paddingX * 2) / Math.max(1, list.length - 1); | ||
| 42 | - const usableH = height - paddingTop - paddingBottom; | ||
| 43 | - | ||
| 44 | - return list.map((item, i) => { | ||
| 45 | - const x = paddingX + i * stepX; | ||
| 46 | - const normalized = (item.value - min) / range; | ||
| 47 | - const y = height - paddingBottom - normalized * usableH; | ||
| 48 | - return { x, y, item, index: i }; | ||
| 49 | - }); | ||
| 50 | - }; | ||
| 51 | - | ||
| 52 | - const linePath = () => { | ||
| 53 | - const pts = points(); | ||
| 54 | - if (pts.length === 0) return ""; | ||
| 55 | - return pts.reduce((acc, p, idx) => (idx === 0 ? `M ${p.x} ${p.y}` : `${acc} L ${p.x} ${p.y}`), ""); | ||
| 56 | - }; | ||
| 57 | - | ||
| 58 | - const areaPath = () => { | ||
| 59 | - const pts = points(); | ||
| 60 | - if (pts.length === 0) return ""; | ||
| 61 | - const first = pts[0]; | ||
| 62 | - const last = pts[pts.length - 1]; | ||
| 63 | - const bottomY = height - paddingBottom; | ||
| 64 | - return `${linePath()} L ${last.x} ${bottomY} L ${first.x} ${bottomY} Z`; | ||
| 65 | - }; | ||
| 66 | - | ||
| 67 | - return ( | ||
| 68 | - <div class={cn("flex flex-col space-y-3 rounded-2xl border border-border/60 bg-card p-4 shadow-xs dark:border-white/8", props.class)}> | ||
| 69 | - <div class="flex items-start justify-between gap-2"> | ||
| 70 | - <div class="space-y-0.5 min-w-0"> | ||
| 71 | - <h3 class="truncate text-sm font-semibold tracking-tight text-foreground">{props.title}</h3> | ||
| 72 | - <Show when={props.subtitle}> | ||
| 73 | - <p class="truncate text-xs text-muted-foreground">{props.subtitle}</p> | ||
| 74 | - </Show> | ||
| 75 | - </div> | ||
| 76 | - <Show when={props.items.length > 0}> | ||
| 77 | - <div class="mono tabular-nums text-xs font-semibold text-primary bg-primary/10 px-2 py-0.5 rounded-full border border-primary/20"> | ||
| 78 | - {hoverIndex() !== null | ||
| 79 | - ? (props.items[hoverIndex()!]?.formattedValue ?? `${props.items[hoverIndex()!]?.value}${props.unit ?? ""}`) | ||
| 80 | - : (props.items[props.items.length - 1]?.formattedValue ?? `${props.items[props.items.length - 1]?.value}${props.unit ?? ""}`)} | ||
| 81 | - </div> | ||
| 82 | - </Show> | ||
| 83 | - </div> | ||
| 84 | - | ||
| 85 | - <Show | ||
| 86 | - when={props.items.length > 0} | ||
| 87 | - fallback={ | ||
| 88 | - <div class="flex flex-col items-center justify-center py-8 px-4 text-center"> | ||
| 89 | - <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-muted/40 border border-border/50 text-muted-foreground/60 mb-2"> | ||
| 90 | - <svg class="h-5 w-5 stroke-[1.5]" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | ||
| 91 | - <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" /> | ||
| 92 | - </svg> | ||
| 93 | - </div> | ||
| 94 | - <p class="text-xs font-semibold text-foreground/80">{t("dashboard.chartEmpty")}</p> | ||
| 95 | - <p class="text-[11px] text-muted-foreground mt-0.5">{t("dashboard.chartEmptyHint")}</p> | ||
| 96 | - </div> | ||
| 97 | - } | ||
| 98 | - > | ||
| 99 | - <div class="relative w-full overflow-hidden"> | ||
| 100 | - <svg viewBox={`0 0 ${width} ${height}`} class="w-full h-32 overflow-visible"> | ||
| 101 | - <defs> | ||
| 102 | - <linearGradient id="areaGradient" x1="0" y1="0" x2="0" y2="1"> | ||
| 103 | - <stop offset="0%" stop-color="hsl(var(--primary))" stop-opacity="0.35" /> | ||
| 104 | - <stop offset="100%" stop-color="hsl(var(--primary))" stop-opacity="0.0" /> | ||
| 105 | - </linearGradient> | ||
| 106 | - </defs> | ||
| 107 | - | ||
| 108 | - {/* Horizontal Grid lines */} | ||
| 109 | - <line x1={paddingX} y1={paddingTop} x2={width - paddingX} y2={paddingTop} stroke="currentColor" stroke-opacity="0.08" stroke-dasharray="3 3" /> | ||
| 110 | - <line x1={paddingX} y1={(paddingTop + height - paddingBottom) / 2} x2={width - paddingX} y2={(paddingTop + height - paddingBottom) / 2} stroke="currentColor" stroke-opacity="0.08" stroke-dasharray="3 3" /> | ||
| 111 | - <line x1={paddingX} y1={height - paddingBottom} x2={width - paddingX} y2={height - paddingBottom} stroke="currentColor" stroke-opacity="0.12" /> | ||
| 112 | - | ||
| 113 | - {/* Hover Vertical Guideline */} | ||
| 114 | - <Show when={hoverIndex() !== null && points()[hoverIndex()!]}> | ||
| 115 | - {(p) => ( | ||
| 116 | - <line | ||
| 117 | - x1={p().x} | ||
| 118 | - y1={paddingTop} | ||
| 119 | - x2={p().x} | ||
| 120 | - y2={height - paddingBottom} | ||
| 121 | - stroke="hsl(var(--primary))" | ||
| 122 | - stroke-opacity="0.3" | ||
| 123 | - stroke-dasharray="3 3" | ||
| 124 | - stroke-width="1.5" | ||
| 125 | - /> | ||
| 126 | - )} | ||
| 127 | - </Show> | ||
| 128 | - | ||
| 129 | - {/* Filled Area */} | ||
| 130 | - <path d={areaPath()} fill="url(#areaGradient)" /> | ||
| 131 | - | ||
| 132 | - {/* Trend Line */} | ||
| 133 | - <path d={linePath()} fill="none" stroke="hsl(var(--primary))" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round" /> | ||
| 134 | - | ||
| 135 | - {/* Data Points */} | ||
| 136 | - <For each={points()}> | ||
| 137 | - {(p) => ( | ||
| 138 | - <g class="cursor-pointer group" onMouseEnter={() => setHoverIndex(p.index)} onMouseLeave={() => setHoverIndex(null)}> | ||
| 139 | - <circle | ||
| 140 | - cx={p.x} | ||
| 141 | - cy={p.y} | ||
| 142 | - r={hoverIndex() === p.index ? "5.5" : "3.5"} | ||
| 143 | - class={cn( | ||
| 144 | - "transition-all duration-200 fill-background stroke-primary stroke-[2.5]", | ||
| 145 | - hoverIndex() === p.index && "fill-primary stroke-background shadow-lg stroke-3", | ||
| 146 | - )} | ||
| 147 | - /> | ||
| 148 | - <text | ||
| 149 | - x={p.x} | ||
| 150 | - y={height - 8} | ||
| 151 | - text-anchor="middle" | ||
| 152 | - class={cn( | ||
| 153 | - "text-[10px] transition-colors font-medium", | ||
| 154 | - hoverIndex() === p.index ? "fill-primary font-bold" : "fill-muted-foreground" | ||
| 155 | - )} | ||
| 156 | - > | ||
| 157 | - {p.item.label} | ||
| 158 | - </text> | ||
| 159 | - </g> | ||
| 160 | - )} | ||
| 161 | - </For> | ||
| 162 | - | ||
| 163 | - {/* Floating Active Hover Tooltip */} | ||
| 164 | - <Show when={hoverIndex() !== null && points()[hoverIndex()!]}> | ||
| 165 | - {(p) => { | ||
| 166 | - const text = p().item.formattedValue ?? `${p().item.value}${props.unit ?? ""}`; | ||
| 167 | - const rectW = 64; | ||
| 168 | - const rectH = 20; | ||
| 169 | - const tooltipX = Math.max(paddingX, Math.min(width - paddingX - rectW, p().x - rectW / 2)); | ||
| 170 | - const tooltipY = Math.max(2, p().y - 26); | ||
| 171 | - return ( | ||
| 172 | - <g class="pointer-events-none transition-all duration-150"> | ||
| 173 | - <circle | ||
| 174 | - cx={p().x} | ||
| 175 | - cy={p().y} | ||
| 176 | - r="8.5" | ||
| 177 | - class="fill-primary/20 stroke-primary/40 stroke-1" | ||
| 178 | - /> | ||
| 179 | - <rect | ||
| 180 | - x={tooltipX} | ||
| 181 | - y={tooltipY} | ||
| 182 | - width={rectW} | ||
| 183 | - height={rectH} | ||
| 184 | - rx="5" | ||
| 185 | - class="fill-card stroke-primary/40 stroke shadow-md dark:fill-zinc-900" | ||
| 186 | - /> | ||
| 187 | - <text | ||
| 188 | - x={tooltipX + rectW / 2} | ||
| 189 | - y={tooltipY + 13.5} | ||
| 190 | - text-anchor="middle" | ||
| 191 | - class="fill-foreground font-semibold text-[10px] mono tabular-nums" | ||
| 192 | - > | ||
| 193 | - {text} | ||
| 194 | - </text> | ||
| 195 | - </g> | ||
| 196 | - ); | ||
| 197 | - }} | ||
| 198 | - </Show> | ||
| 199 | - </svg> | ||
| 200 | - </div> | ||
| 201 | - </Show> | ||
| 202 | - </div> | ||
| 203 | - ); | ||
| 204 | -}; | ||
src/components/ui/chart-bar.tsxmodified+3 -8
| @@ -30,9 +30,9 @@ export const ChartBar: Component<ChartBarProps> = (props) => { | |||
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | return ( | 32 | return ( |
| 33 | - <div class={cn("flex flex-col gap-3.5 rounded-3xl border border-border/60 bg-card/60 p-4 sm:p-5 dark:border-white/8 dark:bg-card/40 shadow-xs backdrop-blur-xs", props.class)}> | 33 | + <div class={cn("flex flex-col gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs", props.class)}> |
| 34 | <Show when={props.title}> | 34 | <Show when={props.title}> |
| 35 | - <div class="flex items-center justify-between gap-2 border-b border-border/40 pb-3"> | 35 | + <div class="border-b border-border pb-3"> |
| 36 | <div> | 36 | <div> |
| 37 | <h3 class="text-sm font-semibold tracking-tight text-foreground">{props.title}</h3> | 37 | <h3 class="text-sm font-semibold tracking-tight text-foreground">{props.title}</h3> |
| 38 | <Show when={props.subtitle}> | 38 | <Show when={props.subtitle}> |
| @@ -45,12 +45,7 @@ export const ChartBar: Component<ChartBarProps> = (props) => { | |||
| 45 | <Show | 45 | <Show |
| 46 | when={props.items.length > 0} | 46 | when={props.items.length > 0} |
| 47 | fallback={ | 47 | fallback={ |
| 48 | - <div class="flex flex-col items-center justify-center py-8 px-4 text-center"> | 48 | + <div class="px-4 py-8 text-center"> |
| 49 | - <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-muted/40 border border-border/50 text-muted-foreground/60 mb-2"> | ||
| 50 | - <svg class="h-5 w-5 stroke-[1.5]" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | ||
| 51 | - <path stroke-linecap="round" stroke-linejoin="round" d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 013 19.875v-6.75zM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V8.625zM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 01-1.125-1.125V4.125z" /> | ||
| 52 | - </svg> | ||
| 53 | - </div> | ||
| 54 | <p class="text-xs font-semibold text-foreground/80">{t("dashboard.chartEmpty")}</p> | 49 | <p class="text-xs font-semibold text-foreground/80">{t("dashboard.chartEmpty")}</p> |
| 55 | <p class="text-[11px] text-muted-foreground mt-0.5">{t("dashboard.chartEmptyHint")}</p> | 50 | <p class="text-[11px] text-muted-foreground mt-0.5">{t("dashboard.chartEmptyHint")}</p> |
| 56 | </div> | 51 | </div> |
src/components/ui/chart-progress-ring.tsxmodified+3 -9
| @@ -24,9 +24,9 @@ export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => { | |||
| 24 | const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0); | 24 | const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0); |
| 25 | 25 | ||
| 26 | return ( | 26 | return ( |
| 27 | - <div class={cn("flex flex-col gap-3.5 rounded-3xl border border-border/60 bg-card/60 p-4 sm:p-5 dark:border-white/8 dark:bg-card/40 shadow-xs backdrop-blur-xs", props.class)}> | 27 | + <div class={cn("flex flex-col gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs", props.class)}> |
| 28 | <Show when={props.title}> | 28 | <Show when={props.title}> |
| 29 | - <div class="flex items-center justify-between gap-2 border-b border-border/40 pb-3"> | 29 | + <div class="border-b border-border pb-3"> |
| 30 | <div> | 30 | <div> |
| 31 | <h3 class="text-sm font-semibold tracking-tight text-foreground">{props.title}</h3> | 31 | <h3 class="text-sm font-semibold tracking-tight text-foreground">{props.title}</h3> |
| 32 | <Show when={props.subtitle}> | 32 | <Show when={props.subtitle}> |
| @@ -39,13 +39,7 @@ export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => { | |||
| 39 | <Show | 39 | <Show |
| 40 | when={calculatedTotal() > 0} | 40 | when={calculatedTotal() > 0} |
| 41 | fallback={ | 41 | fallback={ |
| 42 | - <div class="flex flex-col items-center justify-center py-8 px-4 text-center"> | 42 | + <div class="px-4 py-8 text-center"> |
| 43 | - <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-muted/40 border border-border/50 text-muted-foreground/60 mb-2"> | ||
| 44 | - <svg class="h-5 w-5 stroke-[1.5]" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | ||
| 45 | - <path stroke-linecap="round" stroke-linejoin="round" d="M10.5 6a7.5 7.5 0 107.5 7.5h-7.5V6z" /> | ||
| 46 | - <path stroke-linecap="round" stroke-linejoin="round" d="M13.5 10.5H21A7.5 7.5 0 0013.5 3v7.5z" /> | ||
| 47 | - </svg> | ||
| 48 | - </div> | ||
| 49 | <p class="text-xs font-semibold text-foreground/80">{t("dashboard.chartEmpty")}</p> | 43 | <p class="text-xs font-semibold text-foreground/80">{t("dashboard.chartEmpty")}</p> |
| 50 | <p class="text-[11px] text-muted-foreground mt-0.5">{t("dashboard.chartEmptyHint")}</p> | 44 | <p class="text-[11px] text-muted-foreground mt-0.5">{t("dashboard.chartEmptyHint")}</p> |
| 51 | </div> | 45 | </div> |
src/pages/dashboard-page.test.tsxadded+149 -0
| @@ -0,0 +1,149 @@ | |||
| 1 | +import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; | ||
| 2 | +import type { JSX } from "solid-js"; | ||
| 3 | +import DashboardPage from "@/pages/dashboard-page"; | ||
| 4 | +import { PreferencesProvider } from "@/stores/preferences-context"; | ||
| 5 | + | ||
| 6 | +const { navigate, authUser } = vi.hoisted(() => ({ | ||
| 7 | + navigate: vi.fn(), | ||
| 8 | + authUser: { role: "student" }, | ||
| 9 | +})); | ||
| 10 | + | ||
| 11 | +vi.mock("@tanstack/solid-router", () => ({ | ||
| 12 | + Link: (props: { to: string; children: JSX.Element; class?: string }) => ( | ||
| 13 | + <a href={props.to} class={props.class}>{props.children}</a> | ||
| 14 | + ), | ||
| 15 | + Navigate: () => null, | ||
| 16 | + useNavigate: () => navigate, | ||
| 17 | +})); | ||
| 18 | +vi.mock("@/stores/auth-context", () => ({ | ||
| 19 | + useAuth: () => ({ | ||
| 20 | + user: () => ({ | ||
| 21 | + id: "u-1", | ||
| 22 | + username: "demo", | ||
| 23 | + role: authUser.role, | ||
| 24 | + name: "Demo", | ||
| 25 | + surname: "User", | ||
| 26 | + }), | ||
| 27 | + loading: () => false, | ||
| 28 | + error: () => undefined, | ||
| 29 | + refresh: async () => undefined, | ||
| 30 | + }), | ||
| 31 | +})); | ||
| 32 | + | ||
| 33 | +const now = Date.UTC(2026, 6, 28, 9); | ||
| 34 | +const page = <T,>(items: T[]) => ({ items, total: items.length, limit: 50, offset: 0 }); | ||
| 35 | +const course = { id: "course-1", title: "Algebra", capacity: 24 }; | ||
| 36 | + | ||
| 37 | +vi.mock("@/api/time/getTime", () => ({ getTime: async () => ({ now }) })); | ||
| 38 | +vi.mock("@/api/courses", () => ({ getCourses: async () => page([course]) })); | ||
| 39 | +vi.mock("@/api/reports", () => ({ | ||
| 40 | + getMyCourses: async () => page([course]), | ||
| 41 | + getMyMarks: async () => ({ | ||
| 42 | + overall_average: 82.5, | ||
| 43 | + courses: [{ course, results: [], average: 82.5 }], | ||
| 44 | + }), | ||
| 45 | + getMyAttendance: async () => ({ | ||
| 46 | + events: { total: 3, present: 2, absent: 1, late: 0, excused: 0 }, | ||
| 47 | + sessions: { total: 2, present: 1, absent: 0, late: 1, excused: 0 }, | ||
| 48 | + }), | ||
| 49 | +})); | ||
| 50 | +vi.mock("@/api/exams", () => ({ | ||
| 51 | + getExams: async () => page([{ | ||
| 52 | + id: "exam-1", | ||
| 53 | + title: "Exam deadline", | ||
| 54 | + starts_at: now + 1_000, | ||
| 55 | + ends_at: now + 3_000, | ||
| 56 | + }]), | ||
| 57 | +})); | ||
| 58 | +vi.mock("@/api/events", () => ({ | ||
| 59 | + getEvents: async () => page([{ | ||
| 60 | + id: "event-1", | ||
| 61 | + title: "Event deadline", | ||
| 62 | + starts_at: now + 2_000, | ||
| 63 | + ends_at: now + 4_000, | ||
| 64 | + }]), | ||
| 65 | +})); | ||
| 66 | +vi.mock("@/api/homework", () => ({ | ||
| 67 | + getHomework: async () => page([{ | ||
| 68 | + id: "homework-1", | ||
| 69 | + title: "Homework deadline", | ||
| 70 | + due_at: now + 5_000, | ||
| 71 | + }]), | ||
| 72 | +})); | ||
| 73 | +vi.mock("@/api/appointments", () => ({ | ||
| 74 | + getAppointments: async () => page([{ | ||
| 75 | + id: "appointment-1", | ||
| 76 | + status: "approved", | ||
| 77 | + starts_at: now + 6_000, | ||
| 78 | + ends_at: now + 7_000, | ||
| 79 | + teacher: { username: "teacher", display_name: "Teacher Name" }, | ||
| 80 | + }]), | ||
| 81 | +})); | ||
| 82 | +vi.mock("@/api/parents", () => ({ | ||
| 83 | + getMyStudents: async () => page([{ id: "child-1" }]), | ||
| 84 | +})); | ||
| 85 | +vi.mock("@/api/meals", () => ({ | ||
| 86 | + getMealMenus: async () => page([{ id: "menu-1" }]), | ||
| 87 | +})); | ||
| 88 | + | ||
| 89 | +afterEach(() => { | ||
| 90 | + cleanup(); | ||
| 91 | + navigate.mockReset(); | ||
| 92 | +}); | ||
| 93 | + | ||
| 94 | +function renderDashboard(role: string) { | ||
| 95 | + authUser.role = role; | ||
| 96 | + return render(() => ( | ||
| 97 | + <PreferencesProvider> | ||
| 98 | + <DashboardPage /> | ||
| 99 | + </PreferencesProvider> | ||
| 100 | + )); | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +test("student sees truthful charts, full-width deadlines, and no teaching resources", async () => { | ||
| 104 | + const view = renderDashboard("student"); | ||
| 105 | + | ||
| 106 | + expect(await screen.findByText("Course averages")).toBeTruthy(); | ||
| 107 | + expect(screen.getByText("Attendance split")).toBeTruthy(); | ||
| 108 | + expect(screen.queryByText("Teaching resources")).toBeNull(); | ||
| 109 | + expect(screen.getByRole("link", { name: "Appointments" })).toBeTruthy(); | ||
| 110 | + expect(screen.getByRole("heading", { name: "Upcoming deadlines" }).closest("section")?.className).toContain("lg:col-span-3"); | ||
| 111 | + expect(view.container.querySelector("polyline")).toBeNull(); | ||
| 112 | + expect(screen.queryByText("Priority")).toBeNull(); | ||
| 113 | + expect(screen.queryByText("Refresh data")).toBeNull(); | ||
| 114 | + expect(screen.queryByText("Ask a question")).toBeNull(); | ||
| 115 | + | ||
| 116 | + fireEvent.click(await screen.findByRole("button", { name: /Event deadline/ })); | ||
| 117 | + fireEvent.keyDown(screen.getByRole("button", { name: /Homework deadline/ }), { key: "Enter" }); | ||
| 118 | + fireEvent.keyDown(screen.getByRole("button", { name: /Exam deadline/ }), { key: " " }); | ||
| 119 | + fireEvent.click(screen.getByRole("button", { name: /Teacher Name/ })); | ||
| 120 | + | ||
| 121 | + expect(navigate).toHaveBeenCalledWith({ to: "/events/$id", params: { id: "event-1" } }); | ||
| 122 | + expect(navigate).toHaveBeenCalledWith({ to: "/homework/$id", params: { id: "homework-1" } }); | ||
| 123 | + expect(navigate).toHaveBeenCalledWith({ to: "/exams/$id", params: { id: "exam-1" } }); | ||
| 124 | + expect(navigate).toHaveBeenCalledWith({ to: "/appointments" }); | ||
| 125 | +}); | ||
| 126 | + | ||
| 127 | +test("teacher sees capacities and useful teaching-resource links", async () => { | ||
| 128 | + renderDashboard("teacher"); | ||
| 129 | + | ||
| 130 | + expect(await screen.findByText("Course capacities")).toBeTruthy(); | ||
| 131 | + expect(screen.queryByText("Class sizes")).toBeNull(); | ||
| 132 | + expect(screen.getByText("Workload split")).toBeTruthy(); | ||
| 133 | + expect(screen.getByText("Teaching resources")).toBeTruthy(); | ||
| 134 | + expect(screen.getByRole("link", { name: /Build and reuse question templates/ })).toBeTruthy(); | ||
| 135 | + expect(screen.getByRole("link", { name: /Review questions submitted by students/ })).toBeTruthy(); | ||
| 136 | + expect(screen.getByRole("heading", { name: "Upcoming deadlines" }).closest("section")?.className).toContain("lg:col-span-2"); | ||
| 137 | +}); | ||
| 138 | + | ||
| 139 | +test("parent sees family highlights and appointment deadlines without staff charts", async () => { | ||
| 140 | + renderDashboard("parent"); | ||
| 141 | + | ||
| 142 | + expect(await screen.findByText("Children")).toBeTruthy(); | ||
| 143 | + expect(screen.getAllByText("Appointments").length).toBeGreaterThan(0); | ||
| 144 | + expect(screen.getByText("Meal menus")).toBeTruthy(); | ||
| 145 | + expect(screen.queryByText("Progress overview")).toBeNull(); | ||
| 146 | + expect(screen.queryByText("Teaching resources")).toBeNull(); | ||
| 147 | + expect(await screen.findByRole("button", { name: /Teacher Name/ })).toBeTruthy(); | ||
| 148 | + expect(screen.getByRole("heading", { name: "Upcoming deadlines" }).closest("section")?.className).toContain("lg:col-span-3"); | ||
| 149 | +}); | ||
src/pages/dashboard-page.tsxmodified+59 -139
| @@ -1,5 +1,5 @@ | |||
| 1 | -import { For, Show, Suspense, createMemo, createResource, createSignal, type Component } from "solid-js"; | 1 | +import { For, Show, Suspense, createMemo, createResource, type Component } from "solid-js"; |
| 2 | -import { Link } from "@tanstack/solid-router"; | 2 | +import { Link, useNavigate } from "@tanstack/solid-router"; |
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | import type { Role } from "@/api/client"; | 4 | import type { Role } from "@/api/client"; |
| 5 | import { formatApiError } from "@/api/client"; | 5 | import { formatApiError } from "@/api/client"; |
| @@ -14,21 +14,16 @@ import { getMyAttendance, getMyCourses, getMyMarks } from "@/api/reports"; | |||
| 14 | import { getTime } from "@/api/time/getTime"; | 14 | import { getTime } from "@/api/time/getTime"; |
| 15 | import { RouteGuard } from "@/components/layout/route-guard"; | 15 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 16 | import { Badge } from "@/components/ui/badge"; | 16 | import { Badge } from "@/components/ui/badge"; |
| 17 | -import { ChartAreaTrend } from "@/components/ui/chart-area-trend"; | ||
| 18 | import { ChartBar } from "@/components/ui/chart-bar"; | 17 | import { ChartBar } from "@/components/ui/chart-bar"; |
| 19 | import { ChartProgressRing } from "@/components/ui/chart-progress-ring"; | 18 | import { ChartProgressRing } from "@/components/ui/chart-progress-ring"; |
| 20 | import { DataTable } from "@/components/ui/data-table"; | 19 | import { DataTable } from "@/components/ui/data-table"; |
| 21 | import { | 20 | import { |
| 22 | - IconArchive, | ||
| 23 | IconBook, | 21 | IconBook, |
| 24 | IconCalendarDays, | 22 | IconCalendarDays, |
| 25 | IconChart, | 23 | IconChart, |
| 26 | IconClipboardCheck, | 24 | IconClipboardCheck, |
| 27 | IconExam, | 25 | IconExam, |
| 28 | - IconHelpCircle, | ||
| 29 | IconHomework, | 26 | IconHomework, |
| 30 | - IconRefresh, | ||
| 31 | - IconSearch, | ||
| 32 | IconUsers, | 27 | IconUsers, |
| 33 | IconUtensils, | 28 | IconUtensils, |
| 34 | } from "@/components/ui/icons"; | 29 | } from "@/components/ui/icons"; |
| @@ -36,6 +31,7 @@ import { PageSpinner } from "@/components/ui/page-spinner"; | |||
| 36 | import type { MessageKey } from "@/i18n/messages"; | 31 | import type { MessageKey } from "@/i18n/messages"; |
| 37 | import { cn } from "@/lib/cn"; | 32 | import { cn } from "@/lib/cn"; |
| 38 | import { formatDateTime } from "@/lib/format"; | 33 | import { formatDateTime } from "@/lib/format"; |
| 34 | +import { hasMinRole } from "@/lib/roles"; | ||
| 39 | import { useAuth } from "@/stores/auth-context"; | 35 | import { useAuth } from "@/stores/auth-context"; |
| 40 | import { usePreferences, useT } from "@/stores/preferences-context"; | 36 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 41 | 37 | ||
| @@ -57,36 +53,8 @@ type StatCardData = { | |||
| 57 | labelKey: MessageKey; | 53 | labelKey: MessageKey; |
| 58 | value: string; | 54 | value: string; |
| 59 | Icon: Component<{ class?: string }>; | 55 | Icon: Component<{ class?: string }>; |
| 60 | - spark?: number[]; | ||
| 61 | }; | 56 | }; |
| 62 | 57 | ||
| 63 | -// Tiny real-data sparkline; renders nothing when there's no series. | ||
| 64 | -function StatSpark(props: { values: number[] }) { | ||
| 65 | - const pts = () => { | ||
| 66 | - const v = props.values; | ||
| 67 | - if (v.length < 2) return ""; | ||
| 68 | - const min = Math.min(...v); | ||
| 69 | - const max = Math.max(...v); | ||
| 70 | - const range = max - min || 1; | ||
| 71 | - const w = 64; | ||
| 72 | - const h = 24; | ||
| 73 | - return v | ||
| 74 | - .map((val, i) => { | ||
| 75 | - const x = (i / (v.length - 1)) * w; | ||
| 76 | - const y = h - ((val - min) / range) * h; | ||
| 77 | - return `${x.toFixed(1)},${y.toFixed(1)}`; | ||
| 78 | - }) | ||
| 79 | - .join(" "); | ||
| 80 | - }; | ||
| 81 | - return ( | ||
| 82 | - <Show when={pts()}> | ||
| 83 | - <svg viewBox="0 0 64 24" class="h-6 w-16 shrink-0 overflow-visible" preserveAspectRatio="none"> | ||
| 84 | - <polyline points={pts()} fill="none" stroke="hsl(var(--primary))" stroke-width="2" stroke-linejoin="round" stroke-linecap="round" /> | ||
| 85 | - </svg> | ||
| 86 | - </Show> | ||
| 87 | - ); | ||
| 88 | -} | ||
| 89 | - | ||
| 90 | const roleKeys: Record<Role, MessageKey> = { | 58 | const roleKeys: Record<Role, MessageKey> = { |
| 91 | student: "role.student", | 59 | student: "role.student", |
| 92 | parent: "role.parent", | 60 | parent: "role.parent", |
| @@ -113,63 +81,47 @@ function scheduleStatus(startsAt: number | null, endsAt: number | null, now: num | |||
| 113 | export default function DashboardPage() { | 81 | export default function DashboardPage() { |
| 114 | const auth = useAuth(); | 82 | const auth = useAuth(); |
| 115 | const t = useT(); | 83 | const t = useT(); |
| 84 | + const navigate = useNavigate(); | ||
| 116 | const { locale } = usePreferences(); | 85 | const { locale } = usePreferences(); |
| 117 | const user = () => auth.user()!; | 86 | const user = () => auth.user()!; |
| 118 | const role = () => user().role; | 87 | const role = () => user().role; |
| 119 | - const [clock, clockQ] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | 88 | + const [clock] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); |
| 120 | - const [courses, coursesQ] = createResource( | 89 | + const [courses] = createResource( |
| 121 | () => role() === "parent" ? null : role(), | 90 | () => role() === "parent" ? null : role(), |
| 122 | (currentRole) => currentRole === "student" | 91 | (currentRole) => currentRole === "student" |
| 123 | ? getMyCourses({ kind: "course", limit: 12 }) | 92 | ? getMyCourses({ kind: "course", limit: 12 }) |
| 124 | : getCourses({ kind: "course", limit: 12 }), | 93 | : getCourses({ kind: "course", limit: 12 }), |
| 125 | ); | 94 | ); |
| 126 | - const [events, eventsQ] = createResource( | 95 | + const [events] = createResource( |
| 127 | () => role() === "parent" ? null : clock()?.now, | 96 | () => role() === "parent" ? null : clock()?.now, |
| 128 | (now) => getEvents({ ends_after: now, limit: 50 }), | 97 | (now) => getEvents({ ends_after: now, limit: 50 }), |
| 129 | ); | 98 | ); |
| 130 | - const [exams, examsQ] = createResource( | 99 | + const [exams] = createResource( |
| 131 | () => role() === "parent" ? null : role(), | 100 | () => role() === "parent" ? null : role(), |
| 132 | () => getExams({ limit: 50 }), | 101 | () => getExams({ limit: 50 }), |
| 133 | ); | 102 | ); |
| 134 | - const [homework, homeworkQ] = createResource( | 103 | + const [homework] = createResource( |
| 135 | () => role() === "parent" ? null : clock()?.now, | 104 | () => role() === "parent" ? null : clock()?.now, |
| 136 | (now) => getHomework({ due_after: now, limit: 50 }), | 105 | (now) => getHomework({ due_after: now, limit: 50 }), |
| 137 | ); | 106 | ); |
| 138 | - const [children, childrenQ] = createResource( | 107 | + const [children] = createResource( |
| 139 | () => role() === "parent" ? true : null, | 108 | () => role() === "parent" ? true : null, |
| 140 | () => getMyStudents({ limit: 12 }), | 109 | () => getMyStudents({ limit: 12 }), |
| 141 | ); | 110 | ); |
| 142 | - const [appointments, appointmentsQ] = createResource( | 111 | + const [appointments] = createResource(() => getAppointments({ limit: 20 })); |
| 143 | - () => role() === "parent" ? true : null, | 112 | + const [menus] = createResource( |
| 144 | - () => getAppointments({ limit: 20 }), | ||
| 145 | - ); | ||
| 146 | - const [menus, menusQ] = createResource( | ||
| 147 | () => clock()?.now, | 113 | () => clock()?.now, |
| 148 | (now) => getMealMenus({ from: new Date(now).toISOString().slice(0, 10), limit: 1 }), | 114 | (now) => getMealMenus({ from: new Date(now).toISOString().slice(0, 10), limit: 1 }), |
| 149 | ); | 115 | ); |
| 150 | - const [marks, marksQ] = createResource( | 116 | + const [marks] = createResource( |
| 151 | () => role() === "student" ? true : null, | 117 | () => role() === "student" ? true : null, |
| 152 | () => getMyMarks(), | 118 | () => getMyMarks(), |
| 153 | ); | 119 | ); |
| 154 | - const [attendance, attendanceQ] = createResource( | 120 | + const [attendance] = createResource( |
| 155 | () => role() === "student" ? true : null, | 121 | () => role() === "student" ? true : null, |
| 156 | () => getMyAttendance(), | 122 | () => getMyAttendance(), |
| 157 | ); | 123 | ); |
| 158 | 124 | ||
| 159 | - const [refreshing, setRefreshing] = createSignal(false); | ||
| 160 | - const refresh = async () => { | ||
| 161 | - if (refreshing()) return; | ||
| 162 | - setRefreshing(true); | ||
| 163 | - try { | ||
| 164 | - await Promise.all( | ||
| 165 | - [clockQ, coursesQ, eventsQ, examsQ, homeworkQ, childrenQ, appointmentsQ, menusQ, marksQ, attendanceQ] | ||
| 166 | - .map((q) => q.refetch()), | ||
| 167 | - ); | ||
| 168 | - } finally { | ||
| 169 | - setRefreshing(false); | ||
| 170 | - } | ||
| 171 | - }; | ||
| 172 | - | ||
| 173 | const fullName = () => [user().name, user().surname].filter(Boolean).join(" ") || user().username; | 125 | const fullName = () => [user().name, user().surname].filter(Boolean).join(" ") || user().username; |
| 174 | const now = () => clock()?.now ?? Date.now(); | 126 | const now = () => clock()?.now ?? Date.now(); |
| 175 | 127 | ||
| @@ -181,30 +133,19 @@ export default function DashboardPage() { | |||
| 181 | return total ? Math.round((present / total) * 100) : null; | 133 | return total ? Math.round((present / total) * 100) : null; |
| 182 | }); | 134 | }); |
| 183 | 135 | ||
| 184 | - const capacities = () => | ||
| 185 | - (courses()?.items ?? []).map((c) => c.capacity).filter((n): n is number => n != null); | ||
| 186 | - const courseAvgValues = () => | ||
| 187 | - (marks()?.courses ?? []).filter((c) => c.average != null).map((c) => c.average!); | ||
| 188 | - const attendanceValues = () => { | ||
| 189 | - const report = attendance(); | ||
| 190 | - if (!report) return []; | ||
| 191 | - const sum = (k: "present" | "absent" | "late" | "excused") => report.events[k] + report.sessions[k]; | ||
| 192 | - return [sum("present"), sum("late"), sum("excused"), sum("absent")]; | ||
| 193 | - }; | ||
| 194 | - | ||
| 195 | const stats = createMemo<StatCardData[]>(() => { | 136 | const stats = createMemo<StatCardData[]>(() => { |
| 196 | const r = role(); | 137 | const r = role(); |
| 197 | if (r === "student") { | 138 | if (r === "student") { |
| 198 | return [ | 139 | return [ |
| 199 | - { labelKey: "dashboard.stats.courses", value: String(courses()?.total ?? 0), Icon: IconBook, spark: capacities() }, | 140 | + { labelKey: "dashboard.stats.courses", value: String(courses()?.total ?? 0), Icon: IconBook }, |
| 200 | { labelKey: "dashboard.stats.exams", value: String(exams()?.total ?? 0), Icon: IconExam }, | 141 | { labelKey: "dashboard.stats.exams", value: String(exams()?.total ?? 0), Icon: IconExam }, |
| 201 | - { labelKey: "dashboard.stats.average", value: marks()?.overall_average == null ? "β" : marks()!.overall_average!.toFixed(1), Icon: IconChart, spark: courseAvgValues() }, | 142 | + { labelKey: "dashboard.stats.average", value: marks()?.overall_average == null ? "β" : marks()!.overall_average!.toFixed(1), Icon: IconChart }, |
| 202 | - { labelKey: "dashboard.stats.attendance", value: attendanceRate() == null ? "β" : `${attendanceRate()}%`, Icon: IconClipboardCheck, spark: attendanceValues() }, | 143 | + { labelKey: "dashboard.stats.attendance", value: attendanceRate() == null ? "β" : `${attendanceRate()}%`, Icon: IconClipboardCheck }, |
| 203 | ]; | 144 | ]; |
| 204 | } | 145 | } |
| 205 | if (r === "teacher") { | 146 | if (r === "teacher") { |
| 206 | return [ | 147 | return [ |
| 207 | - { labelKey: "dashboard.stats.courses", value: String(courses()?.total ?? 0), Icon: IconBook, spark: capacities() }, | 148 | + { labelKey: "dashboard.stats.courses", value: String(courses()?.total ?? 0), Icon: IconBook }, |
| 208 | { labelKey: "dashboard.stats.exams", value: String(exams()?.total ?? 0), Icon: IconExam }, | 149 | { labelKey: "dashboard.stats.exams", value: String(exams()?.total ?? 0), Icon: IconExam }, |
| 209 | { labelKey: "dashboard.stats.events", value: String(events()?.total ?? 0), Icon: IconCalendarDays }, | 150 | { labelKey: "dashboard.stats.events", value: String(events()?.total ?? 0), Icon: IconCalendarDays }, |
| 210 | { labelKey: "dashboard.stats.homework", value: String(homework()?.total ?? 0), Icon: IconHomework }, | 151 | { labelKey: "dashboard.stats.homework", value: String(homework()?.total ?? 0), Icon: IconHomework }, |
| @@ -218,20 +159,20 @@ export default function DashboardPage() { | |||
| 218 | ]; | 159 | ]; |
| 219 | } | 160 | } |
| 220 | return [ | 161 | return [ |
| 221 | - { labelKey: "dashboard.stats.courses", value: String(courses()?.total ?? 0), Icon: IconBook, spark: capacities() }, | 162 | + { labelKey: "dashboard.stats.courses", value: String(courses()?.total ?? 0), Icon: IconBook }, |
| 222 | { labelKey: "dashboard.stats.exams", value: String(exams()?.total ?? 0), Icon: IconExam }, | 163 | { labelKey: "dashboard.stats.exams", value: String(exams()?.total ?? 0), Icon: IconExam }, |
| 223 | { labelKey: "dashboard.stats.events", value: String(events()?.total ?? 0), Icon: IconCalendarDays }, | 164 | { labelKey: "dashboard.stats.events", value: String(events()?.total ?? 0), Icon: IconCalendarDays }, |
| 224 | { labelKey: "dashboard.stats.meals", value: String(menus()?.total ?? 0), Icon: IconUtensils }, | 165 | { labelKey: "dashboard.stats.meals", value: String(menus()?.total ?? 0), Icon: IconUtensils }, |
| 225 | ]; | 166 | ]; |
| 226 | }); | 167 | }); |
| 227 | 168 | ||
| 228 | - // Progress panel β student: per-course averages; teacher/manager/admin: class sizes. | 169 | + // Progress panel β student: per-course averages; teacher/manager/admin: course capacities. |
| 229 | const courseAverages = createMemo(() => | 170 | const courseAverages = createMemo(() => |
| 230 | (marks()?.courses ?? []) | 171 | (marks()?.courses ?? []) |
| 231 | .filter((c) => c.average != null) | 172 | .filter((c) => c.average != null) |
| 232 | - .map((c) => ({ label: c.course.title, value: c.average!, formattedValue: c.average!.toFixed(1) })), | 173 | + .map((c) => ({ id: c.course.id, label: c.course.title, value: c.average!, formattedValue: c.average!.toFixed(1) })), |
| 233 | ); | 174 | ); |
| 234 | - const classSizes = createMemo(() => | 175 | + const courseCapacities = createMemo(() => |
| 235 | (courses()?.items ?? []) | 176 | (courses()?.items ?? []) |
| 236 | .filter((c) => c.capacity != null) | 177 | .filter((c) => c.capacity != null) |
| 237 | .map((c) => ({ id: c.id, label: c.title, value: c.capacity! })), | 178 | .map((c) => ({ id: c.id, label: c.title, value: c.capacity! })), |
| @@ -327,23 +268,21 @@ export default function DashboardPage() { | |||
| 327 | ); | 268 | ); |
| 328 | }, | 269 | }, |
| 329 | }, | 270 | }, |
| 330 | - { | ||
| 331 | - id: "priority", | ||
| 332 | - header: t("dashboard.col.priority"), | ||
| 333 | - enableSorting: false, | ||
| 334 | - meta: { headerClass }, | ||
| 335 | - cell: (info) => { | ||
| 336 | - const high = info.row.original.status !== "soon"; | ||
| 337 | - return ( | ||
| 338 | - <span class={cn("text-xs font-semibold", high ? "text-rose-600 dark:text-rose-400" : "text-amber-600 dark:text-amber-400")}> | ||
| 339 | - {high ? t("dashboard.priority.high") : t("dashboard.priority.medium")} | ||
| 340 | - </span> | ||
| 341 | - ); | ||
| 342 | - }, | ||
| 343 | - }, | ||
| 344 | ]); | 271 | ]); |
| 345 | 272 | ||
| 346 | const deadlineSearch = (row: DeadlineRow, q: string) => row.title.toLowerCase().includes(q.toLowerCase()); | 273 | const deadlineSearch = (row: DeadlineRow, q: string) => row.title.toLowerCase().includes(q.toLowerCase()); |
| 274 | + const openDeadline = (row: DeadlineRow) => { | ||
| 275 | + switch (row.kind) { | ||
| 276 | + case "exam": | ||
| 277 | + return navigate({ to: "/exams/$id", params: { id: row.id } }); | ||
| 278 | + case "event": | ||
| 279 | + return navigate({ to: "/events/$id", params: { id: row.id } }); | ||
| 280 | + case "homework": | ||
| 281 | + return navigate({ to: "/homework/$id", params: { id: row.id } }); | ||
| 282 | + case "appointment": | ||
| 283 | + return navigate({ to: "/appointments" }); | ||
| 284 | + } | ||
| 285 | + }; | ||
| 347 | 286 | ||
| 348 | const error = createMemo(() => { | 287 | const error = createMemo(() => { |
| 349 | const problem = courses.error || events.error || exams.error || homework.error || children.error || appointments.error || menus.error || marks.error || attendance.error; | 288 | const problem = courses.error || events.error || exams.error || homework.error || children.error || appointments.error || menus.error || marks.error || attendance.error; |
| @@ -383,9 +322,8 @@ export default function DashboardPage() { | |||
| 383 | </span> | 322 | </span> |
| 384 | <p class="min-w-0 flex-1 truncate text-xs font-medium text-muted-foreground">{t(stat.labelKey)}</p> | 323 | <p class="min-w-0 flex-1 truncate text-xs font-medium text-muted-foreground">{t(stat.labelKey)}</p> |
| 385 | </div> | 324 | </div> |
| 386 | - <div class="mt-3 flex items-end justify-between gap-2"> | 325 | + <div class="mt-3"> |
| 387 | <p class="mono tabular-nums text-2xl font-bold tracking-tight">{stat.value}</p> | 326 | <p class="mono tabular-nums text-2xl font-bold tracking-tight">{stat.value}</p> |
| 388 | - <Show when={stat.spark}>{(s) => <StatSpark values={s()} />}</Show> | ||
| 389 | </div> | 327 | </div> |
| 390 | </div> | 328 | </div> |
| 391 | )} | 329 | )} |
| @@ -396,12 +334,11 @@ export default function DashboardPage() { | |||
| 396 | <Show when={role() !== "parent"}> | 334 | <Show when={role() !== "parent"}> |
| 397 | <div class="grid gap-3 lg:grid-cols-3"> | 335 | <div class="grid gap-3 lg:grid-cols-3"> |
| 398 | <Show when={role() === "student"}> | 336 | <Show when={role() === "student"}> |
| 399 | - <ChartAreaTrend | 337 | + <ChartBar |
| 400 | class="lg:col-span-2" | 338 | class="lg:col-span-2" |
| 401 | title={t("dashboard.progressOverview")} | 339 | title={t("dashboard.progressOverview")} |
| 402 | subtitle={t("dashboard.courseAverages")} | 340 | subtitle={t("dashboard.courseAverages")} |
| 403 | items={courseAverages()} | 341 | items={courseAverages()} |
| 404 | - minScale={0} | ||
| 405 | maxScale={100} | 342 | maxScale={100} |
| 406 | /> | 343 | /> |
| 407 | </Show> | 344 | </Show> |
| @@ -409,8 +346,8 @@ export default function DashboardPage() { | |||
| 409 | <ChartBar | 346 | <ChartBar |
| 410 | class="lg:col-span-2" | 347 | class="lg:col-span-2" |
| 411 | title={t("dashboard.progressOverview")} | 348 | title={t("dashboard.progressOverview")} |
| 412 | - subtitle={t("dashboard.classSizes")} | 349 | + subtitle={t("dashboard.courseCapacities")} |
| 413 | - items={classSizes()} | 350 | + items={courseCapacities()} |
| 414 | /> | 351 | /> |
| 415 | </Show> | 352 | </Show> |
| 416 | <Show when={role() === "student"}> | 353 | <Show when={role() === "student"}> |
| @@ -431,8 +368,16 @@ export default function DashboardPage() { | |||
| 431 | </Show> | 368 | </Show> |
| 432 | 369 | ||
| 433 | <div class="grid gap-3 lg:grid-cols-3"> | 370 | <div class="grid gap-3 lg:grid-cols-3"> |
| 434 | - <section class={cn("flex flex-col gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs", role() !== "parent" ? "lg:col-span-2" : "lg:col-span-3")} aria-labelledby="deadlines-heading"> | 371 | + <section class={cn("flex flex-col gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs", hasMinRole(role(), "teacher") ? "lg:col-span-2" : "lg:col-span-3")} aria-labelledby="deadlines-heading"> |
| 435 | - <h2 id="deadlines-heading" class="text-base font-semibold tracking-tight">{t("dashboard.deadlines")}</h2> | 372 | + <div class="flex items-center justify-between gap-3"> |
| 373 | + <h2 id="deadlines-heading" class="text-base font-semibold tracking-tight">{t("dashboard.deadlines")}</h2> | ||
| 374 | + <Link | ||
| 375 | + to="/appointments" | ||
| 376 | + class="shrink-0 rounded-lg px-2 py-1 text-xs font-semibold text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring" | ||
| 377 | + > | ||
| 378 | + {t("nav.appointments")} | ||
| 379 | + </Link> | ||
| 380 | + </div> | ||
| 436 | <DataTable | 381 | <DataTable |
| 437 | columns={deadlineColumns()} | 382 | columns={deadlineColumns()} |
| 438 | data={deadlines()} | 383 | data={deadlines()} |
| @@ -440,60 +385,35 @@ export default function DashboardPage() { | |||
| 440 | searchPredicate={deadlineSearch} | 385 | searchPredicate={deadlineSearch} |
| 441 | filterPlaceholder={t("dashboard.deadlines")} | 386 | filterPlaceholder={t("dashboard.deadlines")} |
| 442 | empty={t("dashboard.upcomingEmpty")} | 387 | empty={t("dashboard.upcomingEmpty")} |
| 388 | + onRowClick={openDeadline} | ||
| 443 | /> | 389 | /> |
| 444 | </section> | 390 | </section> |
| 445 | 391 | ||
| 446 | - <Show when={role() !== "parent"}> | 392 | + <Show when={hasMinRole(role(), "teacher")}> |
| 447 | <section class="flex flex-col gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs lg:col-span-1" aria-labelledby="review-heading"> | 393 | <section class="flex flex-col gap-4 rounded-2xl border border-border bg-card p-4 shadow-xs lg:col-span-1" aria-labelledby="review-heading"> |
| 448 | <div class="space-y-1"> | 394 | <div class="space-y-1"> |
| 449 | - <h2 id="review-heading" class="text-base font-semibold tracking-tight">{t("nav.questionBank")}</h2> | 395 | + <h2 id="review-heading" class="text-base font-semibold tracking-tight">{t("dashboard.teachingResources")}</h2> |
| 450 | - <p class="text-sm text-muted-foreground">{t("dashboard.questionHubDesc")}</p> | 396 | + <p class="text-sm text-muted-foreground">{t("dashboard.teachingResourcesDesc")}</p> |
| 451 | </div> | 397 | </div> |
| 452 | - <Link | 398 | + <div class="grid gap-2"> |
| 453 | - to="/question-bank" | ||
| 454 | - class="flex h-10 items-center gap-2 rounded-xl border border-border bg-muted/30 px-3 text-sm text-muted-foreground outline-hidden transition-colors hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-ring" | ||
| 455 | - > | ||
| 456 | - <IconSearch class="h-4 w-4 shrink-0" /> | ||
| 457 | - <span class="truncate">{t("dashboard.questionHubPlaceholder")}</span> | ||
| 458 | - </Link> | ||
| 459 | - <div class="flex items-center gap-2"> | ||
| 460 | - <For each={[IconArchive, IconHelpCircle, IconExam, IconBook, IconChart]}> | ||
| 461 | - {(Icon) => ( | ||
| 462 | - <span class="flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/30 text-muted-foreground"> | ||
| 463 | - <Icon class="h-4 w-4" /> | ||
| 464 | - </span> | ||
| 465 | - )} | ||
| 466 | - </For> | ||
| 467 | - </div> | ||
| 468 | - <div class="mt-auto grid grid-cols-2 gap-2"> | ||
| 469 | <Link | 399 | <Link |
| 470 | to="/question-bank" | 400 | to="/question-bank" |
| 471 | - class="flex h-10 items-center justify-center rounded-xl border border-border bg-card text-sm font-semibold outline-hidden transition-colors hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-ring" | 401 | + class="rounded-xl border border-border bg-card p-3 outline-hidden transition-colors hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-ring" |
| 472 | > | 402 | > |
| 473 | - {t("nav.questionBank")} | 403 | + <span class="text-sm font-semibold">{t("nav.questionBank")}</span> |
| 404 | + <span class="mt-0.5 block text-xs text-muted-foreground">{t("dashboard.questionBankDesc")}</span> | ||
| 474 | </Link> | 405 | </Link> |
| 475 | <Link | 406 | <Link |
| 476 | to="/questions" | 407 | to="/questions" |
| 477 | - class="flex h-10 items-center justify-center rounded-xl bg-primary text-sm font-semibold text-primary-foreground outline-hidden transition-colors hover:bg-primary/90 focus-visible:ring-2 focus-visible:ring-ring" | 408 | + class="rounded-xl border border-border bg-card p-3 outline-hidden transition-colors hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-ring" |
| 478 | > | 409 | > |
| 479 | - {t("dashboard.askQuestion")} | 410 | + <span class="text-sm font-semibold">{t("nav.questions")}</span> |
| 411 | + <span class="mt-0.5 block text-xs text-muted-foreground">{t("dashboard.questionPoolDesc")}</span> | ||
| 480 | </Link> | 412 | </Link> |
| 481 | </div> | 413 | </div> |
| 482 | </section> | 414 | </section> |
| 483 | </Show> | 415 | </Show> |
| 484 | </div> | 416 | </div> |
| 485 | - | ||
| 486 | - <div class="flex justify-center pt-2"> | ||
| 487 | - <button | ||
| 488 | - type="button" | ||
| 489 | - onClick={() => void refresh()} | ||
| 490 | - disabled={refreshing()} | ||
| 491 | - class="inline-flex h-9 items-center gap-2 rounded-lg border border-border bg-card px-4 text-xs font-semibold text-muted-foreground outline-hidden transition-colors hover:bg-muted/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60" | ||
| 492 | - > | ||
| 493 | - <IconRefresh class={cn("h-3.5 w-3.5", refreshing() && "animate-spin")} /> | ||
| 494 | - {t("dashboard.refresh")} | ||
| 495 | - </button> | ||
| 496 | - </div> | ||
| 497 | </Suspense> | 417 | </Suspense> |
| 498 | </div> | 418 | </div> |
| 499 | </RouteGuard> | 419 | </RouteGuard> |