mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
Merge the day picker, Coach new-chat button, day panel on /coach and text cleanup into release/v1.42.0
This commit is contained in:
commit
1d080ee166
69 files changed
+2293
-2241
No files matched your search
@@ -0,0 +1,138 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import enMessages from "../../../../messages/en.json";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
|
||||
import {
|
||||
DayCalendar,
|
||||
DayDatePicker,
|
||||
keyToLocalDate,
|
||||
localDateToKey,
|
||||
monthWindow,
|
||||
pickedDay,
|
||||
} from "../day-date-picker";
|
||||
|
||||
/**
|
||||
* The day header's calendar: the date is the button that opens it, the month
|
||||
* marks the days that hold anything, nothing past today can be picked, and
|
||||
* "Today" goes to today. SSR, like the rest of the suite; the clicks
|
||||
* themselves run in `e2e/day-view.spec.ts`.
|
||||
*/
|
||||
|
||||
vi.mock("../use-day", () => ({
|
||||
useDayIndex: () => ({ data: undefined }),
|
||||
}));
|
||||
|
||||
function render(node: React.ReactNode) {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en" initialMessages={enMessages}>
|
||||
{node}
|
||||
</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
function calendar(
|
||||
props: Partial<Parameters<typeof DayCalendar>[0]> = {},
|
||||
): string {
|
||||
return render(
|
||||
<DayCalendar
|
||||
date="2026-09-24"
|
||||
today="2026-10-08"
|
||||
month={keyToLocalDate("2026-09-24")}
|
||||
onMonthChange={() => undefined}
|
||||
withEntries={["2026-09-03", "2026-09-24"]}
|
||||
onPick={() => undefined}
|
||||
{...props}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
function dayButton(html: string, key: string): string {
|
||||
return (
|
||||
html.match(new RegExp(`<button[^>]*data-date-key="${key}"[^>]*>`))?.[0] ??
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
describe("<DayDatePicker>", () => {
|
||||
it("makes the written date the button, with no icon beside it", () => {
|
||||
const html = render(
|
||||
<DayDatePicker
|
||||
date="2026-09-24"
|
||||
today="2026-10-08"
|
||||
label="Thursday, September 24, 2026"
|
||||
onPick={() => undefined}
|
||||
/>,
|
||||
);
|
||||
const button = html.match(/<button[^>]*data-slot="day-date-button"[^>]*>/);
|
||||
expect(button?.[0]).toContain('aria-haspopup="dialog"');
|
||||
expect(button?.[0]).toContain('aria-expanded="false"');
|
||||
expect(html).toContain("Thursday, September 24, 2026");
|
||||
expect(html).not.toContain("<svg");
|
||||
});
|
||||
});
|
||||
|
||||
describe("<DayCalendar>", () => {
|
||||
it("shows the month of the day on screen with that day selected", () => {
|
||||
const html = calendar();
|
||||
expect(html).toContain("September 2026");
|
||||
expect(dayButton(html, "2026-09-24")).toContain(
|
||||
'data-selected-single="true"',
|
||||
);
|
||||
});
|
||||
|
||||
it("marks the days that hold anything, and says so", () => {
|
||||
const html = calendar();
|
||||
expect(dayButton(html, "2026-09-03")).toContain('data-entries="true"');
|
||||
expect(dayButton(html, "2026-09-03")).toContain(
|
||||
'aria-label="Thursday, September 3, 2026, has entries"',
|
||||
);
|
||||
expect(dayButton(html, "2026-09-04")).not.toContain("data-entries");
|
||||
});
|
||||
|
||||
it("offers nothing past today", () => {
|
||||
const html = calendar({
|
||||
date: "2026-10-01",
|
||||
month: keyToLocalDate("2026-10-01"),
|
||||
});
|
||||
expect(dayButton(html, "2026-10-08")).not.toMatch(/\sdisabled=""/);
|
||||
expect(dayButton(html, "2026-10-09")).toMatch(/\sdisabled=""/);
|
||||
});
|
||||
|
||||
it("offers Today, except on today", () => {
|
||||
const today = (html: string) =>
|
||||
html.match(/<button[^>]*data-slot="day-date-today"[^>]*>Today/)?.[0];
|
||||
expect(today(calendar())).not.toMatch(/\sdisabled=""/);
|
||||
expect(
|
||||
today(
|
||||
calendar({ date: "2026-10-08", month: keyToLocalDate("2026-10-08") }),
|
||||
),
|
||||
).toMatch(/\sdisabled=""/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("picking a day", () => {
|
||||
it("opens a past day or today, never the open day or a future one", () => {
|
||||
expect(pickedDay("2026-09-03", "2026-09-24", "2026-10-08")).toBe(
|
||||
"2026-09-03",
|
||||
);
|
||||
expect(pickedDay("2026-10-08", "2026-09-24", "2026-10-08")).toBe(
|
||||
"2026-10-08",
|
||||
);
|
||||
expect(pickedDay("2026-09-24", "2026-09-24", "2026-10-08")).toBeNull();
|
||||
expect(pickedDay("2026-10-09", "2026-09-24", "2026-10-08")).toBeNull();
|
||||
});
|
||||
|
||||
it("reads the month it shows, and never past today", () => {
|
||||
expect(monthWindow(keyToLocalDate("2026-09-24"), "2026-10-08")).toEqual({
|
||||
from: "2026-09-01",
|
||||
to: "2026-09-30",
|
||||
});
|
||||
expect(monthWindow(keyToLocalDate("2026-10-02"), "2026-10-08")).toEqual({
|
||||
from: "2026-10-01",
|
||||
to: "2026-10-08",
|
||||
});
|
||||
expect(localDateToKey(keyToLocalDate("2024-02-29"))).toBe("2024-02-29");
|
||||
});
|
||||
});
|
||||
@@ -110,6 +110,7 @@ let canWrite = true;
|
||||
vi.mock("../use-day", () => ({
|
||||
useDay: () => ({ ...dayQuery, refetch: () => undefined }),
|
||||
usePrefetchDay: () => () => undefined,
|
||||
useDayIndex: () => ({ data: undefined }),
|
||||
}));
|
||||
vi.mock("next/navigation", () => ({ usePathname: () => pathname }));
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
@@ -161,6 +162,7 @@ async function render(
|
||||
shell={props.shell ?? "docked"}
|
||||
onClose={() => undefined}
|
||||
onStep={() => undefined}
|
||||
onPick={() => undefined}
|
||||
Title={(p) => <h2 {...p} />}
|
||||
titleId="t"
|
||||
/>
|
||||
@@ -180,15 +182,19 @@ describe("<DayView>", () => {
|
||||
it("names the day and counts what it holds", async () => {
|
||||
const html = await render();
|
||||
expect(html).toContain("Saturday, January 3, 2026");
|
||||
expect(html).toContain("3 values · 2 entries");
|
||||
expect(html).toContain("3 values, 2 entries");
|
||||
});
|
||||
|
||||
it("lists what ran through the day with its running count", async () => {
|
||||
const html = await render();
|
||||
expect(html).toContain("Running that day");
|
||||
expect(html).toContain("Common cold");
|
||||
expect(html).toContain("Day 4 · since");
|
||||
expect(html).toContain("Winter course · Day 64 of 151");
|
||||
// Name first, the quiet day count below; an open span names its start
|
||||
// as a date, its year left out when it is the viewed day's year.
|
||||
expect(html).toContain("Day 4, since December 31");
|
||||
expect(html).toContain("Vitamin D 1,000 IU Winter course");
|
||||
expect(html).toContain("Day 64 of 151");
|
||||
expect(html).not.toContain("ongoing");
|
||||
expect(html).toContain('href="/illness/ep1"');
|
||||
});
|
||||
|
||||
@@ -227,10 +233,11 @@ describe("<DayView>", () => {
|
||||
const html = await render();
|
||||
const rows = html.split('data-slot="day-running-item"').slice(1);
|
||||
const med = rows.find((row) => row.includes("Levothyroxine")) ?? "";
|
||||
expect(med).toContain("50 µg");
|
||||
expect(med).toContain("Levothyroxine 50 µg");
|
||||
expect(med.split("</li>")[0]).not.toMatch(/Day \d|since/);
|
||||
const leave = rows.find((row) => row.includes("Parental leave")) ?? "";
|
||||
expect(leave).toContain("Family · Day 34 of 90");
|
||||
expect(leave).toMatch(/data-slot="tag-chip"[^>]*>Family</);
|
||||
expect(leave).toContain("Day 34 of 90");
|
||||
expect(leave).not.toContain("FAMILY");
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Calendar, CalendarDayButton } from "@/components/ui/calendar";
|
||||
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
|
||||
import { resolveDateFnsLocale } from "@/components/ui/date-field";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import type { DateKey } from "@/lib/day/contract";
|
||||
import { resolveIntlLocale } from "@/lib/format-locale";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { useDayIndex } from "./use-day";
|
||||
|
||||
/**
|
||||
* The date in the day's header, as the way to any other day: the written
|
||||
* date is the button, and it opens a month calendar beside it. Picking a
|
||||
* day opens that day; "Today" opens today. Days that hold anything carry a
|
||||
* dot, read from `GET /api/day/index` for the month on screen.
|
||||
*
|
||||
* No icon and no field: the header keeps its one line, and the arrows
|
||||
* beside it stay the way to the neighbouring days. Radix owns the keyboard
|
||||
* (Enter or Space opens, Escape closes, focus returns to the date). A
|
||||
* popover beside the date serves the docked column and the side sheet; in
|
||||
* the phone's bottom sheet the calendar rises as a sheet of its own, with
|
||||
* touch-sized cells wherever the pointer is coarse.
|
||||
*/
|
||||
|
||||
/** `YYYY-MM-DD` → a local `Date` at midnight, the calendar's own unit. */
|
||||
export function keyToLocalDate(key: DateKey): Date {
|
||||
const [y, m, d] = key.split("-").map(Number) as [number, number, number];
|
||||
return new Date(y, m - 1, d);
|
||||
}
|
||||
|
||||
/** A local `Date` → `YYYY-MM-DD`, read in the zone it was made in. */
|
||||
export function localDateToKey(date: Date): DateKey {
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(
|
||||
date.getDate(),
|
||||
)}` as DateKey;
|
||||
}
|
||||
|
||||
/** First and last day of the month that holds `month`, never past today. */
|
||||
export function monthWindow(
|
||||
month: Date,
|
||||
today: DateKey,
|
||||
): { from: DateKey; to: DateKey } {
|
||||
const from = localDateToKey(
|
||||
new Date(month.getFullYear(), month.getMonth(), 1),
|
||||
);
|
||||
const last = localDateToKey(
|
||||
new Date(month.getFullYear(), month.getMonth() + 1, 0),
|
||||
);
|
||||
return { from, to: last > today ? today : last };
|
||||
}
|
||||
|
||||
/**
|
||||
* What a pick opens: the day itself, unless it is the day on screen already
|
||||
* or lies past today (the calendar disables those, this is the backstop).
|
||||
*/
|
||||
export function pickedDay(
|
||||
next: DateKey,
|
||||
date: DateKey,
|
||||
today: DateKey,
|
||||
): DateKey | null {
|
||||
return next !== date && next <= today ? next : null;
|
||||
}
|
||||
|
||||
export function DayDatePicker({
|
||||
date,
|
||||
today,
|
||||
label,
|
||||
onPick,
|
||||
variant = "popover",
|
||||
className,
|
||||
}: {
|
||||
date: DateKey;
|
||||
today: DateKey;
|
||||
/** The date as the header writes it: the button's text. */
|
||||
label: React.ReactNode;
|
||||
onPick: (date: DateKey) => void;
|
||||
/**
|
||||
* `sheet` in the phone's bottom sheet: a month of finger-sized cells
|
||||
* does not fit beside a header that sits halfway down the screen, so the
|
||||
* calendar rises as its own bottom sheet there.
|
||||
*/
|
||||
variant?: "popover" | "sheet";
|
||||
className?: string;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
const [open, setOpen] = useState(false);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const [month, setMonth] = useState(() => keyToLocalDate(date));
|
||||
const range = monthWindow(month, today);
|
||||
const index = useDayIndex(range.from, range.to, open);
|
||||
|
||||
const onOpenChange = (next: boolean) => {
|
||||
// Each opening starts on the month of the day on screen.
|
||||
if (next) setMonth(keyToLocalDate(date));
|
||||
setOpen(next);
|
||||
};
|
||||
const buttonClass = cn(
|
||||
"hover:bg-muted/60 focus-visible:ring-ring/50 data-[state=open]:bg-muted/60 -mx-1 block max-w-full truncate rounded-md px-1 text-left transition-colors focus-visible:ring-[3px] focus-visible:outline-none",
|
||||
className,
|
||||
);
|
||||
const calendar = (
|
||||
<DayCalendar
|
||||
date={date}
|
||||
today={today}
|
||||
month={month}
|
||||
onMonthChange={setMonth}
|
||||
withEntries={Object.keys(index.data?.days ?? {}) as DateKey[]}
|
||||
onPick={(next) => {
|
||||
setOpen(false);
|
||||
const day = pickedDay(next, date, today);
|
||||
if (day !== null) onPick(day);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
if (variant === "sheet") {
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
ref={buttonRef}
|
||||
type="button"
|
||||
data-slot="day-date-button"
|
||||
data-state={open ? "open" : "closed"}
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={open}
|
||||
title={t("day.pickDate")}
|
||||
onClick={() => onOpenChange(true)}
|
||||
className={buttonClass}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
<ResponsiveSheet
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title={t("day.pickerTitle")}
|
||||
hideHeader
|
||||
showCloseButton={false}
|
||||
bodyClassName="items-center p-2"
|
||||
// Back to the date, inside the day's own sheet.
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
buttonRef.current?.focus({ preventScroll: true });
|
||||
}}
|
||||
>
|
||||
<div data-slot="day-date-picker" className="w-fit">
|
||||
{calendar}
|
||||
</div>
|
||||
</ResponsiveSheet>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={onOpenChange}>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
data-slot="day-date-button"
|
||||
aria-haspopup="dialog"
|
||||
title={t("day.pickDate")}
|
||||
className={buttonClass}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
align="start"
|
||||
data-slot="day-date-picker"
|
||||
aria-label={t("day.pickerTitle")}
|
||||
className="w-auto p-0"
|
||||
>
|
||||
{calendar}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
/** The calendar's day button, with its date key and dot as attributes. */
|
||||
function KeyedDayButton(props: React.ComponentProps<typeof CalendarDayButton>) {
|
||||
return (
|
||||
<CalendarDayButton
|
||||
{...props}
|
||||
data-date-key={localDateToKey(props.day.date)}
|
||||
data-entries={props.modifiers.entries ? "true" : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The popover's body: the month with the day on screen selected, a dot on
|
||||
* every day that holds anything, nothing past today, and "Today" below.
|
||||
*/
|
||||
export function DayCalendar({
|
||||
date,
|
||||
today,
|
||||
month,
|
||||
onMonthChange,
|
||||
withEntries,
|
||||
onPick,
|
||||
}: {
|
||||
date: DateKey;
|
||||
today: DateKey;
|
||||
month: Date;
|
||||
onMonthChange: (month: Date) => void;
|
||||
withEntries: readonly DateKey[];
|
||||
onPick: (date: DateKey) => void;
|
||||
}) {
|
||||
const { t, locale } = useTranslations();
|
||||
const todayDate = keyToLocalDate(today);
|
||||
const dateLabel = new Intl.DateTimeFormat(resolveIntlLocale(locale), {
|
||||
weekday: "long",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
// The calendar hands out local midnights; the label reads the same
|
||||
// calendar day at noon UTC, so no zone can move it.
|
||||
const labelOf = (day: Date) =>
|
||||
dateLabel.format(new Date(`${localDateToKey(day)}T12:00:00.000Z`));
|
||||
return (
|
||||
<>
|
||||
<Calendar
|
||||
mode="single"
|
||||
required
|
||||
selected={keyToLocalDate(date)}
|
||||
onSelect={(picked) => {
|
||||
if (picked) onPick(localDateToKey(picked));
|
||||
}}
|
||||
month={month}
|
||||
onMonthChange={onMonthChange}
|
||||
endMonth={todayDate}
|
||||
disabled={{ after: todayDate }}
|
||||
showOutsideDays={false}
|
||||
locale={resolveDateFnsLocale(locale)}
|
||||
modifiers={{ entries: withEntries.map(keyToLocalDate) }}
|
||||
modifiersClassNames={{
|
||||
// A dot under the number; the selected day's dot takes the
|
||||
// colour of the number on it.
|
||||
entries:
|
||||
"after:bg-primary data-[selected=true]:after:bg-primary-foreground after:pointer-events-none after:absolute after:bottom-1 after:left-1/2 after:size-1 after:-translate-x-1/2 after:rounded-full",
|
||||
}}
|
||||
labels={{
|
||||
labelDayButton: (day, modifiers) =>
|
||||
modifiers.entries
|
||||
? `${labelOf(day)}, ${t("day.hasEntries")}`
|
||||
: labelOf(day),
|
||||
}}
|
||||
components={{ DayButton: KeyedDayButton }}
|
||||
// 32 px cells beside a fine pointer, 40 px for a finger.
|
||||
className="[--cell-size:--spacing(10)] pointer-fine:[--cell-size:--spacing(8)]"
|
||||
autoFocus
|
||||
/>
|
||||
<div className="border-border flex justify-end border-t p-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
data-slot="day-date-today"
|
||||
disabled={date === today}
|
||||
onClick={() => onPick(today)}
|
||||
>
|
||||
{t("day.today")}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -158,6 +158,15 @@ export function openDay(date: DateKey, options: OpenDayOptions = {}): void {
|
||||
/** Move the open day by `delta` calendar days, without a new history entry. */
|
||||
export function stepDay(from: DateKey, delta: number): DateKey {
|
||||
const next = shiftDateKey(from, delta);
|
||||
jumpDay(next);
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the open day for `next` (a day picked from the header's calendar),
|
||||
* the way a step does: no new history entry, so one Back still leaves.
|
||||
*/
|
||||
export function jumpDay(next: DateKey): void {
|
||||
memory.focus = null;
|
||||
emit();
|
||||
const { pathname, search } = currentLocation();
|
||||
@@ -169,7 +178,27 @@ export function stepDay(from: DateKey, delta: number): DateKey {
|
||||
"",
|
||||
withDayHref(pathname, search, next),
|
||||
);
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set while the docked day collapses to make room for another panel (the
|
||||
* Coach's conversations below 1600 px): focus then stays with the control
|
||||
* that asked for the room instead of moving to the day's edge.
|
||||
*/
|
||||
let yielding = false;
|
||||
|
||||
/** Collapse the docked day to its edge for a neighbouring panel. */
|
||||
export function yieldDay(): void {
|
||||
yielding = true;
|
||||
memory.trigger = null;
|
||||
closeDay();
|
||||
}
|
||||
|
||||
/** Read and clear the flag `yieldDay` set. */
|
||||
export function takeDayYield(): boolean {
|
||||
const was = yielding;
|
||||
yielding = false;
|
||||
return was;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import {
|
||||
Suspense,
|
||||
useCallback,
|
||||
@@ -37,11 +37,13 @@ import { cn } from "@/lib/utils";
|
||||
|
||||
import {
|
||||
closeDay,
|
||||
jumpDay,
|
||||
openDay,
|
||||
peekDayTriggerAt,
|
||||
publishOpenDay,
|
||||
stepDay,
|
||||
takeDayTrigger,
|
||||
takeDayYield,
|
||||
useDayFocus,
|
||||
} from "./day-layer-controller";
|
||||
import { parseDayParam, shiftDateKey, withDayHref } from "./day-url";
|
||||
@@ -72,8 +74,10 @@ import { useTodayKey } from "./use-today-key";
|
||||
* the chart stays in view above it; dragging the handle up (or tapping
|
||||
* it) takes it to full height, dragging it down closes it.
|
||||
*
|
||||
* On `/coach` the conversations panel already holds the side column, and
|
||||
* there is never more than one docked panel: the day opens as a sheet there.
|
||||
* On `/coach` the day docks too, right of the Coach's conversations: page,
|
||||
* conversations, day. Below 1600 px only one of the two is open at a time;
|
||||
* opening the day folds the conversations to their edge, and opening the
|
||||
* conversations folds the day to its edge (`yieldDay`).
|
||||
*
|
||||
* The parameter is the state. A date that is not a calendar date, or lies in
|
||||
* the future, is removed from the URL without a word. Collapsing the docked
|
||||
@@ -121,7 +125,6 @@ function modalSurfaceOpen(): boolean {
|
||||
|
||||
function DayLayer() {
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const today = useTodayKey();
|
||||
const raw = searchParams.get(DAY_QUERY_PARAM);
|
||||
const date = parseDayParam(raw, today);
|
||||
@@ -157,7 +160,7 @@ function DayLayer() {
|
||||
const phone = useIsMobile();
|
||||
const shell: "docked" | "sheet" | "bottom" = phone
|
||||
? "bottom"
|
||||
: wide && !pathname.startsWith("/coach")
|
||||
: wide
|
||||
? "docked"
|
||||
: "sheet";
|
||||
|
||||
@@ -206,6 +209,11 @@ function DayLayer() {
|
||||
return;
|
||||
}
|
||||
if (before !== null && shell === "docked") {
|
||||
// Collapsed for a neighbouring panel: focus stays where it was.
|
||||
if (takeDayYield()) {
|
||||
collapsing.current = false;
|
||||
return;
|
||||
}
|
||||
const rail = expandRef.current;
|
||||
if (collapsing.current && rail) {
|
||||
takeDayTrigger();
|
||||
@@ -226,6 +234,14 @@ function DayLayer() {
|
||||
[date, today],
|
||||
);
|
||||
|
||||
const onPick = useCallback(
|
||||
(next: DateKey) => {
|
||||
if (next > today) return;
|
||||
jumpDay(next);
|
||||
},
|
||||
[today],
|
||||
);
|
||||
|
||||
// Keyboard: Escape closes the docked column (a sheet's own Escape is the
|
||||
// dialog's), Alt with an arrow steps a day. Bare arrows stay with scrolling.
|
||||
useEffect(() => {
|
||||
@@ -285,7 +301,7 @@ function DayLayer() {
|
||||
<div
|
||||
data-slot="day-rail"
|
||||
data-day={railDay}
|
||||
className="bg-card text-card-foreground border-border flex h-full w-12 shrink-0 flex-col border-l"
|
||||
className="bg-card text-card-foreground border-border order-2 flex h-full w-12 shrink-0 flex-col border-l"
|
||||
>
|
||||
{/* The top bar's band, so the two bottom borders draw one line;
|
||||
the control sits where the open day keeps its own. */}
|
||||
@@ -343,6 +359,7 @@ function DayLayer() {
|
||||
shell={shell}
|
||||
onClose={shell === "docked" ? collapse : closeDay}
|
||||
onStep={onStep}
|
||||
onPick={onPick}
|
||||
Title={Title}
|
||||
titleId={titleId}
|
||||
titleRef={titleRef}
|
||||
@@ -363,7 +380,7 @@ function DayLayer() {
|
||||
// A short fade, not a slide: the column takes its width at once
|
||||
// (the page beside it reflows in the same frame either way), so
|
||||
// only its content eases in. None under reduced motion.
|
||||
className="bg-card text-card-foreground border-border motion-safe:animate-in motion-safe:fade-in-0 flex h-full w-105 shrink-0 flex-col border-l motion-safe:duration-150"
|
||||
className="bg-card text-card-foreground border-border motion-safe:animate-in motion-safe:fade-in-0 order-2 flex h-full w-105 shrink-0 flex-col border-l motion-safe:duration-150"
|
||||
>
|
||||
{view(DockedTitle, {
|
||||
// No status-bar inset here: the docked column sits inside
|
||||
|
||||
@@ -23,7 +23,9 @@ import {
|
||||
type LucideIcon,
|
||||
} from "lucide-react";
|
||||
|
||||
import { TagChip } from "@/components/ui/tag-chip";
|
||||
import {
|
||||
type DateKey,
|
||||
type DayEvent,
|
||||
type DayEventKind,
|
||||
type DayNotable,
|
||||
@@ -37,6 +39,7 @@ import {
|
||||
LIFE_EVENT_CATEGORY_KEY,
|
||||
keyOf,
|
||||
} from "@/components/timeline/label-keys";
|
||||
import { resolveIntlLocale } from "@/lib/format-locale";
|
||||
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
||||
import { MOOD_LABEL_KEYS } from "@/lib/mood/labels";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -154,7 +157,7 @@ export function DayNotableLines({
|
||||
<Sparkles className="mt-px size-3.5 shrink-0" aria-hidden="true" />
|
||||
<span>
|
||||
{withMetric && notable.type
|
||||
? `${labelFor(tileKeyOf(notable.type))} · `
|
||||
? `${labelFor(tileKeyOf(notable.type))}: `
|
||||
: null}
|
||||
{text(notable)}
|
||||
</span>
|
||||
@@ -289,33 +292,60 @@ export function dayMeta(
|
||||
}
|
||||
}
|
||||
|
||||
export function DayRunning({ items }: { items: readonly DayRunningItem[] }) {
|
||||
const { t } = useTranslations();
|
||||
const fmt = useFormatters();
|
||||
/** Running kinds whose `sub` is a dose and reads as part of the name. */
|
||||
const DOSE_SUB_KINDS: ReadonlySet<DayRunningKind> = new Set([
|
||||
"medication",
|
||||
"medicationCourse",
|
||||
]);
|
||||
|
||||
export function DayRunning({
|
||||
items,
|
||||
date,
|
||||
}: {
|
||||
items: readonly DayRunningItem[];
|
||||
/** The viewed day; a start date in another year names its year. */
|
||||
date: DateKey;
|
||||
}) {
|
||||
const { t, locale } = useTranslations();
|
||||
if (items.length === 0) return null;
|
||||
const viewedYear = date.slice(0, 4);
|
||||
const intlLocale = resolveIntlLocale(locale);
|
||||
const sinceText = (since: string): string =>
|
||||
new Intl.DateTimeFormat(intlLocale, {
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
...(since.slice(0, 4) === viewedYear ? {} : { year: "numeric" }),
|
||||
timeZone: "UTC",
|
||||
}).format(new Date(`${since}T12:00:00.000Z`));
|
||||
return (
|
||||
<section className="space-y-2" data-slot="day-running">
|
||||
<h3 className={DAY_SECTION_LABEL}>{t("day.groups.running")}</h3>
|
||||
<ul>
|
||||
{items.map((item) => {
|
||||
const cycleLine = cycleRunningLine(item, t);
|
||||
const parts = (
|
||||
const title = dayTitle(item.kind, item.title, t);
|
||||
const doseInName = item.sub !== null && DOSE_SUB_KINDS.has(item.kind);
|
||||
const name = doseInName ? `${title} ${item.sub}` : title;
|
||||
const chip =
|
||||
cycleLine === null && item.sub !== null && !doseInName
|
||||
? dayMeta(item.kind, item.sub, t)
|
||||
: null;
|
||||
const since =
|
||||
item.dayCount === null && item.since !== null
|
||||
? sinceText(item.since)
|
||||
: null;
|
||||
const detail =
|
||||
cycleLine !== null
|
||||
? [cycleLine]
|
||||
: [
|
||||
item.sub === null ? null : dayMeta(item.kind, item.sub, t),
|
||||
item.dayIndex !== null
|
||||
? item.dayCount !== null
|
||||
? t("day.dayOf", { n: item.dayIndex, m: item.dayCount })
|
||||
: t("day.dayN", { n: item.dayIndex })
|
||||
: null,
|
||||
item.dayCount === null && item.since !== null
|
||||
? t("day.since", {
|
||||
date: fmt.dateShortSmartCalendar(item.since),
|
||||
})
|
||||
: null,
|
||||
]
|
||||
).filter((part): part is string => !!part);
|
||||
? cycleLine
|
||||
: item.dayIndex !== null
|
||||
? item.dayCount !== null
|
||||
? t("day.dayOf", { n: item.dayIndex, m: item.dayCount })
|
||||
: since !== null
|
||||
? t("day.dayNSince", { n: item.dayIndex, date: since })
|
||||
: t("day.dayN", { n: item.dayIndex })
|
||||
: since !== null
|
||||
? t("day.sinceDate", { date: since })
|
||||
: null;
|
||||
const body = (
|
||||
<>
|
||||
<span
|
||||
@@ -324,12 +354,17 @@ export function DayRunning({ items }: { items: readonly DayRunningItem[] }) {
|
||||
style={{ backgroundColor: RUNNING_COLOR[item.kind] }}
|
||||
/>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium">
|
||||
{dayTitle(item.kind, item.title, t)}
|
||||
</span>
|
||||
<span className="text-muted-foreground block truncate text-xs">
|
||||
{parts.join(" · ")}
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<span className="min-w-0 truncate text-sm font-medium">
|
||||
{name}
|
||||
</span>
|
||||
{chip ? <TagChip className="shrink-0">{chip}</TagChip> : null}
|
||||
</span>
|
||||
{detail ? (
|
||||
<span className="text-muted-foreground block truncate text-xs">
|
||||
{detail}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
{item.href ? (
|
||||
<ChevronRight
|
||||
|
||||
@@ -30,6 +30,7 @@ import { resolveIntlLocale } from "@/lib/format-locale";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { DayDatePicker } from "./day-date-picker";
|
||||
import type { DayFocus } from "./day-layer-controller";
|
||||
import {
|
||||
DayEvents,
|
||||
@@ -77,6 +78,8 @@ export interface DayViewProps {
|
||||
shell: "docked" | "sheet" | "bottom";
|
||||
onClose: () => void;
|
||||
onStep: (delta: number) => void;
|
||||
/** Open another day, picked from the header's calendar. */
|
||||
onPick: (date: DateKey) => void;
|
||||
/** The heading element: an `h2`, or the sheet primitive's title. */
|
||||
Title: ComponentType<{
|
||||
id?: string;
|
||||
@@ -114,6 +117,7 @@ export function DayView({
|
||||
shell,
|
||||
onClose,
|
||||
onStep,
|
||||
onPick,
|
||||
Title,
|
||||
titleId,
|
||||
titleRef,
|
||||
@@ -178,7 +182,7 @@ export function DayView({
|
||||
? [
|
||||
tCount("day.countValues", data.counts.values),
|
||||
tCount("day.countEntries", data.counts.entries),
|
||||
].join(" · ")
|
||||
].join(", ")
|
||||
: null;
|
||||
const compact = shell === "bottom";
|
||||
const closeLabel = shell === "docked" ? t("day.hidePanel") : t("day.close");
|
||||
@@ -230,14 +234,24 @@ export function DayView({
|
||||
tabIndex={-1}
|
||||
className="min-w-0 flex-1 truncate px-1 text-base leading-snug font-semibold focus-visible:outline-none"
|
||||
>
|
||||
{compact ? (
|
||||
<>
|
||||
<span aria-hidden="true">{shortLabel(date)}</span>
|
||||
<span className="sr-only">{longLabel(date)}</span>
|
||||
</>
|
||||
) : (
|
||||
longLabel(date)
|
||||
)}
|
||||
{/* The date is the way to any other day: a calendar opens from
|
||||
it, so the header needs no icon of its own. */}
|
||||
<DayDatePicker
|
||||
date={date}
|
||||
today={today}
|
||||
onPick={onPick}
|
||||
variant={compact ? "sheet" : "popover"}
|
||||
label={
|
||||
compact ? (
|
||||
<>
|
||||
<span aria-hidden="true">{shortLabel(date)}</span>
|
||||
<span className="sr-only">{longLabel(date)}</span>
|
||||
</>
|
||||
) : (
|
||||
longLabel(date)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</Title>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -291,7 +305,7 @@ export function DayView({
|
||||
className="text-muted-foreground -mb-3 text-xs tabular-nums"
|
||||
data-slot="day-meta"
|
||||
>
|
||||
{meta ?? <span className="invisible">·</span>}
|
||||
{meta ?? <span className="invisible">0</span>}
|
||||
</p>
|
||||
{focus ? (
|
||||
<div className="space-y-2.5">
|
||||
@@ -321,7 +335,7 @@ export function DayView({
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<DayRunning items={data.running} />
|
||||
<DayRunning items={data.running} date={date} />
|
||||
{data.values.length > 0 ? (
|
||||
<div className="space-y-2.5">
|
||||
<DayValues values={data.values} focusTypes={focusTypes} />
|
||||
|
||||
Reference in new issue
Block a user