mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
fix(insights): correct the active-energy assessment id and share the status card
The active-energy page passed `ACTIVE_ENERGY_BURNED` as `statusMetric`, but that is the DB MeasurementType, not the registry id the metric-status route accepts. The route's closed enum only knows `ACTIVE_ENERGY`, so every fetch 422'd and the assessment card silently fell back to its empty body. Point the page at the `ACTIVE_ENERGY` registry id and type `statusMetric` (plus the `useInsightMetricStatus` metric param) to the closed `MetricStatusMetricId` union instead of a bare string, so a future MeasurementType-vs-registry-id mismatch is a compile error rather than a silent 422. A typecheck pass over all 29 pages confirms active-energy was the only diverging one. Extract a shared `MetricStatusCard` that owns the `useInsightMetricStatus` hook and the assessment-card wiring, collapsing the duplicated mount block in the HealthKit metric scaffold and the bespoke sleep page to a single line each (only the icon differs). Behaviour is unchanged: the card mounts only on the data-bearing branch, so a source-less account never fires an assessment round-trip. Add a test asserting the active-energy page wires an accepted registry id. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 6e371aaeb9698f7b4251c22e1d8f381ddfa70a00)
This commit is contained in:
1 parent
5827ef58cb
commit
58b793ee4a
6 files changed
+112
-48
No files matched your search
@@ -4,6 +4,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import type { MetricStatusMetricId } from "@/lib/insights/metric-status-registry";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
|
||||
/**
|
||||
@@ -183,7 +184,15 @@ export function useInsightStatus(metric: InsightStatusMetric) {
|
||||
* no data (the page renders the insufficient-data empty state instead of
|
||||
* the card), so a brand-new account never fires an assessment round-trip.
|
||||
*/
|
||||
export function useInsightMetricStatus(metric: string, enabled = true) {
|
||||
export function useInsightMetricStatus(
|
||||
// The closed registry-id union (the route's Zod enum vocabulary). `""`
|
||||
// is the disabled-fetch placeholder the `HealthKitMetricPage` passes when
|
||||
// no `statusMetric` is wired (the hook must still run per the rules of
|
||||
// hooks); `enabled` is false on that branch so the empty id never reaches
|
||||
// a round-trip. A typo'd metric id is therefore a compile error.
|
||||
metric: MetricStatusMetricId | "",
|
||||
enabled = true,
|
||||
) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
const { locale } = useTranslations();
|
||||
|
||||
|
||||
Reference in new issue
Block a user