mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
Merge remote-tracking branch 'origin/feat/dashboard-today-overview' into release/v1.40.2
This commit is contained in:
commit
98ac9c3d80
28 files changed
+3837
-170
No files matched your search
@@ -355,6 +355,9 @@ const DIGEST: DailyDigest = {
|
||||
score: null,
|
||||
topSignal: null,
|
||||
briefingLead: "A steady week so far.",
|
||||
lead: { text: "A steady week so far.", source: "briefing" },
|
||||
today: [],
|
||||
restMode: null,
|
||||
line: "A steady week so far.",
|
||||
justIn: null,
|
||||
reactionLine: null,
|
||||
|
||||
@@ -42,6 +42,9 @@ function digest(over: Partial<DailyDigest> = {}): DailyDigest {
|
||||
score: { value: 82, band: "green", delta: 3 },
|
||||
topSignal: null,
|
||||
briefingLead: "Your week is trending steady.",
|
||||
lead: { text: "Your week is trending steady.", source: "briefing" },
|
||||
today: [],
|
||||
restMode: null,
|
||||
line: "Your week is trending steady.",
|
||||
worthALook: [],
|
||||
justIn: null,
|
||||
@@ -105,6 +108,7 @@ describe("TodayHero — an arrival is not a chip", () => {
|
||||
digest={digest({
|
||||
score: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
worthALook: [],
|
||||
reactionLine: null,
|
||||
justIn: { kind: "sleep_night", at: ARRIVED_AT },
|
||||
@@ -152,6 +156,7 @@ describe("TodayHero — what earns the hero without a score", () => {
|
||||
return digest({
|
||||
score: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
reactionLine: null,
|
||||
phase: "provisional",
|
||||
sleepPending: true,
|
||||
@@ -203,6 +208,8 @@ describe("TodayHero — the reaction line replaces the lead", () => {
|
||||
digest={digest({
|
||||
reactionLine: REACTION,
|
||||
briefingLead: "Your week is trending steady.",
|
||||
// The server resolved the reaction line as the lead.
|
||||
lead: { text: REACTION, source: "reaction" },
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
@@ -218,6 +225,8 @@ describe("TodayHero — the reaction line replaces the lead", () => {
|
||||
digest={digest({
|
||||
reactionLine: REACTION,
|
||||
briefingLead: "Your week is trending steady.",
|
||||
// The server resolved the reaction line as the lead.
|
||||
lead: { text: REACTION, source: "reaction" },
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
@@ -246,6 +255,7 @@ describe("TodayHero — the reaction line replaces the lead", () => {
|
||||
digest={digest({
|
||||
score: null,
|
||||
briefingLead: null,
|
||||
lead: { text: REACTION, source: "reaction" },
|
||||
worthALook: [],
|
||||
reactionLine: REACTION,
|
||||
justIn: { kind: "weight", at: ARRIVED_AT },
|
||||
|
||||
@@ -6,6 +6,7 @@ import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { TodayHero } from "../today-hero";
|
||||
import type { DailyDigest } from "@/lib/daily/digest";
|
||||
import type { PriorityItem } from "@/lib/daily/priority-item";
|
||||
import type { TodayFact } from "@/lib/daily/today-overview";
|
||||
import { SCORE_VERSION } from "@/lib/analytics/score/types";
|
||||
import { DIGEST_AI_AVAILABLE } from "@/__tests__/helpers/ai-capability-fixtures";
|
||||
|
||||
@@ -71,6 +72,9 @@ function digest(over: Partial<DailyDigest> = {}): DailyDigest {
|
||||
delta: "+6 mmHg vs your 30-day average",
|
||||
},
|
||||
briefingLead: "Your week is trending steady.",
|
||||
lead: { text: "Your week is trending steady.", source: "briefing" },
|
||||
today: [],
|
||||
restMode: null,
|
||||
line: "Your week is trending steady.",
|
||||
worthALook: [doseItem, syncItem],
|
||||
justIn: null,
|
||||
@@ -146,6 +150,7 @@ describe("<TodayHero>", () => {
|
||||
sleepPending: true,
|
||||
score: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
line: "Your health score today is 82.",
|
||||
worthALook: [doseItem],
|
||||
})}
|
||||
@@ -160,13 +165,15 @@ describe("<TodayHero>", () => {
|
||||
expect(html).not.toContain('data-slot="today-hero-briefing-link"');
|
||||
});
|
||||
|
||||
it("keeps the useful loaded narrative without repeating the ring's numeric score", () => {
|
||||
it("renders the server-resolved lead without repeating the ring's numeric score", () => {
|
||||
// The server already dropped the score sentence from the briefing (see
|
||||
// `today-overview.test.ts`); the hero prints what it was handed.
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
briefingLead:
|
||||
"Your health score is 82. Your week is trending steady.",
|
||||
line: "Your health score is 82. Your week is trending steady.",
|
||||
briefingLead: "Your week is trending steady.",
|
||||
lead: { text: "Your week is trending steady.", source: "briefing" },
|
||||
line: "Your week is trending steady.",
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
@@ -178,12 +185,16 @@ describe("<TodayHero>", () => {
|
||||
expect(html).toContain('data-slot="today-hero-lead"');
|
||||
});
|
||||
|
||||
it("promotes the top signal when score de-duplication removes the only lead", () => {
|
||||
it("does not repeat the top signal under a lead made from it", () => {
|
||||
// A briefing whose only sentence repeated the score leads with the top
|
||||
// signal's headline (resolved on the server); the muted signal line under
|
||||
// it would say the same thing twice.
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
briefingLead: "Your health score is 82.",
|
||||
line: "Your health score is 82.",
|
||||
briefingLead: null,
|
||||
lead: { text: "Pulse is settling lately", source: "briefing" },
|
||||
line: "Pulse is settling lately",
|
||||
topSignal: {
|
||||
sourceMetric: "pulse",
|
||||
tone: "info",
|
||||
@@ -208,6 +219,7 @@ describe("<TodayHero>", () => {
|
||||
sleepPending: true,
|
||||
score: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
reactionLine: null,
|
||||
line: "Your health score today is 82.",
|
||||
worthALook: [doseItem],
|
||||
@@ -228,6 +240,7 @@ describe("<TodayHero>", () => {
|
||||
score: null,
|
||||
topSignal: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
line: "Nothing needs your attention today — everything's tracking normally.",
|
||||
worthALook: [],
|
||||
})}
|
||||
@@ -246,6 +259,7 @@ describe("<TodayHero>", () => {
|
||||
score: null,
|
||||
topSignal: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
line: "Nothing needs your attention today — everything's tracking normally.",
|
||||
worthALook: [],
|
||||
reactionLine: null,
|
||||
@@ -273,7 +287,7 @@ describe("<TodayHero>", () => {
|
||||
expect(html).toContain('data-slot="today-hero-score"');
|
||||
});
|
||||
|
||||
it("shows the first-class all-clear line when a score is present but nothing is notable", () => {
|
||||
it("draws no empty rail and no all-clear sentence once a lead carries the day", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
@@ -282,16 +296,36 @@ describe("<TodayHero>", () => {
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('data-slot="today-hero"');
|
||||
expect(html).toContain('data-slot="today-hero-all-clear"');
|
||||
expect(html).toContain('data-slot="today-hero-lead"');
|
||||
expect(html).not.toContain('data-slot="today-hero-all-clear"');
|
||||
expect(html).not.toContain('data-slot="today-hero-rail"');
|
||||
});
|
||||
|
||||
it("keeps only the delta when the lead already says the headline", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
lead: {
|
||||
text: "Blood pressure a touch high this morning.",
|
||||
source: "briefing",
|
||||
},
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
const text = visibleText(html);
|
||||
expect(html).toContain('data-slot="today-hero-signal"');
|
||||
expect(text).toContain("+6 mmHg vs your 30-day average");
|
||||
// Said once, by the lead; the signal line carries only the delta.
|
||||
expect(text.split("touch high this morning").length - 1).toBe(1);
|
||||
});
|
||||
|
||||
it("uses the compact score-only composition when all-clear has no narrative", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
topSignal: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
reactionLine: null,
|
||||
line: "Your health score today is 82.",
|
||||
worthALook: [],
|
||||
@@ -379,6 +413,7 @@ describe("<TodayHero>", () => {
|
||||
score: null,
|
||||
topSignal: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
worthALook: [],
|
||||
})}
|
||||
primaryContent="reminders"
|
||||
@@ -446,3 +481,165 @@ describe("<TodayHero> score basis", () => {
|
||||
expect(html).not.toContain('data-slot="today-hero-score-basis"');
|
||||
});
|
||||
});
|
||||
|
||||
const FACTS: TodayFact[] = [
|
||||
{
|
||||
kind: "rest_mode",
|
||||
label: "Rest mode",
|
||||
value: "Day 3",
|
||||
href: "/illness",
|
||||
moduleKey: "illness",
|
||||
},
|
||||
{
|
||||
kind: "medications",
|
||||
label: "Medications",
|
||||
value: "1 of 3 taken",
|
||||
href: "/medications",
|
||||
moduleKey: "medications",
|
||||
},
|
||||
{
|
||||
kind: "appointment",
|
||||
label: "Appointment",
|
||||
value: "Tomorrow 09:30, Dr. Example",
|
||||
href: "/checkups",
|
||||
},
|
||||
{
|
||||
kind: "sleep",
|
||||
label: "Last night",
|
||||
value: "7h 20m, close to your usual",
|
||||
href: "/insights/sleep",
|
||||
moduleKey: "sleep",
|
||||
},
|
||||
{
|
||||
kind: "cycle",
|
||||
label: "Cycle",
|
||||
value: "Follicular, day 12",
|
||||
href: "/cycle",
|
||||
moduleKey: "cycle",
|
||||
},
|
||||
];
|
||||
|
||||
describe("<TodayHero> Today overview", () => {
|
||||
it("renders each fact as a link to its page, in the order it was given", () => {
|
||||
const html = render(<TodayHero digest={digest({ today: FACTS })} />);
|
||||
expect(html).toContain('data-slot="today-hero-today"');
|
||||
const kinds = [
|
||||
...html.matchAll(/data-slot="today-hero-fact" data-kind="([a-z_]+)"/g),
|
||||
].map((m) => m[1]);
|
||||
expect(kinds).toEqual([
|
||||
"rest_mode",
|
||||
"medications",
|
||||
"appointment",
|
||||
"sleep",
|
||||
"cycle",
|
||||
]);
|
||||
for (const fact of FACTS) {
|
||||
expect(html).toContain(`href="${fact.href}"`);
|
||||
expect(visibleText(html)).toContain(fact.value);
|
||||
}
|
||||
});
|
||||
|
||||
it("hides the fifth fact below md and never the first four", () => {
|
||||
const html = render(<TodayHero digest={digest({ today: FACTS })} />);
|
||||
const items = [
|
||||
...html.matchAll(/<li[^>]*data-slot="today-hero-fact"[^>]*>/g),
|
||||
].map((m) => m[0]);
|
||||
expect(items).toHaveLength(5);
|
||||
items.slice(0, 4).forEach((li) => expect(li).not.toContain("hidden"));
|
||||
expect(items[4]).toContain("hidden md:block");
|
||||
});
|
||||
|
||||
it("drops the all-clear sentence when facts carry the day", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({ today: FACTS.slice(0, 2), worthALook: [] })}
|
||||
/>,
|
||||
);
|
||||
expect(html).not.toContain('data-slot="today-hero-all-clear"');
|
||||
expect(html).toContain('data-layout="narrative"');
|
||||
});
|
||||
|
||||
it("keeps the hero for an account whose only content is facts", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
score: null,
|
||||
topSignal: null,
|
||||
briefingLead: null,
|
||||
lead: null,
|
||||
worthALook: [],
|
||||
today: FACTS.slice(1, 2),
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('data-slot="today-hero"');
|
||||
expect(html).toContain('data-slot="today-hero-today"');
|
||||
});
|
||||
|
||||
it("renders a deterministic lead without the AI signal line", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({
|
||||
lead: {
|
||||
text: "All 4 of your latest vitals sit inside their usual range.",
|
||||
source: "signal",
|
||||
},
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('data-source="signal"');
|
||||
expect(html).not.toContain('data-slot="today-hero-signal"');
|
||||
});
|
||||
|
||||
it("shows the facts in reminders mode, without the ring", () => {
|
||||
const html = render(
|
||||
<TodayHero
|
||||
digest={digest({ today: FACTS.slice(0, 2) })}
|
||||
primaryContent="reminders"
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('data-slot="today-hero-today"');
|
||||
expect(html).not.toContain('data-slot="today-hero-score"');
|
||||
});
|
||||
});
|
||||
|
||||
describe("<TodayHero> steady line", () => {
|
||||
const steady = (over: Partial<NonNullable<DailyDigest["score"]>>) =>
|
||||
digest({
|
||||
score: {
|
||||
value: 94,
|
||||
band: "green",
|
||||
delta: null,
|
||||
deltaReason: "below_noise_floor",
|
||||
scoreVersion: SCORE_VERSION,
|
||||
composition: ["BLOOD_PRESSURE", "ACTIVITY", "SLEEP"],
|
||||
steadyWeeks: 4,
|
||||
...over,
|
||||
},
|
||||
});
|
||||
|
||||
it("says how long the score has held when no delta is shown", () => {
|
||||
const html = render(<TodayHero digest={steady({})} />);
|
||||
expect(html).toContain('data-slot="today-hero-score-steady"');
|
||||
expect(visibleText(html)).toContain("Steady for 4 weeks");
|
||||
expect(html).not.toContain('data-slot="today-hero-score-delta"');
|
||||
});
|
||||
|
||||
it("never pairs a steady line with a delta", () => {
|
||||
const html = render(
|
||||
<TodayHero digest={steady({ delta: 3, deltaReason: null })} />,
|
||||
);
|
||||
expect(html).toContain('data-slot="today-hero-score-delta"');
|
||||
expect(html).not.toContain('data-slot="today-hero-score-steady"');
|
||||
});
|
||||
|
||||
it("says nothing without a run", () => {
|
||||
const html = render(<TodayHero digest={steady({ steadyWeeks: null })} />);
|
||||
expect(html).not.toContain('data-slot="today-hero-score-steady"');
|
||||
});
|
||||
|
||||
it("uses the German plural", () => {
|
||||
const html = render(<TodayHero digest={steady({})} />, "de");
|
||||
expect(visibleText(html)).toContain("Seit 4 Wochen stabil");
|
||||
});
|
||||
});
|
||||
@@ -54,6 +54,8 @@ import { usePriorityItemDismiss } from "@/hooks/use-priority-item-dismiss";
|
||||
import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { pluralKey } from "@/lib/i18n/plural";
|
||||
import { MAX_TODAY_FACTS_NARROW as TODAY_FACTS_NARROW } from "@/lib/daily/today-overview";
|
||||
import type { DailyDigest } from "@/lib/daily/digest";
|
||||
import type { HeroPrimaryContent } from "@/lib/dashboard-layout";
|
||||
import {
|
||||
@@ -72,26 +74,18 @@ function formatDelta(
|
||||
return t("daily.today.deltaVsBaseline", { delta: signed });
|
||||
}
|
||||
|
||||
/**
|
||||
* The ring already owns the headline number. AI briefing copy can still carry
|
||||
* an older lead sentence that repeats that exact score, so remove only the
|
||||
* sentence containing the displayed number and retain every other useful
|
||||
* sentence verbatim. If the score sentence was the whole lead, render no lead
|
||||
* rather than inventing replacement prose.
|
||||
*/
|
||||
function withoutRepeatedScore(
|
||||
text: string | null,
|
||||
score: number | null,
|
||||
): string | null {
|
||||
if (!text || score === null) return text;
|
||||
const shownScore = String(Math.round(score));
|
||||
const scorePattern = new RegExp(
|
||||
`(^|[^0-9])${shownScore.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\$&")}([^0-9]|$)`,
|
||||
);
|
||||
const sentences = text.match(/[^.!?]+[.!?]+(?:\s+|$)|[^.!?]+$/g) ?? [text];
|
||||
const retained = sentences.filter((sentence) => !scorePattern.test(sentence));
|
||||
const result = retained.join(" ").replace(/\s+/g, " ").trim();
|
||||
return result.length > 0 ? result : null;
|
||||
/** Lowercase letters and digits only, for a wording-insensitive compare. */
|
||||
function normalise(text: string): string {
|
||||
return text
|
||||
.toLowerCase()
|
||||
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/** Whether `lead` already says what `headline` says. */
|
||||
function restates(lead: string, headline: string): boolean {
|
||||
const h = normalise(headline);
|
||||
return h.length > 0 && normalise(lead).includes(h);
|
||||
}
|
||||
|
||||
export function TodayHero({
|
||||
@@ -104,7 +98,7 @@ export function TodayHero({
|
||||
/** Server-persisted hero choice from the dashboard layout blob. */
|
||||
primaryContent?: HeroPrimaryContent;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
const { t, locale } = useTranslations();
|
||||
// The hero is deliberately NOT mount-gated (v1.30.9: it is the LCP element
|
||||
// and paints from the server-dehydrated digest on both the SSR and the
|
||||
// hydration render), so nothing in it may differ between those two passes.
|
||||
@@ -138,35 +132,52 @@ export function TodayHero({
|
||||
|
||||
const hasScore = digest.score !== null;
|
||||
const hasItems = digest.worthALook.length > 0;
|
||||
// Lead precedence, warmest first: the day's reaction line REPLACES the
|
||||
// briefing lead once something landed — it never appends as a second
|
||||
// paragraph, so the hero stays exactly one lead line tall and nothing below
|
||||
// it shifts. The briefing lead is the standing read; the deterministic
|
||||
// `line` is the floor a keyless self-hoster still gets.
|
||||
const rawLead =
|
||||
digest.reactionLine ??
|
||||
digest.briefingLead ??
|
||||
// The deterministic line is a useful floor only once the ring has a real
|
||||
// score. A provisional/null ring must not pair with a fabricated score
|
||||
// sentence from that fallback.
|
||||
(hasScore ? digest.line : null);
|
||||
const lead = withoutRepeatedScore(rawLead, digest.score?.value ?? null);
|
||||
// `?? []` / `?? null` below: the service worker's offline data cache can
|
||||
// still hand back a digest written before the overview fields existed, and
|
||||
// a missing list must read as "no facts", not as a crash.
|
||||
const facts = digest.today ?? [];
|
||||
const hasFacts = facts.length > 0;
|
||||
// The lead is resolved on the server (`digest.lead`): the reaction line or
|
||||
// a briefing sentence with content while AI text is available, otherwise a
|
||||
// deterministic sentence about the day's strongest signal. Greetings and a
|
||||
// sentence that only repeats the ring's number never reach it, so the hero
|
||||
// renders it verbatim and decides nothing about it.
|
||||
const lead = digest.lead?.text ?? null;
|
||||
const topSignal = digest.topSignal;
|
||||
// A score-only briefing can legitimately lose its lead when the only
|
||||
// sentence repeated the number already printed inside the ring. Keep the
|
||||
// day's signal as the visible headline in that case instead of leaving the
|
||||
// hero with a muted, orphaned subtitle below an empty bold slot.
|
||||
const signalFallbackLead =
|
||||
hasScore && !lead ? topSignal?.headline?.trim() || null : null;
|
||||
const displayLead = lead ?? signalFallbackLead;
|
||||
// A score-only all-clear digest has no narrative content for the leading
|
||||
// column. Keeping the full md ring in that two-column shell left a blank
|
||||
// column beside a 168 px dial and pushed the actual all-clear read below it.
|
||||
// Treat that honest fallback as its own compact composition: the all-clear
|
||||
// copy occupies the leading column and a smaller version of the SAME score
|
||||
// ring remains the one numeric face. This branch depends only on the
|
||||
// server-delivered digest, so SSR and hydration choose it identically.
|
||||
const compactAllClear = !lead && !topSignal && !hasItems;
|
||||
// The briefing's top signal rides under an AI lead as its supporting line,
|
||||
// and only with what the lead does not already say: a headline the lead
|
||||
// restates is dropped and its delta, when there is one, stands alone.
|
||||
const signalLine =
|
||||
topSignal && lead && digest.lead?.source !== "signal"
|
||||
? restates(lead, topSignal.headline)
|
||||
? topSignal.delta
|
||||
? { headline: null, delta: topSignal.delta }
|
||||
: null
|
||||
: { headline: topSignal.headline, delta: topSignal.delta }
|
||||
: null;
|
||||
// A score-only digest with nothing else to say has no narrative content for
|
||||
// the leading column. Keeping the full md ring in that two-column shell left
|
||||
// a blank column beside a 168 px dial and pushed the all-clear read below
|
||||
// it, so that case keeps its compact composition: the all-clear copy leads
|
||||
// and a smaller version of the SAME score ring stays the one numeric face.
|
||||
// This branch depends only on the server-delivered digest, so SSR and
|
||||
// hydration choose it identically.
|
||||
const compactAllClear = !lead && !signalLine && !hasItems && !hasFacts;
|
||||
|
||||
// How long the number has held, read off the stored daily scores on the
|
||||
// server. Said only when no delta is: a moved score is described by its
|
||||
// delta, a still one by its duration, never both under one ring.
|
||||
const deltaShown =
|
||||
digest.score !== null &&
|
||||
digest.score.delta !== null &&
|
||||
digest.score.deltaReason === null;
|
||||
const steadyWeeks = digest.score?.steadyWeeks ?? null;
|
||||
const steadyLine =
|
||||
!deltaShown && steadyWeeks !== null
|
||||
? t(pluralKey("daily.today.steadyWeeks", steadyWeeks, locale), {
|
||||
count: steadyWeeks,
|
||||
})
|
||||
: null;
|
||||
|
||||
// v1.38 — what the ring's number rests on, when that is less than the
|
||||
// breadth the score recommends. The hero renders the number and nothing
|
||||
@@ -203,13 +214,7 @@ export function TodayHero({
|
||||
//
|
||||
// A filtered layout is the one explicit exception: its empty digest means
|
||||
// "the hidden canonical candidates are quiet here", so retain all-clear.
|
||||
if (
|
||||
!renderFilteredAllClear &&
|
||||
!hasScore &&
|
||||
!hasItems &&
|
||||
!digest.briefingLead &&
|
||||
!digest.reactionLine
|
||||
) {
|
||||
if (!renderFilteredAllClear && !hasScore && !hasItems && !hasFacts && !lead) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -252,6 +257,45 @@ export function TodayHero({
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
/* The Today overview — up to five statements about the day, resolved on the
|
||||
server in priority order. A phone shows the first four: the fifth is
|
||||
hidden below `md` rather than dropped, so the list a wide screen reads is
|
||||
the same list, one line longer. Each line opens the page it belongs to.
|
||||
The block never asks for anything; the rail below is the one place on the
|
||||
hero that may. */
|
||||
const todayBlock = hasFacts ? (
|
||||
<div className="space-y-2" data-slot="today-hero-today">
|
||||
<h2 className="text-muted-foreground text-xs font-medium tracking-wide uppercase">
|
||||
{t("daily.today.heading")}
|
||||
</h2>
|
||||
<ul className="flex flex-col md:grid md:grid-cols-2 md:gap-x-6 md:gap-y-3 xl:grid-cols-3">
|
||||
{facts.map((fact, i) => (
|
||||
<li
|
||||
key={fact.kind}
|
||||
data-slot="today-hero-fact"
|
||||
data-kind={fact.kind}
|
||||
className={cn(
|
||||
"min-w-0",
|
||||
i >= TODAY_FACTS_NARROW && "hidden md:block",
|
||||
)}
|
||||
>
|
||||
<Link
|
||||
href={fact.href}
|
||||
className="focus-visible:ring-ring/50 hover:bg-muted/50 -mx-1.5 flex items-baseline justify-between gap-3 rounded-md px-1.5 py-1 focus-visible:ring-2 focus-visible:outline-none md:flex-col md:items-start md:justify-start md:gap-0.5"
|
||||
>
|
||||
<span className="text-muted-foreground shrink-0 text-sm md:text-xs">
|
||||
{fact.label}
|
||||
</span>
|
||||
<span className="text-foreground min-w-0 text-right text-sm font-medium md:text-left">
|
||||
{fact.value}
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
const heroShellClassName = cn(
|
||||
// The tile strip's surface plus the ONE sanctioned Today atmosphere:
|
||||
// `.today-hero-wash` leans a faint `--primary` mix over the theme
|
||||
@@ -275,14 +319,16 @@ export function TodayHero({
|
||||
className={heroShellClassName}
|
||||
>
|
||||
<div className="flex flex-col gap-3 md:gap-4">
|
||||
{rail ?? (
|
||||
<p
|
||||
data-slot="today-hero-all-clear"
|
||||
className="text-muted-foreground text-sm"
|
||||
>
|
||||
{t("daily.today.allClear")}
|
||||
</p>
|
||||
)}
|
||||
{todayBlock}
|
||||
{rail ??
|
||||
(hasFacts ? null : (
|
||||
<p
|
||||
data-slot="today-hero-all-clear"
|
||||
className="text-muted-foreground text-sm"
|
||||
>
|
||||
{t("daily.today.allClear")}
|
||||
</p>
|
||||
))}
|
||||
{sleepPendingNote}
|
||||
</div>
|
||||
</section>
|
||||
@@ -312,33 +358,36 @@ export function TodayHero({
|
||||
: "flex-col md:flex-row md:items-start md:justify-between md:gap-6",
|
||||
)}
|
||||
>
|
||||
<div className="min-w-0 flex-1 space-y-2">
|
||||
<div className="min-w-0 flex-1 space-y-3">
|
||||
{/* Hero numeric face: the read leads large in the foreground
|
||||
token, calm and legible — the day's read, not a slogan. */}
|
||||
{displayLead ? (
|
||||
<div
|
||||
data-slot="today-hero-lead"
|
||||
className="text-foreground text-lg leading-snug font-semibold tracking-tight sm:text-xl"
|
||||
>
|
||||
<ProseBlocks text={displayLead} strip linkify={false} />
|
||||
{lead || signalLine ? (
|
||||
<div className="space-y-2">
|
||||
{lead ? (
|
||||
<div
|
||||
data-slot="today-hero-lead"
|
||||
data-source={digest.lead?.source}
|
||||
className="text-foreground text-lg leading-snug font-semibold tracking-tight sm:text-xl"
|
||||
>
|
||||
<ProseBlocks text={lead} strip linkify={false} />
|
||||
</div>
|
||||
) : null}
|
||||
{/* Top signal — present-tense headline + optional delta, one
|
||||
muted step down so it supports the lead without
|
||||
competing. */}
|
||||
{signalLine ? (
|
||||
<p
|
||||
data-slot="today-hero-signal"
|
||||
className="text-muted-foreground text-sm"
|
||||
>
|
||||
{signalLine.headline}
|
||||
{signalLine.headline && signalLine.delta ? " · " : null}
|
||||
{signalLine.delta}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{/* Top signal — present-tense headline + optional delta, one
|
||||
muted step down so it supports the lead without competing. */}
|
||||
{topSignal && lead ? (
|
||||
<p
|
||||
data-slot="today-hero-signal"
|
||||
className="text-muted-foreground text-sm"
|
||||
>
|
||||
{topSignal.headline}
|
||||
{topSignal.delta ? (
|
||||
<span className="text-muted-foreground">
|
||||
{" "}
|
||||
· {topSignal.delta}
|
||||
</span>
|
||||
) : null}
|
||||
</p>
|
||||
) : null}
|
||||
{todayBlock}
|
||||
{compactAllClear ? (
|
||||
<p
|
||||
data-slot="today-hero-all-clear"
|
||||
@@ -380,9 +429,7 @@ export function TodayHero({
|
||||
/>
|
||||
</Link>
|
||||
</div>
|
||||
{digest.score &&
|
||||
digest.score.delta !== null &&
|
||||
digest.score.deltaReason === null ? (
|
||||
{deltaShown && digest.score?.delta != null ? (
|
||||
<span
|
||||
data-slot="today-hero-score-delta"
|
||||
className="text-muted-foreground text-xs tabular-nums"
|
||||
@@ -390,6 +437,14 @@ export function TodayHero({
|
||||
{formatDelta(digest.score.delta, t)}
|
||||
</span>
|
||||
) : null}
|
||||
{steadyLine ? (
|
||||
<span
|
||||
data-slot="today-hero-score-steady"
|
||||
className="text-muted-foreground text-xs"
|
||||
>
|
||||
{steadyLine}
|
||||
</span>
|
||||
) : null}
|
||||
{basisLine ? (
|
||||
<span
|
||||
data-slot="today-hero-score-basis"
|
||||
@@ -411,8 +466,11 @@ export function TodayHero({
|
||||
{/* Worth-a-look rail — S1's `PriorityCard`s, bounded 0–3. When the
|
||||
digest is all-clear, a first-class muted line stands in for the
|
||||
rail (calm inversion of an alarm), never an empty card. */}
|
||||
{/* The all-clear sentence only ever stands in for an empty card
|
||||
(the compact composition above). Once a lead or facts carry the
|
||||
day, an empty rail simply is not drawn. */}
|
||||
{rail ??
|
||||
(!compactAllClear ? (
|
||||
(!compactAllClear && !hasFacts && !lead ? (
|
||||
<p
|
||||
data-slot="today-hero-all-clear"
|
||||
className="text-muted-foreground text-sm"
|
||||
|
||||
Reference in new issue
Block a user