mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
refactor: simplify batch (S-02 to S-04)
Three small reuse wins from the W6 simplify review: - openapi/registry.ts swaps the lazy require() for a static import. The ESLint disable + as-cast carried no real benefit; the only callers always loaded the route table anyway. - Extract useCoachPrefs() into a shared hook so the settings sheet and message thread share one queryKey + one fallback shape. Removes the drift between the two existing inline blocks. - Replace the 9-deep wantsX boolean ladder in coach snapshot with a single CoachScopeSource -> MeasurementType[] map. Drives both the WHERE type IN (...) build and the appleHealthBlocks gate, so adding a new metric is one entry instead of three parallel edits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3ee6dab6fa
commit
dfffe6bb3b
5 files changed
+99
-60
No files matched your search
@@ -39,8 +39,16 @@ vi.mock("@/hooks/use-auth", () => ({
|
||||
// QueryClientProvider; stub the hook to return the legacy defaults so
|
||||
// the existing assertions on the closed-by-default disclosure stay
|
||||
// representative.
|
||||
//
|
||||
// v1.4.23 H7 — also stubs `useMutation` for the per-message thumbs
|
||||
// feedback row inside the assistant bubble.
|
||||
vi.mock("@tanstack/react-query", () => ({
|
||||
useQuery: () => ({ data: undefined }),
|
||||
useMutation: () => ({
|
||||
mutate: vi.fn(),
|
||||
isPending: false,
|
||||
isError: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
import { MessageThread } from "../message-thread";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import {
|
||||
Bot,
|
||||
ChevronRight,
|
||||
@@ -14,10 +14,7 @@ import {
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import {
|
||||
DEFAULT_COACH_PREFS,
|
||||
type CoachPrefs,
|
||||
} from "@/lib/validations/coach-prefs";
|
||||
import { useCoachPrefs } from "@/hooks/use-coach-prefs";
|
||||
|
||||
import { SourceChips } from "./source-chips";
|
||||
import type {
|
||||
@@ -66,18 +63,10 @@ export function MessageThread({
|
||||
|
||||
// v1.4.23 H4 — read the user's Coach prefs so the evidence
|
||||
// disclosure honours `showEvidenceByDefault`. Cached at the
|
||||
// queryClient level; the settings sheet writes the same key after a
|
||||
// successful save so the new default takes effect on the next reply
|
||||
// without a page reload.
|
||||
const { data: coachPrefs } = useQuery({
|
||||
queryKey: ["coach-prefs"],
|
||||
queryFn: async () => {
|
||||
const res = await fetch("/api/auth/me/coach-prefs");
|
||||
if (!res.ok) return DEFAULT_COACH_PREFS;
|
||||
const env = (await res.json()) as { data: CoachPrefs };
|
||||
return env.data;
|
||||
},
|
||||
});
|
||||
// queryClient level via the shared `useCoachPrefs` hook; the
|
||||
// settings sheet writes the same key after a successful save so the
|
||||
// new default takes effect on the next reply without a page reload.
|
||||
const { data: coachPrefs } = useCoachPrefs();
|
||||
const evidenceDefaultOpen = coachPrefs?.showEvidenceByDefault ?? false;
|
||||
|
||||
const messages: CoachMessageDTO[] = conversation?.messages ?? [];
|
||||
|
||||
Reference in new issue
Block a user