mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
Maintainer-voice sweep across `src/`. ~190 references to the maintainer by first name in code comments and JSDoc neutralised to "the maintainer", "the live tenant", "users", or "the user" depending on context. Three sed passes covering ~50 distinct patterns (`Marc reported`, `Marc wants`, `Marc kept`, `Marc rolled back`, etc.). Test fixtures (`displayName: "Marc B."`, `username: "marc"`, `<HeroStrip userName="Marc">`) kept as opaque test data per the brief. CHANGELOG normalisation. The v1.4.14 + v1.4.15 entries paired a German bullet with its English translation by historical design — the in-app copy is English-default and the user docs are English, so the mixed-language style was a holdover from the early-marathon notes. A one-off node script extracted the `_..._` English paragraph from each bilingual bullet and rewrote the entry as that text. ~44 bullets reduced; one Docs bullet that lost a leading word in the regex fixed by hand. CLAUDE.md → CONTRIBUTING-AI.md rename so the filename is no longer AI-vendor-specific. `CONTRIBUTING.md` reference updated. `AGENTS.md` stays in place for multi-agent compatibility (the conventions doc is shared with Codex / Cursor / etc.). Wave-4 state wrap. STATE.md now records C1–C5 + D + D2 as complete; v1421-backlog.md grew a "Closed in v1.4.22" header listing the 20 items the marathon landed; `.planning/phase-W4-report.md` documents the per-commit decisions, test deltas, and the 23 items deferred to v1.4.23 with reasoning. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
136 lines
4.3 KiB
TypeScript
136 lines
4.3 KiB
TypeScript
"use client";
|
|
|
|
import { CheckCircle2, AlertTriangle, CircleSlash } from "lucide-react";
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { useTranslations } from "@/lib/i18n/context";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
/**
|
|
* v1.4.19 phase A5 — single status pill rendered top-right of every
|
|
* integration card (Withings, Mood Log, Apple Health…). It replaces
|
|
* the three- to four-fold redundant status surface the maintainer spotted in
|
|
* v1.4.18:
|
|
*
|
|
* - top-right "Connected" badge
|
|
* - middle container with "Connected / last successful / last attempt"
|
|
* - bottom-of-card "letzter Sync" line
|
|
*
|
|
* Now there is exactly ONE place a sync status can appear on a card
|
|
* and it follows the pattern the maintainer liked from the Withings header: a
|
|
* Dracula-tokenized chip with the relative time inline.
|
|
*
|
|
* The component is locale-aware (EN + DE) and mobile-safe: on a
|
|
* Pixel-5 viewport (393 CSS px) the pill stays on the same line as
|
|
* the card title because it whitespace-nowraps and tucks the icon +
|
|
* abbreviated time form into a 12 char string at most.
|
|
*/
|
|
|
|
export type IntegrationPillState = "connected" | "error" | "disconnected";
|
|
|
|
interface IntegrationStatusPillProps {
|
|
state: IntegrationPillState;
|
|
/** When connected, the last-successful-sync timestamp drives the
|
|
* relative "12 min ago" suffix. Pass `null` to suppress the
|
|
* suffix (used when the integration was just configured but has
|
|
* never synced yet). */
|
|
lastSyncAt: Date | string | null;
|
|
/** Override "now" for deterministic testing. Defaults to `new Date()`. */
|
|
now?: Date;
|
|
className?: string;
|
|
}
|
|
|
|
function toDate(value: Date | string): Date {
|
|
return value instanceof Date ? value : new Date(value);
|
|
}
|
|
|
|
/**
|
|
* Translate a millisecond delta into a short, locale-aware relative
|
|
* string. We keep the buckets small and fixed (just-now / minutes /
|
|
* hours / days) because the pill must fit on a 360 px wide card.
|
|
*/
|
|
function formatRelative(
|
|
deltaMs: number,
|
|
t: (key: string, params?: Record<string, string | number>) => string,
|
|
): string {
|
|
if (deltaMs < 60_000) return t("settings.integrationPill.justNow");
|
|
const minutes = Math.floor(deltaMs / 60_000);
|
|
if (minutes < 60) {
|
|
return t("settings.integrationPill.minutesAgo", { count: minutes });
|
|
}
|
|
const hours = Math.floor(minutes / 60);
|
|
if (hours < 24) {
|
|
return t("settings.integrationPill.hoursAgo", { count: hours });
|
|
}
|
|
const days = Math.floor(hours / 24);
|
|
return t("settings.integrationPill.daysAgo", { count: days });
|
|
}
|
|
|
|
export function IntegrationStatusPill({
|
|
state,
|
|
lastSyncAt,
|
|
now,
|
|
className,
|
|
}: IntegrationStatusPillProps) {
|
|
const { t } = useTranslations();
|
|
|
|
// chipClass only applies to the `connected` branch — `error` falls back
|
|
// to `variant="destructive"` and `disconnected` to `variant="outline"`.
|
|
const connectedChipClass =
|
|
"border-dracula-green/30 bg-dracula-green/15 text-dracula-green";
|
|
|
|
let label: string;
|
|
let icon: React.ReactNode;
|
|
|
|
switch (state) {
|
|
case "connected":
|
|
label = t("settings.integrationPill.connected");
|
|
icon = <CheckCircle2 aria-hidden="true" className="h-3 w-3" />;
|
|
break;
|
|
case "error":
|
|
label = t("settings.integrationPill.errorReconnect");
|
|
icon = <AlertTriangle aria-hidden="true" className="h-3 w-3" />;
|
|
break;
|
|
case "disconnected":
|
|
label = t("settings.integrationPill.notConnected");
|
|
icon = <CircleSlash aria-hidden="true" className="h-3 w-3" />;
|
|
break;
|
|
}
|
|
|
|
const reference = now ?? new Date();
|
|
const relative =
|
|
state === "connected" && lastSyncAt
|
|
? formatRelative(
|
|
Math.max(0, reference.getTime() - toDate(lastSyncAt).getTime()),
|
|
t,
|
|
)
|
|
: null;
|
|
|
|
return (
|
|
<Badge
|
|
data-testid="integration-status-pill"
|
|
data-state={state}
|
|
variant={
|
|
state === "connected"
|
|
? undefined
|
|
: state === "error"
|
|
? "destructive"
|
|
: "outline"
|
|
}
|
|
aria-label={t("settings.integrationPill.ariaLabel")}
|
|
className={cn(
|
|
"max-w-full whitespace-nowrap",
|
|
state === "connected" && connectedChipClass,
|
|
className,
|
|
)}
|
|
>
|
|
{icon}
|
|
<span className="truncate">
|
|
{label}
|
|
{relative ? <span aria-hidden="true"> · {relative}</span> : null}
|
|
</span>
|
|
{relative ? <span className="sr-only">{relative}</span> : null}
|
|
</Badge>
|
|
);
|
|
}
|