mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
Offer the previous session of the same sport from the workout page
"How does this compare to last time?" is the most likely next question after reading a workout, and answering it meant going back to the list and scanning for the one before. Resolve the previous session server-side, through the same canonical picker the list uses, so the link can never land on a duplicate row recorded by a second watch, and render it beside the own-history average line. Null when nothing older exists, and then no link is shown. The stats card's hand-rolled heading moves to the icon-less TileHeader while the file is open.
This commit is contained in:
1 parent
76b407b6de
commit
a61cdae437
13 files changed
+177
-14
No files matched your search
@@ -80,6 +80,7 @@ const FIXTURE: WorkoutDetailPayload = {
|
||||
sportContext: null,
|
||||
aiInsight: null,
|
||||
canonicalId: "w-1",
|
||||
previousWorkoutId: null,
|
||||
};
|
||||
|
||||
describe("<WorkoutDetailHeader>", () => {
|
||||
@@ -104,6 +105,18 @@ describe("<WorkoutDetailStats>", () => {
|
||||
expect(html).toContain("Pace");
|
||||
});
|
||||
|
||||
it("links to the previous session only when the server resolved one", () => {
|
||||
expect(render(<WorkoutDetailStats workout={FIXTURE} />)).not.toContain(
|
||||
'data-slot="workout-detail-previous-link"',
|
||||
);
|
||||
|
||||
const html = render(
|
||||
<WorkoutDetailStats workout={{ ...FIXTURE, previousWorkoutId: "w-0" }} />,
|
||||
);
|
||||
expect(html).toContain('href="/insights/workouts/w-0"');
|
||||
expect(html).toContain("Previous session");
|
||||
});
|
||||
|
||||
it("omits tiles for null fields", () => {
|
||||
const minimal: WorkoutDetailPayload = {
|
||||
...FIXTURE,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowRight,
|
||||
Flame,
|
||||
Footprints,
|
||||
HeartPulse,
|
||||
@@ -11,6 +13,7 @@ import {
|
||||
} from "lucide-react";
|
||||
|
||||
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||
import { TileHeader } from "@/components/insights/tile-header";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import type { WorkoutDetailPayload } from "@/hooks/use-workouts";
|
||||
@@ -157,12 +160,12 @@ export function WorkoutDetailStats({ workout }: WorkoutDetailStatsProps) {
|
||||
return (
|
||||
<Card data-slot="workout-detail-stats">
|
||||
<CardHeader>
|
||||
<h2
|
||||
data-slot="card-title"
|
||||
className="text-base leading-none font-semibold"
|
||||
>
|
||||
{t("insights.workouts.detail.statsTitle")}
|
||||
</h2>
|
||||
{/* Icon-less `TileHeader`, not a hand-rolled h2 — the standards
|
||||
allow exactly three header patterns and this card is a tile. */}
|
||||
<TileHeader
|
||||
title={t("insights.workouts.detail.statsTitle")}
|
||||
titleAs="h2"
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div
|
||||
@@ -175,14 +178,32 @@ export function WorkoutDetailStats({ workout }: WorkoutDetailStatsProps) {
|
||||
<StatTile key={tile.label} {...tile} />
|
||||
))}
|
||||
</div>
|
||||
{averageLine ? (
|
||||
<p
|
||||
data-slot="workout-detail-sport-average"
|
||||
className="text-muted-foreground text-xs"
|
||||
>
|
||||
{t("insights.workouts.detail.sportAverageLabel")}{" "}
|
||||
<span className="tabular-nums">{averageLine}</span>
|
||||
</p>
|
||||
{averageLine || workout.previousWorkoutId ? (
|
||||
// One row, per the inline-action shape: the sentence wraps
|
||||
// internally, the link stays beside it.
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
{averageLine ? (
|
||||
<p
|
||||
data-slot="workout-detail-sport-average"
|
||||
className="text-muted-foreground min-w-0 flex-1 text-xs"
|
||||
>
|
||||
{t("insights.workouts.detail.sportAverageLabel")}{" "}
|
||||
<span className="tabular-nums">{averageLine}</span>
|
||||
</p>
|
||||
) : (
|
||||
<span className="min-w-0 flex-1" />
|
||||
)}
|
||||
{workout.previousWorkoutId ? (
|
||||
<Link
|
||||
href={`/insights/workouts/${workout.previousWorkoutId}`}
|
||||
data-slot="workout-detail-previous-link"
|
||||
className="text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 inline-flex shrink-0 items-center gap-1.5 text-xs underline-offset-4 transition-colors hover:underline focus-visible:ring-[3px] focus-visible:outline-none"
|
||||
>
|
||||
{t("insights.workouts.detail.previousSessionLink")}
|
||||
<ArrowRight className="size-3.5" aria-hidden="true" />
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Reference in new issue
Block a user