From 5e1f5aa9eab8675c355dbb40f5c428625ff8e85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 8 Aug 2026 04:02:34 +0200 Subject: [PATCH] refactor(mood): keep the trend windows in one place The dead-code sweep found the window type exported and unread. It was unread because the surface that offers the choice carried its own copy of the same three numbers: the chart could not import the calculator's, since that module reaches the database client two hops down and a client component pulling it in would ship Prisma to the browser. Both now come from the dimension table, which is pure by construction and which the chart already imported. One declaration of 7 / 30 / 90, read by the calculator that averages over them and by the control that offers them, so the two cannot drift. --- .../insights/mood/mood-dimension-trends.tsx | 15 ++++++++------- src/lib/insights/mood-aggregates.ts | 1 - src/lib/insights/mood-dimension-series.ts | 10 +++++----- src/lib/mood/dimensions.ts | 13 +++++++++++++ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/components/insights/mood/mood-dimension-trends.tsx b/src/components/insights/mood/mood-dimension-trends.tsx index b9aa7af6e..2b06f7ca8 100644 --- a/src/components/insights/mood/mood-dimension-trends.tsx +++ b/src/components/insights/mood/mood-dimension-trends.tsx @@ -12,7 +12,11 @@ import { } from "recharts"; import { useTranslations } from "@/lib/i18n/context"; -import { MOOD_DIMENSIONS } from "@/lib/mood/dimensions"; +import { + MOOD_DIMENSIONS, + MOOD_DIMENSION_WINDOWS, + type MoodDimensionWindow, +} from "@/lib/mood/dimensions"; import { cn } from "@/lib/utils"; /** @@ -50,9 +54,6 @@ export interface MoodDimensionSummaryData { series: MoodDimensionPointData[]; } -const WINDOWS = [7, 30, 90] as const; -type Window = (typeof WINDOWS)[number]; - /** One colour per dimension, from the same semantic set the other charts use. */ const COLOR_BY_KEY: Record = { a1: "var(--chart-1)", @@ -64,7 +65,7 @@ const COLOR_BY_KEY: Record = { function meanForWindow( summary: MoodDimensionSummaryData, - window: Window, + window: MoodDimensionWindow, ): number | null { if (window === 7) return summary.avg7; if (window === 30) return summary.avg30; @@ -77,7 +78,7 @@ export function MoodDimensionTrends({ dimensions: MoodDimensionSummaryData[]; }) { const { t } = useTranslations(); - const [window, setWindow] = useState(30); + const [window, setWindow] = useState(30); const present = dimensions.filter((d) => d.present); const missing = dimensions.filter((d) => !d.present); @@ -115,7 +116,7 @@ export function MoodDimensionTrends({ return (
- {WINDOWS.map((option) => ( + {MOOD_DIMENSION_WINDOWS.map((option) => (