mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
The two consoles used the same primitives and still read as two systems, because everything without a primitive had drifted: the header-to-body step existed in three competing techniques at once (`mt-4` on the first body child, `space-y-4` on the card, `mb-4` on the header), the body started either at the card edge or 28 px in, and both shells hand-rolled the page title instead of calling `PageHeader`. Move the decisions into the primitives so a call site cannot re-open them: - `SettingsCard` is gap-based like `Card` (`flex flex-col gap-4`). The header-to-body step is the container's, not a margin somebody remembers. A dense card still overrides the gap on the card itself. - The body starts at the card edge. `pl-7` is gone — off the spacing scale, and it mis-aligned action rows against their own forms wherever two neighbouring cards disagreed about it. - The card header's description slot loses its `space-y-1`. That was the licence call sites used to stack explainer paragraphs into a muted `text-xs` slot; the slot holds one sentence. - New `SettingsCardActions`: one action row, trailing edge, last thing in the card. `align="start"` spells the one exception, a card whose only actions are links out. - New `StatTile` replaces four hand-rolled label/value boxes in Admin. - `SectionHeading` moves from `insights/` to `ui/`. It is the heading above a group of cards, which is what Settings needs; Settings had been using a card header with no card, which reads as a card that failed to paint. Both shells now render their heading through `PageHeader`, which gained `headingAs="div"` for the second copy each shell paints (mobile above the nav strip, desktop inside the grid) so only one is a real `<h1>`. The page explainer is muted everywhere: the primitive said foreground, the standards and every hand-rolled copy said muted, so pages disagreed with each other. Medications, Vorsorge, the labs / custom-metric / illness detail pages and the clinician view drop their hand-rolled title blocks too, including the mid-word truncation on the medications subtitle. Tests pin the parts that can be checked exactly: the card's gap, the description slot's missing rhythm, the action row's two alignments, the `<h1>`-free shells, and a sweep asserting `pl-7` stays gone.
111 lines
3.9 KiB
TypeScript
111 lines
3.9 KiB
TypeScript
"use client";
|
|
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { Droplet, Info } from "lucide-react";
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { SettingsCard } from "@/components/settings/settings-card";
|
|
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
|
import { useTranslations } from "@/lib/i18n/context";
|
|
import { queryKeys } from "@/lib/query-keys";
|
|
import { apiGet, apiPatch } from "@/lib/api/api-fetch";
|
|
|
|
/**
|
|
* Glucose reference band — the web control for the declared diabetes opt-in
|
|
* (`GET/PATCH /api/auth/me/diabetes`).
|
|
*
|
|
* WHY IT LIVES ON TARGETS
|
|
* -----------------------
|
|
* The flag answers exactly the question this page answers — "which range is my
|
|
* reading judged against" — and the page already owns the four glucose target
|
|
* rows. Putting it anywhere else would split one concept across two surfaces.
|
|
* The card sits ABOVE the per-metric editor because the two controls are
|
|
* ordered: this one picks the default band, a per-metric override below then
|
|
* beats it (`src/lib/targets/glucose-targets.ts`).
|
|
*
|
|
* WHAT IT DOES NOT DO
|
|
* -------------------
|
|
* The flag is a display preference, never a diagnosis, and is never inferred
|
|
* from a reading. It selects the band the glucose surfaces and the Coach's
|
|
* reference grounding read; the app takes no clinical action on it. The copy
|
|
* says so at the point of the switch rather than in a help page.
|
|
*
|
|
* Note: `GET /api/user/thresholds` (the editor below) reports the general
|
|
* bands regardless of this flag — the flag resolves in the targets pipeline
|
|
* (`src/lib/targets/build-response.ts`), which is why the mutation invalidates
|
|
* `insightsTargets()` rather than `userThresholds()`.
|
|
*/
|
|
|
|
interface DiabetesPrefShape {
|
|
hasDiabetes: boolean;
|
|
}
|
|
|
|
export function GlucoseReferenceCard() {
|
|
const { t } = useTranslations();
|
|
const queryClient = useQueryClient();
|
|
|
|
const { data } = useQuery({
|
|
queryKey: queryKeys.diabetesPref(),
|
|
queryFn: async () => apiGet<DiabetesPrefShape>("/api/auth/me/diabetes"),
|
|
});
|
|
|
|
const toggle = useMutation({
|
|
mutationFn: async (hasDiabetes: boolean) =>
|
|
apiPatch<DiabetesPrefShape>("/api/auth/me/diabetes", { hasDiabetes }),
|
|
onSuccess: (next) => {
|
|
queryClient.setQueryData(queryKeys.diabetesPref(), next);
|
|
void queryClient.invalidateQueries({
|
|
queryKey: queryKeys.insightsTargets(),
|
|
});
|
|
},
|
|
});
|
|
|
|
const enabled = data?.hasDiabetes ?? false;
|
|
|
|
return (
|
|
<SettingsCard>
|
|
<SettingsCardHeader
|
|
icon={Droplet}
|
|
title={t("settings.glucoseReference.title")}
|
|
description={t("settings.glucoseReference.description")}
|
|
/>
|
|
<div className="space-y-4">
|
|
<div className="flex items-start justify-between gap-4">
|
|
<Label htmlFor="glucose-reference-diabetes" className="text-sm">
|
|
{t("settings.glucoseReference.enable")}
|
|
</Label>
|
|
<Switch
|
|
id="glucose-reference-diabetes"
|
|
checked={enabled}
|
|
disabled={toggle.isPending || data == null}
|
|
onCheckedChange={(v) => toggle.mutate(v)}
|
|
className="mt-0.5 shrink-0"
|
|
/>
|
|
</div>
|
|
|
|
<p className="text-sm">{t("settings.glucoseReference.explainer")}</p>
|
|
|
|
<div
|
|
data-slot="glucose-reference-disclaimer"
|
|
className="border-border bg-muted/40 flex items-start gap-2.5 rounded-lg border-l-2 p-3"
|
|
>
|
|
<Info
|
|
className="text-muted-foreground mt-0.5 h-4 w-4 shrink-0"
|
|
aria-hidden="true"
|
|
/>
|
|
<p className="text-foreground/80 text-xs leading-relaxed">
|
|
{t("settings.glucoseReference.disclaimer")}
|
|
</p>
|
|
</div>
|
|
|
|
{toggle.isError ? (
|
|
<p className="text-destructive text-sm" role="alert">
|
|
{t("settings.glucoseReference.error")}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
</SettingsCard>
|
|
);
|
|
}
|