Merge wave-qol-mechanical: route stray query keys through the factory

Fix the target-edit-sheet invalidation that used a bare ["insights"] array
not matching the factory prefix the reads nest under (a silent no-op), and
migrate 12 further bare queryKey call sites onto the centralised factory.
This commit is contained in:
Marc-André Bombeck committed 2026-06-19 20:58:16 +02:00
commit 572ff3502e
16 files changed
+80 -24

No files matched your search

+5 -1
View File
@@ -32,6 +32,8 @@ import {
type QueryClient,
} from "@tanstack/react-query";
import { queryKeys } from "@/lib/query-keys";
const DB_NAME = "healthlog-query-cache";
const STORE = "kv";
const KEY = "react-query";
@@ -143,7 +145,9 @@ interface PersistedPayload {
/** Read the current account id from the live `["auth","me"]` cache entry. */
function currentUserId(queryClient: QueryClient): string | null {
const me = queryClient.getQueryData<{ id?: string } | null>(["auth", "me"]);
const me = queryClient.getQueryData<{ id?: string } | null>(
queryKeys.authMe(),
);
return me?.id ?? null;
}
+14
View File
@@ -13,4 +13,18 @@ export const coachKeys = {
coachNudgeStatus: () => ["coach-nudge-status"] as const,
/** v1.18.6 (CCH-03) — mark-Coach-seen mutation (clears the FAB unread dot). */
coachMarkSeen: () => ["coach-mark-seen"] as const,
/**
* v1.18.7 — the Coach conversation rail list (`GET /api/insights/chat`).
* Previously a hook-local bare `["coachConversations"]`; centralised so
* the optimistic delete and the streaming hook's post-turn invalidation
* share one factory-routed key.
*/
coachConversations: () => ["coachConversations"] as const,
/**
* v1.18.7 — one decrypted Coach conversation (`GET /api/insights/chat/[id]`).
* Keyed on the conversation id so two open threads never share a cache slot;
* the streaming hook invalidates this slot once the persisted twin lands.
*/
coachConversation: (id: string | null) =>
["coachConversation", id] as const,
};
+19
View File
@@ -126,6 +126,25 @@ export const measurementKeys = {
measurementDiversity: (type: string) =>
["measurement-diversity", type] as const,
/**
* v1.18.7 — per-day drill-down list for one `MeasurementType`
* (`GET /api/measurements?type=&dayKey=`), opened from a values-list
* day row. Keyed by `(type, dayKey)` so each expanded day caches its own
* slot. Distinct `["measurement-drilldown"]` prefix (not `["measurements"]`)
* because the day list is a stable historical slice that the drain has
* already settled — it does not need a measurement-write fan-out.
*/
measurementDrilldown: (type: string, dayKey: string) =>
["measurement-drilldown", type, dayKey] as const,
/**
* v1.18.7 — per-metric personal-records read (`GET /api/personal-records`)
* backing the decorative PR badge on a metric tile. Per-metric key so two
* tiles never share a cache slot; its own `["personal-records"]` prefix.
*/
personalRecordsByMetric: (metric: string) =>
["personal-records", "by-metric", metric] as const,
/**
* v1.18.7 (Wave E) — bounded last-7 readings for one `MeasurementType`,
* powering the discreet 7-day trend strip on a Vorsorge card. Rides under
+16
View File
@@ -8,6 +8,22 @@ export const medicationKeys = {
medicationDetail: (id: string) => ["medications", id] as const,
medicationComplianceChart: (medicationId: string) =>
["compliance-chart-inline", medicationId] as const,
/**
* v1.18.7 — the bare `["compliance-chart-inline"]` prefix, for fan-out
* invalidation across every per-medication inline compliance tile in one
* tick (e.g. a dashboard quick-add intake). `medicationComplianceChart(id)`
* above keys an individual tile; this routes the parent prefix through the
* factory so the fan-out is not a bare array at the call site.
*/
complianceChartInline: () => ["compliance-chart-inline"] as const,
/**
* v1.18.7 — per-medication side-effects list, last 30 days
* (`GET /api/medications/[id]/side-effects`). Rides under the
* `["medications", id, …]` prefix so a CRUD mutation reaches it through
* `medicationDependentKeys`.
*/
medicationSideEffects: (medicationId: string) =>
["medications", medicationId, "side-effects", "list"] as const,
/**
* v1.4.42 W3-QUERYKEY-LONGTAIL — per-medication compliance KPI used
* by `medication-card` + `glp1-medication-card`. Centralising lets