mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
refactor(day): word the cycle line through a typed key map
This commit is contained in:
1 parent
6033935449
commit
2ca60ab956
2 files changed
+16
-9
No files matched your search
@@ -1,11 +1,6 @@
|
||||
import type { DayRunningItem } from "@/lib/day/contract";
|
||||
|
||||
const CYCLE_PHASES: ReadonlySet<string> = 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 | number>) => 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<Record<string, string>>)[item.sub];
|
||||
if (key) return t(key, { n: item.dayIndex });
|
||||
return t("day.cycleDay", { n: item.dayIndex });
|
||||
}
|
||||
@@ -97,3 +97,13 @@ export const ILLNESS_IMPACT_KEY: Readonly<Record<string, string>> = {
|
||||
"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",
|
||||
};
|
||||
Reference in new issue
Block a user