mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
Output of `node scripts/strip-planning-tags.mjs --write`: 3,157 comment lines in 1,308 files lose the work-item identifier at their head. Release versions and issue references stay; nothing outside comment text changes, which the script checks per file against a comment-free printout. healthlog/no-planning-tags is enabled at error level with this commit, so the tree it lands on is clean.
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 — 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;
|
|
}
|