mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
fix(charts): match chart loading shells to the charts they become
The footer reserve under a day-linked chart's loading shell still held the caption line that was dropped from those charts, so every such shell stood 20 px taller than its chart (40 px on a phone). The dashboard's mood chart loaded behind the generic shell, which is about 30 px shorter than the mood card. When the shared chart chunk arrived late the dashboard's chart row changed height under a reader already scrolled past it; the tablet shell journey measured <main> right after such a swap and found it no longer at its end. The reserve now holds only the day rug, and the mood chart gets a shell built from the same card primitives and boxes. The tablet journey also waits for every chart cell to reveal and every loading shell to go before it scrolls to the end, instead of trusting two equal heights 250 ms apart.
This commit is contained in:
1 parent
23a6f85b0f
commit
e84c358fdf
5 files changed
+103
-16
No files matched your search
@@ -12,7 +12,10 @@ import { queryKeys } from "@/lib/query-keys";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useInsightsLayoutPrefs } from "@/hooks/use-insights-layout-prefs";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ChartSkeleton } from "@/components/charts/chart-skeleton";
|
||||
import {
|
||||
ChartSkeleton,
|
||||
MoodChartSkeleton,
|
||||
} from "@/components/charts/chart-skeleton";
|
||||
import { MetricEmptyState } from "@/components/insights/metric-empty-state";
|
||||
import { MetricTargetSummary } from "@/components/insights/metric-target-summary";
|
||||
import {
|
||||
@@ -54,7 +57,7 @@ const MoodChart = dynamic(
|
||||
import("@/components/charts/chart-runtime").then((mod) => ({
|
||||
default: mod.MoodChart,
|
||||
})),
|
||||
{ ssr: false, loading: () => <ChartSkeleton /> },
|
||||
{ ssr: false, loading: () => <MoodChartSkeleton /> },
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
@@ -50,12 +51,16 @@ const SLOW_HINT_DELAY_MS = 3_000;
|
||||
|
||||
/**
|
||||
* The footer a loaded `<HealthChart>` paints under its plot: the row of day
|
||||
* dots and its caption on a day-linked chart, and the collapsed "show as
|
||||
* table" disclosure. A loading shell without it was ~100 px shorter than the
|
||||
* card it turned into (CLS on every metric page, the BMI page most visibly),
|
||||
* so the shells reserve the same boxes: `h-3` rug, `mt-1` caption (two lines
|
||||
* on a phone, one from `sm`), and the disclosure's `mt-3 border-t pt-3` frame
|
||||
* around its `min-h-11` button.
|
||||
* dots on a day-linked chart, and the collapsed "show as table" disclosure. A
|
||||
* loading shell without it was ~100 px shorter than the card it turned into
|
||||
* (CLS on every metric page, the BMI page most visibly), so the shells reserve
|
||||
* the same boxes: the `h-3` rug, and the disclosure's `mt-3 border-t pt-3`
|
||||
* frame around its `min-h-11` button.
|
||||
*
|
||||
* The rug is all a day-linked chart paints under its plot. It used to carry a
|
||||
* one-line caption as well, and the reserve kept that line after the caption
|
||||
* went: every day-linked shell stood 20 px taller than its chart (40 px on a
|
||||
* phone) and the page shrank under the reader when the chart arrived.
|
||||
*/
|
||||
export function ChartFooterReserve({
|
||||
dayLinks = false,
|
||||
@@ -67,12 +72,7 @@ export function ChartFooterReserve({
|
||||
if (!dayLinks && !dataTable) return null;
|
||||
return (
|
||||
<div aria-hidden="true" data-slot="chart-footer-reserve">
|
||||
{dayLinks ? (
|
||||
<>
|
||||
<div className="h-3" />
|
||||
<div className="mt-1 h-9 sm:h-4" />
|
||||
</>
|
||||
) : null}
|
||||
{dayLinks ? <div className="h-3" /> : null}
|
||||
{dataTable ? (
|
||||
<div className="border-border mt-3 border-t pt-3">
|
||||
<div className="h-11" />
|
||||
@@ -172,3 +172,43 @@ export function ChartSkeleton({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The loading shell for a full-size, day-linked `<MoodChart>`.
|
||||
*
|
||||
* The mood chart is drawn in a `Card` (vertical padding and a gap between
|
||||
* header and plot, where `ChartSkeleton` has padding and a margin), its plot
|
||||
* band is 200 / 220 px rather than 240 / 280, and it paints the day rug and
|
||||
* the collapsed data-table disclosure under the plot. Shown in the generic
|
||||
* shell, the card grew by about 30 px when the chart chunk arrived, under a
|
||||
* reader already scrolled past it. So it gets the same primitives and the
|
||||
* same boxes.
|
||||
*/
|
||||
export function MoodChartSkeleton() {
|
||||
const { t } = useTranslations();
|
||||
return (
|
||||
<Card
|
||||
data-slot="chart-skeleton"
|
||||
role="status"
|
||||
aria-busy="true"
|
||||
aria-live="polite"
|
||||
>
|
||||
<span className="sr-only">{t("charts.loadingLabel")}</span>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
<Skeleton className="h-5 w-32" />
|
||||
<div className="flex h-11 items-center gap-2">
|
||||
<Skeleton className="h-6 w-12" />
|
||||
<Skeleton className="h-6 w-12" />
|
||||
<Skeleton className="h-6 w-12" />
|
||||
<Skeleton className="h-6 w-12" />
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-[var(--chart-height,200px)] w-full md:h-[var(--chart-height-md,220px)]" />
|
||||
<ChartFooterReserve dayLinks dataTable />
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import type { ComponentProps, ReactNode } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
import { ChartErrorBoundary } from "@/components/charts/chart-error-state";
|
||||
import { ChartSkeleton } from "@/components/charts/chart-skeleton";
|
||||
import {
|
||||
ChartSkeleton,
|
||||
MoodChartSkeleton,
|
||||
} from "@/components/charts/chart-skeleton";
|
||||
import { HealthChartDynamic } from "@/components/charts/health-chart-dynamic";
|
||||
import { RecentWorkoutsTile } from "@/components/dashboard/recent-workouts-tile";
|
||||
import { RecentAchievementsCard } from "@/components/gamification/recent-achievements-card";
|
||||
@@ -26,7 +29,7 @@ const MoodChartLazy = dynamic(
|
||||
importWithRetry(() => import("@/components/charts/chart-runtime")).then(
|
||||
(mod) => ({ default: mod.MoodChart }),
|
||||
),
|
||||
{ ssr: false, loading: () => <ChartSkeleton /> },
|
||||
{ ssr: false, loading: () => <MoodChartSkeleton /> },
|
||||
);
|
||||
const MoodChart = (props: ComponentProps<typeof MoodChartLazy>) => (
|
||||
<ChartErrorBoundary>
|
||||
|
||||
Reference in new issue
Block a user