From 2ca60ab956f50de95c2c1b28ddb08c263c960908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 9 Oct 2026 14:29:07 +0200 Subject: [PATCH] refactor(day): word the cycle line through a typed key map --- src/components/day/day-cycle-line.ts | 15 ++++++--------- src/components/day/label-keys.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/day/day-cycle-line.ts b/src/components/day/day-cycle-line.ts index 83a97a9d4..e6120bb4b 100644 --- a/src/components/day/day-cycle-line.ts +++ b/src/components/day/day-cycle-line.ts @@ -1,11 +1,6 @@ import type { DayRunningItem } from "@/lib/day/contract"; -const CYCLE_PHASES: ReadonlySet = new Set([ - "MENSTRUAL", - "FOLLICULAR", - "OVULATORY", - "LUTEAL", -]); +import { CYCLE_PHASE_LINE_KEY } from "./label-keys"; /** * The quiet line under a running cycle: "Cycle day 12, follicular phase", @@ -18,8 +13,10 @@ export function cycleRunningLine( t: (key: string, params?: Record) => string, ): string | null { if (item.kind !== "cyclePhase" || item.dayIndex === null) return null; - if (item.sub !== null && CYCLE_PHASES.has(item.sub)) { - return t(`day.cyclePhaseLine.${item.sub}`, { n: item.dayIndex }); - } + const key = + item.sub === null + ? undefined + : (CYCLE_PHASE_LINE_KEY as Readonly>)[item.sub]; + if (key) return t(key, { n: item.dayIndex }); return t("day.cycleDay", { n: item.dayIndex }); } diff --git a/src/components/day/label-keys.ts b/src/components/day/label-keys.ts index 237fc520c..03b1d4b10 100644 --- a/src/components/day/label-keys.ts +++ b/src/components/day/label-keys.ts @@ -97,3 +97,13 @@ export const ILLNESS_IMPACT_KEY: Readonly> = { "2": "illness.impact.2", "3": "illness.impact.3", }; + +/** The quiet line under a running cycle, by the phase code the server sends. */ +export const CYCLE_PHASE_LINE_KEY: Readonly< + Record<"MENSTRUAL" | "FOLLICULAR" | "OVULATORY" | "LUTEAL", string> +> = { + MENSTRUAL: "day.cyclePhaseLine.MENSTRUAL", + FOLLICULAR: "day.cyclePhaseLine.FOLLICULAR", + OVULATORY: "day.cyclePhaseLine.OVULATORY", + LUTEAL: "day.cyclePhaseLine.LUTEAL", +};