feat(nav): add the center capture action and More hub, move unit preference into the profile

Reshape the mobile bottom bar to the five-slot shape the native client
uses: Home · Meds · Log · Insights · More. The center "Log" slot is a
capture action rather than a destination — it opens a picker that routes
to the existing measurement, medication-intake and mood quick-entry
sheets (those forms already share a mount contract, so the picker reuses
them verbatim). Expand the former overflow into a real "More" hub that
holds the rest of the top-level destinations: Measurements, Mood,
Workouts, Achievements, Notifications and Settings.

The change is additive — Measurements and Mood leave the always-visible
strip but stay reachable through the More hub and the capture picker, so
nothing loses its route. On desktop the sidebar still lists every
destination.

Move the metric/imperial unit system from its standalone card into a
dropdown in the Profile form beside the timezone picker — it is a
display preference like language and timezone. Persistence is unchanged:
the dropdown PATCHes /api/auth/me/unit-preference on change and
invalidates the same query keys, so chart display transforms re-render
without a reload. Retire the now-unused card.
This commit is contained in:
Marc-André Bombeck committed 2026-06-05 00:08:07 +02:00
1 parent 488cc09ae9
commit 280bf42382
15 files changed
+716 -491

No files matched your search

@@ -1,16 +1,18 @@
/**
* v1.4.16 Wave-C MED — bottom-nav 5+More layout.
* Bottom-nav iOS-parity layout (additive middle-path).
*
* SSR contract for `<BottomNav>`:
* - exactly five primary links + one "More" button render in the strip
* - the More button is keyboard-reachable as a `<button>` with
* `aria-haspopup="dialog"`
* - Achievements lives in the More sheet (closed by default under SSR),
* not in the always-visible strip
* - WCAG 2.5.5 floor: every entry is `min-h-11 min-w-11`
* - the mobile bar is Home · Meds · Log(center) · Insights · More
* - the center "Log" slot is a capture ACTION (a `<button>` with
* `aria-haspopup="dialog"`), not a navigation link
* - the More button opens a hub (closed by default under SSR)
* - the More hub is a real hub: Measurements + Mood (which left the
* always-visible strip) stay reachable here, alongside Workouts,
* Achievements, Notifications and Settings — nothing is orphaned
* - WCAG 2.5.5 floor: every strip entry is `min-h-11 min-w-11`
*
* v1.8.6 — the Targets (Zielwerte) page is deprecated and dropped from
* the menu, so it no longer appears in the strip or the overflow set.
* the menu, so it no longer appears in the strip or the hub.
*/
import { describe, expect, it, vi } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
@@ -33,20 +35,23 @@ function render() {
);
}
describe("<BottomNav> 5+More layout", () => {
it("renders the five primary anchors", () => {
describe("<BottomNav> iOS-parity layout", () => {
it("renders the flanking primary anchors (Home, Meds, Insights)", () => {
const html = render();
for (const href of [
"/",
"/measurements",
"/mood",
"/medications",
"/insights",
]) {
for (const href of ["/", "/medications", "/insights"]) {
expect(html).toContain(`href="${href}"`);
}
});
it("renders the center capture action as a dialog-opening button, not a link", () => {
const html = render();
expect(html).toContain('data-testid="bottom-nav-capture"');
// The capture button opening tag carries aria-haspopup="dialog".
const capture = html.match(/<button[^>]*bottom-nav-capture[^>]*>/);
expect(capture).not.toBeNull();
expect(capture![0]).toMatch(/aria-haspopup="dialog"/);
});
it("renders an overflow More button via aria-haspopup", () => {
const html = render();
expect(html).toContain('data-testid="bottom-nav-more"');
@@ -54,28 +59,36 @@ describe("<BottomNav> 5+More layout", () => {
expect(html).toMatch(/aria-expanded="false"/);
});
it("each primary entry meets the 44 px tap-target floor (min-h-11 min-w-11)", () => {
it("does not render Measurements or Mood as always-visible strip links", () => {
// Measurements + Mood left the always-visible strip when the center
// capture action took the middle slot; they live in the More hub
// (rendered on open — exercised in e2e) plus the capture picker.
// The closed-hub SSR markup must therefore carry neither as a strip
// anchor, and the capture/More affordances replace them.
const html = render();
// Count `min-h-11 min-w-11` occurrences. Six is the expected floor
// (five anchors + the More button); we don't hard-pin because a
// future entry would also satisfy the contract.
expect(html).not.toContain('href="/measurements"');
expect(html).not.toContain('href="/mood"');
// The replacements that keep those surfaces reachable are present.
expect(html).toContain('data-testid="bottom-nav-capture"');
expect(html).toContain('data-testid="bottom-nav-more"');
});
it("each strip entry meets the 44 px tap-target floor (min-h-11 min-w-11)", () => {
const html = render();
// Five flanking strip slots (Home, Meds, capture button, Insights,
// More) all carry `min-h-11 min-w-11`. We don't hard-pin the count
// because a future entry would also satisfy the contract.
const matches = html.match(/min-h-11 min-w-11/g) ?? [];
expect(matches.length).toBeGreaterThanOrEqual(6);
expect(matches.length).toBeGreaterThanOrEqual(5);
});
it("no longer lists the deprecated /targets entry (v1.8.6)", () => {
// Targets was dropped from the OVERFLOW set; the strip never carried
// it. The closed-sheet SSR render must therefore contain no /targets
// link — a regression net against the entry creeping back into the
// primary strip or the overflow set.
const html = render();
expect(html).not.toContain('href="/targets"');
});
it("More button carries an accessible label", () => {
const html = render();
// Attribute order isn't guaranteed by React's renderer, so match
// both possible directions instead of pinning the order.
const hasLabelFirst =
/aria-label="More"[^>]*data-testid="bottom-nav-more"/.test(html);
const hasTestidFirst =
+94 -66
View File
@@ -2,10 +2,14 @@
import {
Activity,
Bell,
Dumbbell,
Home,
Lightbulb,
MoreHorizontal,
Pill,
Plus,
Settings,
Trophy,
Waves,
} from "lucide-react";
@@ -19,6 +23,7 @@ import {
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
import { CapturePicker } from "@/components/layout/capture-picker";
import { cn } from "@/lib/utils";
import { useTranslations } from "@/lib/i18n/context";
@@ -28,36 +33,48 @@ interface NavLink {
icon: typeof Home;
}
// v1.4.16 Wave-C MED — bottom-nav was rendering all 7 destinations
// edge-to-edge on a 375 px viewport, which collapsed each touch
// target to ~50 px wide and made the WCAG 2.5.5 44 px floor only
// just-pass on iPhone-13-mini-class screens. The mobile audit
// recommended 5+More — so the four most-used surfaces stay in the
// strip (Home, Measurements, Mood, Medications) plus Insights as
// the fifth, and Achievements moves into a "More" sheet.
// v1.12.x — iOS-parity bottom bar (additive middle-path).
//
// Order is preserved relative to the v1.4.15 bottom-nav so muscle
// memory keeps working for the four core actions.
// The mobile bar is a 5-slot shape: Home · Meds · Log(center) ·
// Insights · More — mirroring the native client. The center slot is a
// capture ACTION (not a destination): it opens a picker that routes to
// the existing measurement / medication / mood quick-entry surfaces
// (see `<CapturePicker>`).
//
// v1.9.0 — the standalone Targets (Zielwerte) page is retired. Target
// editing lives inline on the Insights metric pages (the per-metric
// reference panel mounts the target editor), so there is no nav entry.
const PRIMARY: ReadonlyArray<NavLink> = [
// PRIMARY_LEFT / PRIMARY_RIGHT are the two anchor pairs that flank the
// center action. The previous strip (Home · Measurements · Mood ·
// Medications · Insights) carried Measurements and Mood inline; those
// stay fully reachable — through the center capture picker AND the More
// hub below — so nothing is orphaned. On desktop the sidebar still
// lists every destination.
const PRIMARY_LEFT: ReadonlyArray<NavLink> = [
{ href: "/", tKey: "nav.dashboard", icon: Home },
{ href: "/measurements", tKey: "nav.measurements", icon: Activity },
{ href: "/mood", tKey: "nav.mood", icon: Waves },
{ href: "/medications", tKey: "nav.medications", icon: Pill },
];
const PRIMARY_RIGHT: ReadonlyArray<NavLink> = [
{ href: "/insights", tKey: "nav.insights", icon: Lightbulb },
];
const OVERFLOW: ReadonlyArray<NavLink> = [
// The "More" hub — a real hub of the remaining top-level destinations,
// not just an overflow bucket. Measurements and Mood live here (they
// left the always-visible strip when the center capture action took the
// middle slot), alongside Workouts, Achievements, Notifications and
// Settings. Every entry is an existing top-level route.
const MORE_HUB: ReadonlyArray<NavLink> = [
{ href: "/measurements", tKey: "nav.measurements", icon: Activity },
{ href: "/mood", tKey: "nav.mood", icon: Waves },
{ href: "/insights/workouts", tKey: "nav.workouts", icon: Dumbbell },
{ href: "/achievements", tKey: "nav.achievements", icon: Trophy },
{ href: "/notifications", tKey: "nav.notifications", icon: Bell },
{ href: "/settings/account", tKey: "nav.settings", icon: Settings },
];
export function BottomNav() {
const pathname = usePathname();
const { t } = useTranslations();
const [moreOpen, setMoreOpen] = useState(false);
const [captureOpen, setCaptureOpen] = useState(false);
function isActiveLink(href: string) {
return href === "/" ? pathname === "/" : pathname.startsWith(href);
@@ -65,84 +82,95 @@ export function BottomNav() {
// The "More" entry is treated as active when any of its children
// is the current page — gives the user a clue that they've drilled
// into a sub-route via overflow.
const overflowActive = OVERFLOW.some((item) => isActiveLink(item.href));
// into a sub-route via the hub.
const moreActive = MORE_HUB.some((item) => isActiveLink(item.href));
function renderPrimary(item: NavLink) {
const isActive = isActiveLink(item.href);
return (
<Link
key={item.href}
href={item.href}
aria-label={t(item.tKey)}
aria-current={isActive ? "page" : undefined}
// Touch target sized to WCAG 2.5.5 (44×44 CSS px). The
// outer min-h-11 min-w-11 is the actual hit area; the icon
// stays visually centered at 20px so the design doesn't shift.
className={cn(
"relative flex min-h-11 min-w-11 flex-1 items-center justify-center rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2",
isActive
? "text-primary"
: "text-muted-foreground hover:text-foreground",
)}
>
<item.icon className="h-5 w-5" />
{isActive && (
<span className="bg-primary absolute bottom-1.5 h-1 w-1 rounded-full" />
)}
</Link>
);
}
return (
<>
{/* v1.4.33 F14 — bar height and safe-area defence so the bar can
never overlap the last viewport line of scrollable page content.
- `min-h-16` floors the bar at 64px even if the inner flex row
collapses (e.g. a future variant without one of the icons).
- `pb-[env(safe-area-inset-bottom)]` reserves the home-indicator
inset on iOS / iPadOS PWA installs.
- `bg-card` (solid, not the previous `bg-card/80`) plus
`border-t` give the bar a clean visual edge so any page
content that scrolls under the bar is properly occluded
rather than bleeding through a translucent surface. Page-
level pb-* padding owners (auth-shell + per-page shells)
still reserve room above the bar; this change hardens the
bar itself so the visual contract holds even when a page
shell forgets the bottom-padding contract.
*/}
`min-h-16` floors the bar at 64px; `pb-[env(safe-area-inset-bottom)]`
reserves the home-indicator inset on iOS / iPadOS PWA installs;
`bg-card` + `border-t` give the bar a clean visual edge so page
content that scrolls under the bar is occluded, not bleeding
through. */}
<nav
aria-label={t("nav.mobileNavigation")}
className="bg-card border-border fixed bottom-0 left-0 z-50 min-h-16 w-full border-t pb-[env(safe-area-inset-bottom)] backdrop-blur-md md:hidden"
>
<div className="mx-auto flex h-16 max-w-lg items-stretch justify-around px-1">
{PRIMARY.map((item) => {
const isActive = isActiveLink(item.href);
return (
<Link
key={item.href}
href={item.href}
aria-label={t(item.tKey)}
aria-current={isActive ? "page" : undefined}
// Touch target sized to WCAG 2.5.5 (44×44 CSS px). The
// outer min-h-11 min-w-11 is the actual hit area; the icon
// stays visually centered at 20px so the design doesn't shift.
//
// v1.4.34 IW-G — keyboard users get a visible ring on
// focus-visible, matching the sidebar treatment from
// v1.4.33. Without it the bottom-nav had no focus
// indicator at all on Tab navigation.
className={cn(
"relative flex min-h-11 min-w-11 flex-1 items-center justify-center rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2",
isActive
? "text-primary"
: "text-muted-foreground hover:text-foreground",
)}
>
<item.icon className="h-5 w-5" />
{isActive && (
<span className="bg-primary absolute bottom-1.5 h-1 w-1 rounded-full" />
)}
</Link>
);
})}
{PRIMARY_LEFT.map(renderPrimary)}
{/* Center capture action — a labeled button (NOT a link) that
opens the capture picker. Visually elevated so it reads as
the primary CTA. */}
<div className="flex flex-1 items-center justify-center">
<button
type="button"
aria-label={t("nav.capture.title")}
aria-haspopup="dialog"
aria-expanded={captureOpen}
onClick={() => setCaptureOpen(true)}
data-testid="bottom-nav-capture"
className="bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:ring-ring/50 flex min-h-11 min-w-11 items-center justify-center rounded-full shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2"
>
<Plus className="h-6 w-6" />
</button>
</div>
{PRIMARY_RIGHT.map(renderPrimary)}
<button
type="button"
aria-label={t("nav.more")}
aria-haspopup="dialog"
aria-expanded={moreOpen}
aria-current={overflowActive ? "page" : undefined}
aria-current={moreActive ? "page" : undefined}
onClick={() => setMoreOpen(true)}
className={cn(
"relative flex min-h-11 min-w-11 flex-1 items-center justify-center rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2",
overflowActive
moreActive
? "text-primary"
: "text-muted-foreground hover:text-foreground",
)}
data-testid="bottom-nav-more"
>
<MoreHorizontal className="h-5 w-5" />
{overflowActive && (
{moreActive && (
<span className="bg-primary absolute bottom-1.5 h-1 w-1 rounded-full" />
)}
</button>
</div>
</nav>
<CapturePicker open={captureOpen} onOpenChange={setCaptureOpen} />
<Sheet open={moreOpen} onOpenChange={setMoreOpen}>
<SheetContent
side="bottom"
@@ -156,8 +184,8 @@ export function BottomNav() {
<SheetTitle>{t("nav.moreSheetTitle")}</SheetTitle>
<SheetDescription>{t("nav.moreSheetDescription")}</SheetDescription>
</SheetHeader>
<div className="grid grid-cols-1 gap-2 px-4 pb-4">
{OVERFLOW.map((item) => {
<div className="grid grid-cols-2 gap-2 px-4 pb-4">
{MORE_HUB.map((item) => {
const isActive = isActiveLink(item.href);
return (
<Link
+157
View File
@@ -0,0 +1,157 @@
"use client";
import { useState } from "react";
import { Activity, Pill, Waves } from "lucide-react";
import { MeasurementForm } from "@/components/measurements/measurement-form";
import { MoodForm } from "@/components/mood/mood-form";
import { MedicationIntakeQuickAdd } from "@/components/dashboard/medication-intake-quick-add";
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
import { cn } from "@/lib/utils";
import { useTranslations } from "@/lib/i18n/context";
/**
* The center "Log" capture action (iOS parity — the bottom bar's
* middle slot is a capture CTA, not a destination). It opens a small
* picker that routes to one of three existing quick-entry surfaces:
*
* - Measurement → `<MeasurementForm>` (the `/measurements` add form)
* - Medication → `<MedicationIntakeQuickAdd>` (the dashboard intake
* quick-add)
* - Mood → `<MoodForm>` (the `/mood` add form, 5-face flow)
*
* All three forms share the `{ onSuccess, onCancel, footerSlot }`
* contract and are designed to mount inside `<ResponsiveSheet>`, so the
* picker reuses them verbatim rather than rebuilding any capture UI.
*
* Nothing here orphans a route: the same surfaces remain reachable
* from their own pages (`/measurements`, `/mood`, dashboard) and from
* the More hub. The picker is an additional fast path, not a removal.
*/
type CaptureKind = "measurement" | "medication" | "mood";
interface CapturePickerProps {
/** Whether the picker chooser sheet is open. */
open: boolean;
/** Open-state setter for the chooser sheet. */
onOpenChange: (open: boolean) => void;
}
export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
const { t } = useTranslations();
const [kind, setKind] = useState<CaptureKind | null>(null);
const [footerEl, setFooterEl] = useState<HTMLDivElement | null>(null);
function chooseKind(next: CaptureKind) {
// Close the chooser first, then open the form sheet so only one
// bottom-sheet is mounted at a time (no stacked backdrops).
onOpenChange(false);
setKind(next);
}
function closeForm() {
setKind(null);
}
const options: ReadonlyArray<{
kind: CaptureKind;
label: string;
description: string;
icon: typeof Activity;
}> = [
{
kind: "measurement",
label: t("nav.capture.measurement"),
description: t("nav.capture.measurementDescription"),
icon: Activity,
},
{
kind: "medication",
label: t("nav.capture.medication"),
description: t("nav.capture.medicationDescription"),
icon: Pill,
},
{
kind: "mood",
label: t("nav.capture.mood"),
description: t("nav.capture.moodDescription"),
icon: Waves,
},
];
const formTitle =
kind === "measurement"
? t("measurements.addMeasurement")
: kind === "medication"
? t("nav.capture.medication")
: t("mood.addEntry");
return (
<>
{/* The capture-kind chooser. */}
<ResponsiveSheet
open={open}
onOpenChange={onOpenChange}
title={t("nav.capture.title")}
description={t("nav.capture.description")}
>
<div className="grid grid-cols-1 gap-2" data-testid="capture-picker-options">
{options.map((opt) => (
<button
key={opt.kind}
type="button"
data-testid={`capture-picker-${opt.kind}`}
onClick={() => chooseKind(opt.kind)}
className={cn(
"border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2",
)}
>
<span className="bg-primary/10 text-primary flex h-9 w-9 shrink-0 items-center justify-center rounded-full">
<opt.icon className="h-5 w-5" aria-hidden="true" />
</span>
<span className="min-w-0">
<span className="block text-sm font-medium">{opt.label}</span>
<span className="text-muted-foreground block text-xs">
{opt.description}
</span>
</span>
</button>
))}
</div>
</ResponsiveSheet>
{/* The chosen capture surface, reusing the existing form. */}
<ResponsiveSheet
open={kind !== null}
onOpenChange={(next) => {
if (!next) closeForm();
}}
title={formTitle}
footer={<div ref={setFooterEl} className="flex w-full" />}
>
{kind === "measurement" && (
<MeasurementForm
onSuccess={closeForm}
onCancel={closeForm}
footerSlot={footerEl}
/>
)}
{kind === "medication" && (
<MedicationIntakeQuickAdd
onSuccess={closeForm}
onCancel={closeForm}
footerSlot={footerEl}
/>
)}
{kind === "mood" && (
<MoodForm
onSuccess={closeForm}
onCancel={closeForm}
footerSlot={footerEl}
/>
)}
</ResponsiveSheet>
</>
);
}