refactor(cycle): wire the phase-correlation card into the insights tab

The cycle insights tab rendered an empty placeholder while the phase-contrast
card + its `/api/cycle/insights` feed sat unused. Wire them together: a
`useCycleInsights` read drives the headline finding + the luteal-vs-follicular
crosstab on the insights tab, matching the mood-factor crosstab styling. Drops
the placeholder card + a duplicate disclaimer component in favour of the ones
already in use, and removes the unused recency/phase-result/label exports.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.8 committed 2026-06-06 10:26:13 +02:00
1 parent e984ada5f1
commit 55f40df0ac
9 files changed
+33 -213

No files matched your search

+23
View File
@@ -22,6 +22,13 @@ import type {
CycleHistoryResponse,
CycleProfileDTO,
} from "./types";
import type { CyclePhaseCrosstabRow } from "./cycle-phase-crosstab";
/** The `/api/cycle/insights` read: the phase-contrast rows + the headline. */
export interface CycleInsightsResponse {
rows: CyclePhaseCrosstabRow[];
headline: CyclePhaseCrosstabRow | null;
}
async function unwrap<T>(res: Response): Promise<T> {
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
@@ -60,6 +67,22 @@ export function useCycleProfile() {
});
}
/**
* The FDR-guarded phase-correlation surface: the luteal-vs-follicular contrast
* rows + the one headline finding. Gated server-side; reads only on the cycle
* insights tab.
*/
export function useCycleInsights() {
return useQuery({
queryKey: queryKeys.cycleInsights(),
queryFn: () =>
fetch("/api/cycle/insights").then((r) =>
unwrap<CycleInsightsResponse>(r),
),
staleTime: 5 * 60_000,
});
}
/** A fresh idempotency key per write attempt (matches the iOS Outbox shape). */
function idempotencyKey(): string {
return crypto.randomUUID();