mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 15:02:04 +00:00
Server and first client render now agree everywhere query state used to leak into the chrome, checkboxes no longer nest inside buttons, delete confirmations admit the undo they offer, raw step counts drop their decimals, the truncated unit label wraps instead, streaks know their singular, the medication header speaks the user's date format, a failed coach turn keeps the user's message and says what went wrong, settings status notes follow a language switch, the locale only flips once its bundle actually loaded, and the last raw api fetches in hooks move onto the shared client.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { queryKeys } from "@/lib/query-keys";
|
|
import { apiGet } from "@/lib/api/api-fetch";
|
|
import {
|
|
resolveDashboardLayout,
|
|
type DashboardLayout,
|
|
} from "@/lib/dashboard-layout";
|
|
|
|
/**
|
|
* v1.4.25 W4 — shared reader for the dashboard-layout payload across
|
|
* the insights surfaces.
|
|
*
|
|
* The mother page and every sub-page need the persisted
|
|
* `comparisonBaseline` so the dashboard / insights chart-cog stays
|
|
* in sync. The shape repeats the same `useQuery({ … queryKey:
|
|
* queryKeys.dashboardWidgets() … })` four-line block that lived inline
|
|
* on the mother page — extracted here so a new sub-page consumer drops
|
|
* the boilerplate and so the TanStack-Query cache lookup stays
|
|
* authoritative for every consumer.
|
|
*
|
|
* Returns the resolved `comparisonBaseline` (defaults to `"none"`)
|
|
* directly so consumers don't have to remember the `resolveDashboardLayout`
|
|
* fallback dance. `enabled` controls whether the query fires — the
|
|
* sub-pages gate this on `useAuth().isAuthenticated`.
|
|
*/
|
|
export function useInsightsLayoutPrefs(enabled: boolean) {
|
|
const { data } = useQuery({
|
|
queryKey: queryKeys.dashboardWidgets(),
|
|
queryFn: async () => apiGet<DashboardLayout>("/api/dashboard/widgets"),
|
|
enabled,
|
|
});
|
|
const compareBaseline =
|
|
resolveDashboardLayout(data).comparisonBaseline ?? "none";
|
|
return { layout: data ?? null, compareBaseline } as const;
|
|
}
|