mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 06:52:04 +00:00
The opt-in timeline module gets its page (#613). At 768 px and up the record's lanes (life, conditions, allergies, medications, vaccinations, doctor and procedures, labs, documents) are drawn in one SVG on a shared time axis, with a year, month or week grid, open periods ending in an arrow, a dashed lead-in where a start is unknown, dose marks and pauses on the medication they belong to, a Today line and a selection line. Up to three neutral value lines run below as monthly means, chosen in a menu. Recharts stays for every value chart; this surface is plain SVG like the heatmaps. All geometry is pure (timeline-geometry.ts): window, scale, row packing and label placement through one occupancy map, so no label overlaps another label or a bar, none runs past the card edge, and labels that do not fit are left out rather than squeezed. The width comes from a ResizeObserver, so a docked day panel re-runs the layout. The bar under the chart names the selected month's entries as chips, the month's means and "Open 3 Jan.", which puts ?day= in the URL for the day layer. The chart is one tab stop: arrows move the selection by a day, a month or a year with the zoom, Home and End jump to the ends, Enter opens the day. A visually hidden table lists every entry for screen readers. The legend says once that stacked means at the same time, not cause and effect. Below 768 px the timeline is a chronicle, newest first by month or year, with an Ongoing block for what has no meaningful start, rails beside the rows an episode or course spans, and empty stretches named as such. Switching the module on in Settings opens the readiness inventory: each lane carries, is thin or is empty, with one link per gap and the verdict as a count. The same inventory sits as a dismissible card on the timeline while a gap is open, and under Layers as "Data coverage". Life events are entered in a sheet (title, kind, a date to the day, month or year, an optional end, an optional note) from the timeline, the capture picker and the dashboard's add menu; one surface line maps the capture kind to the timeline module, and it is offered in one's own record only. Deleting asks first. Server routes are built in parallel; the e2e journey answers them with the contract's shapes. Copy in all seven locales; the timeline and lifeEvents release-pending prefixes are gone.
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
/**
|
|
* What the readiness inventory shows, decided once (v1.42, #613).
|
|
*
|
|
* The server decides each lane's status and the verdict; nothing here
|
|
* recounts. This module only orders the lanes for reading (what carries,
|
|
* then what is thin, then what is empty), flattens the gap links, and says
|
|
* when the dismissible card belongs on the timeline.
|
|
*/
|
|
import type {
|
|
TimelineReadinessLane,
|
|
TimelineReadinessResponse,
|
|
TimelineReadinessStatus,
|
|
} from "@/lib/day/contract";
|
|
|
|
const STATUS_RANK: Record<TimelineReadinessStatus, number> = {
|
|
carries: 0,
|
|
thin: 1,
|
|
empty: 2,
|
|
};
|
|
|
|
/** Lanes in reading order; the server's order is kept within one status. */
|
|
export function orderedReadinessLanes(
|
|
readiness: Pick<TimelineReadinessResponse, "lanes">,
|
|
): TimelineReadinessLane[] {
|
|
return readiness.lanes
|
|
.map((lane, index) => ({ lane, index }))
|
|
.sort(
|
|
(a, b) =>
|
|
STATUS_RANK[a.lane.status] - STATUS_RANK[b.lane.status] ||
|
|
a.index - b.index,
|
|
)
|
|
.map(({ lane }) => lane);
|
|
}
|
|
|
|
export interface ReadinessGap {
|
|
lane: TimelineReadinessLane["key"];
|
|
key: string;
|
|
count: number;
|
|
href: string;
|
|
}
|
|
|
|
/** Every gap with its one link, in the lanes' reading order. */
|
|
export function readinessGaps(
|
|
readiness: Pick<TimelineReadinessResponse, "lanes">,
|
|
): ReadinessGap[] {
|
|
return orderedReadinessLanes(readiness).flatMap((lane) =>
|
|
lane.gaps.map((gap) => ({ lane: lane.key, ...gap })),
|
|
);
|
|
}
|
|
|
|
/** How many lanes carry, out of how many are listed. */
|
|
export function readinessTally(
|
|
readiness: Pick<TimelineReadinessResponse, "lanes">,
|
|
): { carrying: number; total: number } {
|
|
return {
|
|
carrying: readiness.lanes.filter((l) => l.status === "carries").length,
|
|
total: readiness.lanes.length,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* The card belongs on the timeline while a lane is thin or empty and offers
|
|
* a way to close the gap, until the person closes the card.
|
|
*/
|
|
export function showReadinessCard(
|
|
readiness: Pick<TimelineReadinessResponse, "lanes"> | undefined,
|
|
dismissed: boolean,
|
|
): boolean {
|
|
if (!readiness || dismissed) return false;
|
|
return readiness.lanes.some(
|
|
(lane) => lane.status !== "carries" && lane.gaps.length > 0,
|
|
);
|
|
}
|
|
|
|
/** Storage key for the dismissed card; a per-viewer convenience only. */
|
|
export const READINESS_CARD_DISMISSED_KEY = "healthlog.timeline.readinessCard";
|