fix(sleep): the hypnogram keeps its timeline when a summary writer joins the night

A writer whose stage rows all share one timestamp carries night totals,
not segments — reconstructing them as segments paints every stage
flush against the night's right edge. The session picker now prefers a
writer with genuinely timed rows among the granular candidates, so a
stage summary backfilled for a night an actually-timed writer also
recorded no longer evicts the real timeline; summary-only nights still
resolve. The hypnogram itself degrades a summary-shaped session to the
stage breakdown instead of drawing the false skyline.
This commit is contained in:
Marc-André Bombeck committed 2026-06-12 20:30:59 +02:00
1 parent 4493eb2cac
commit 5859072561
3 files changed
+89 -6

No files matched your search

+9 -1
View File
@@ -209,7 +209,15 @@ export function SleepHypnogram({ session }: SleepHypnogramProps) {
// need any positive per-stage minutes. A legacy stage-summary night (no
// segment spans) still shows its breakdown rather than collapsing the
// whole card. "Unavailable" is reserved for a truly empty session.
const hasTrack = spans.length > 0;
// Spans must also carry more than one distinct end instant: a summary-
// shaped writer (per-stage night totals all stamped on the sleep end)
// reconstructs into bars that all touch the night's right edge — that
// is a breakdown wearing a timeline costume, so paint it as the
// breakdown footer instead.
const hasTrack =
spans.length > 0 &&
(spans.length === 1 ||
new Set(spans.map((s) => s.x2)).size > 1);
const hasBreakdown = breakdown.length > 0;
return (