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.
108 lines
3.8 KiB
TypeScript
108 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* The Health Score's "something about this number changed" note, rendered
|
|
* for the first time.
|
|
*
|
|
* The machinery behind it shipped a while ago and has been raising,
|
|
* persisting and evicting a notice that nothing ever drew: the report has
|
|
* carried `algorithmNotice` for its whole life and no surface read it.
|
|
* This is that renderer. It sits on the settings page rather than on the
|
|
* hero because the note's whole subject is what counts toward the score,
|
|
* and the person reading it is one tap from acting on it.
|
|
*
|
|
* Two notes ride one key, told apart by the account's own recipe version.
|
|
*
|
|
* - **Version 0** — nobody has chosen yet. The note explains what the
|
|
* upgrade did: what counts used to follow the module switches, it now
|
|
* follows this page, and the number itself did not move. It is the
|
|
* one-time note for accounts that existed before the choice did, and
|
|
* it is written to be true for a fresh account as well, because the
|
|
* stored recipe cannot tell the two apart and inventing a distinction
|
|
* from the account's age would be guessing.
|
|
* - **Version 1 and up** — the person changed what counts, on a date
|
|
* the recipe records. The note says what that does to the history.
|
|
*
|
|
* Dismissal is per key, so a dismissal of one version never silences the
|
|
* next, and it survives a reload because the server holds it.
|
|
*/
|
|
|
|
import { Info, Loader2 } from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { SettingsCard } from "@/components/settings/settings-card";
|
|
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
|
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
|
|
|
export interface ScoreChangeNoticeProps {
|
|
/** The account's own recipe version. 0 while nobody has chosen. */
|
|
configVersion: number;
|
|
/** When the recipe last changed, ISO 8601, or null while it never has. */
|
|
changedAt: string | null;
|
|
/** Fired when the person acknowledges the note. */
|
|
onDismiss: () => void;
|
|
dismissing?: boolean;
|
|
}
|
|
|
|
export function ScoreChangeNotice({
|
|
configVersion,
|
|
changedAt,
|
|
onDismiss,
|
|
dismissing = false,
|
|
}: ScoreChangeNoticeProps) {
|
|
const { t } = useTranslations();
|
|
const fmt = useFormatters();
|
|
const kind = configVersion >= 1 ? "changed" : "upgrade";
|
|
const parsed = changedAt ? new Date(changedAt) : null;
|
|
const dateLabel =
|
|
parsed && !Number.isNaN(parsed.getTime()) ? fmt.date(parsed) : null;
|
|
|
|
// Written out rather than assembled from the discriminator so the i18n
|
|
// call-site guard can see every key this component can reach.
|
|
const title =
|
|
kind === "changed"
|
|
? t("settings.sections.score.notice.changed.title")
|
|
: t("settings.sections.score.notice.upgrade.title");
|
|
const body =
|
|
kind !== "changed"
|
|
? t("settings.sections.score.notice.upgrade.body")
|
|
: dateLabel
|
|
? t("settings.sections.score.notice.changed.body", { date: dateLabel })
|
|
: t("settings.sections.score.notice.changed.bodyUndated");
|
|
|
|
return (
|
|
<SettingsCard
|
|
as="section"
|
|
data-slot="score-change-notice"
|
|
data-kind={kind}
|
|
aria-labelledby="score-change-notice-title"
|
|
>
|
|
<SettingsCardHeader
|
|
icon={Info}
|
|
titleId="score-change-notice-title"
|
|
title={title}
|
|
/>
|
|
<p data-slot="score-change-notice-body" className="text-sm">
|
|
{body}
|
|
</p>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={onDismiss}
|
|
disabled={dismissing}
|
|
data-slot="score-change-notice-dismiss"
|
|
className="min-h-11 sm:min-h-9"
|
|
>
|
|
{dismissing ? (
|
|
<Loader2
|
|
aria-hidden="true"
|
|
className="size-3.5 animate-spin motion-reduce:animate-none"
|
|
/>
|
|
) : null}
|
|
{t("settings.sections.score.notice.dismiss")}
|
|
</Button>
|
|
</SettingsCard>
|
|
);
|
|
}
|