From 34061236e7f98995b0fde4b6cdbb106f065f8344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 5 Jun 2026 01:17:15 +0200 Subject: [PATCH] refactor: simplify the capture picker without behavior change Drop the no-op single-argument cn() wrapper on the chooser button class (and its now-unused import), and replace the three-way nested ternary that resolves the form-sheet title with an explicit per-kind lookup map. The null-kind fallback keeps the prior ternary's mood label, and the sheet stays closed in that state so the title is never read. (cherry picked from commit 856e620754753570e0d4ce8d6ce982778e929b75) --- src/components/layout/capture-picker.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/layout/capture-picker.tsx b/src/components/layout/capture-picker.tsx index a7ba357dd..7228221b4 100644 --- a/src/components/layout/capture-picker.tsx +++ b/src/components/layout/capture-picker.tsx @@ -7,7 +7,6 @@ import { MeasurementForm } from "@/components/measurements/measurement-form"; import { MoodForm } from "@/components/mood/mood-form"; import { MedicationIntakeQuickAdd } from "@/components/dashboard/medication-intake-quick-add"; import { ResponsiveSheet } from "@/components/ui/responsive-sheet"; -import { cn } from "@/lib/utils"; import { useTranslations } from "@/lib/i18n/context"; /** @@ -80,12 +79,15 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) { }, ]; - const formTitle = - kind === "measurement" - ? t("measurements.addMeasurement") - : kind === "medication" - ? t("nav.capture.medication") - : t("mood.addEntry"); + const formTitleByKind: Record = { + measurement: t("measurements.addMeasurement"), + medication: t("nav.capture.medication"), + mood: t("mood.addEntry"), + }; + // `kind === null` keeps the form sheet closed (the title is unread then); + // the mood label is the harmless default, matching the prior ternary's + // else branch. + const formTitle = kind ? formTitleByKind[kind] : t("mood.addEntry"); return ( <> @@ -103,9 +105,7 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) { type="button" data-testid={`capture-picker-${opt.kind}`} onClick={() => chooseKind(opt.kind)} - className={cn( - "border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2", - )} + className="border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2" >