mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
Merge branch 'feat/biomarker-detail-page' into release/v1.25.0
This commit is contained in:
commit
95ee088646
36 files changed
+2209
-147
No files matched your search
@@ -44,6 +44,12 @@ export interface AskCoachActionProps {
|
||||
* briefing), which read better against the default all-source snapshot.
|
||||
*/
|
||||
scope?: CoachLaunchScope;
|
||||
/**
|
||||
* Auto-send the seeded question as the conversation's first turn instead
|
||||
* of only seeding the composer. The assessment hand-off sets this so the
|
||||
* Coach answers immediately; defaults to false (seed-only).
|
||||
*/
|
||||
autoSend?: boolean;
|
||||
/** Optional visible-label override; defaults to the shared CTA copy. */
|
||||
label?: string;
|
||||
/** className passthrough for per-card alignment. */
|
||||
@@ -53,6 +59,7 @@ export interface AskCoachActionProps {
|
||||
export function AskCoachAction({
|
||||
question,
|
||||
scope,
|
||||
autoSend,
|
||||
label,
|
||||
className,
|
||||
}: AskCoachActionProps) {
|
||||
@@ -76,7 +83,7 @@ export function AskCoachAction({
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
data-slot="ask-coach-action"
|
||||
onClick={() => launch.askCoach(question, scope)}
|
||||
onClick={() => launch.askCoach(question, scope, autoSend)}
|
||||
className={cn(
|
||||
// Discreet: muted text, hover lifts to foreground, no fill. Tight
|
||||
// height so it sits as a quiet footer link, not a primary CTA.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useReducer, useState } from "react";
|
||||
import { useEffect, useReducer, useRef, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
@@ -117,6 +117,13 @@ export interface CoachConversationProps {
|
||||
* established scope. Null → the route's default all-source snapshot.
|
||||
*/
|
||||
launchScope?: CoachLaunchScope | null;
|
||||
/**
|
||||
* When true, the `prefill` is dispatched as the conversation's first turn
|
||||
* automatically, exactly once on mount (ref-guarded). Used by the
|
||||
* assessment hand-off so the answer lands without a manual send. The send
|
||||
* only fires for a fresh conversation with a non-empty prefill.
|
||||
*/
|
||||
autoSend?: boolean;
|
||||
/**
|
||||
* Renders the conversation title. The surface passes the resolved
|
||||
* title string; the drawer wraps it in `<SheetTitle>`, the page in an
|
||||
@@ -188,6 +195,7 @@ export interface CoachConversationProps {
|
||||
export function CoachConversation({
|
||||
prefill,
|
||||
launchScope,
|
||||
autoSend,
|
||||
renderTitle,
|
||||
renderDescription,
|
||||
leadingHeaderActions,
|
||||
@@ -340,6 +348,33 @@ export function CoachConversation({
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-send the prefill as the conversation's first turn, exactly once.
|
||||
// A card hand-off (e.g. the assessment "ask about this") opens the Coach
|
||||
// with `autoSend` so the answer lands without a manual send. Ref-guarded so
|
||||
// it fires a single time per mount; only for a fresh conversation with a
|
||||
// non-empty prefill and no stream in flight.
|
||||
const autoSentRef = useRef(false);
|
||||
// Latest-handler ref so the auto-send effect never lists `handleSubmit` (it
|
||||
// re-creates each render) and never calls it synchronously in the effect
|
||||
// body — the dispatch is deferred to a microtask so the composer state it
|
||||
// touches settles outside the effect.
|
||||
const handleSubmitRef = useRef(handleSubmit);
|
||||
useEffect(() => {
|
||||
handleSubmitRef.current = handleSubmit;
|
||||
});
|
||||
useEffect(() => {
|
||||
if (!autoSend) return;
|
||||
if (autoSentRef.current) return;
|
||||
if (currentConversationId !== null) return;
|
||||
if (send.isStreaming) return;
|
||||
const seed = (prefill ?? "").trim();
|
||||
if (!seed) return;
|
||||
autoSentRef.current = true;
|
||||
queueMicrotask(() => {
|
||||
void handleSubmitRef.current(seed);
|
||||
});
|
||||
}, [autoSend, prefill, currentConversationId, send.isStreaming]);
|
||||
|
||||
// v1.22 — "Try again": regenerate an assistant reply by resubmitting the
|
||||
// user turn that produced it as a FRESH turn. The composer value is left
|
||||
// untouched (unlike `handleSubmit`, which clears it) so a half-typed
|
||||
|
||||
@@ -54,6 +54,11 @@ export interface CoachDrawerProps {
|
||||
* source(s) + window. Null → the route's default all-source snapshot.
|
||||
*/
|
||||
scope?: CoachLaunchScope | null;
|
||||
/**
|
||||
* When true, the conversation auto-sends `prefill` as its first turn
|
||||
* exactly once on open. Used by the assessment hand-off.
|
||||
*/
|
||||
autoSend?: boolean;
|
||||
}
|
||||
|
||||
export function CoachDrawer({
|
||||
@@ -61,6 +66,7 @@ export function CoachDrawer({
|
||||
onOpenChange,
|
||||
prefill,
|
||||
scope,
|
||||
autoSend,
|
||||
}: CoachDrawerProps) {
|
||||
const { t } = useTranslations();
|
||||
const router = useRouter();
|
||||
@@ -139,6 +145,7 @@ export function CoachDrawer({
|
||||
surface="drawer"
|
||||
prefill={prefill}
|
||||
launchScope={scope}
|
||||
autoSend={autoSend}
|
||||
autoFocusComposer
|
||||
registerReset={registerReset}
|
||||
// v1.16.1 — the "Conversations" affordance hands off to a
|
||||
|
||||
@@ -69,6 +69,11 @@ interface InsightStatusCardProps {
|
||||
*/
|
||||
coachQuestion?: string;
|
||||
coachScope?: CoachLaunchScope;
|
||||
/**
|
||||
* Auto-send the seeded opener as the first turn (assessment hand-off)
|
||||
* instead of only seeding the composer. Defaults to false.
|
||||
*/
|
||||
coachAutoSend?: boolean;
|
||||
}
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────
|
||||
@@ -83,6 +88,7 @@ export function InsightStatusCard({
|
||||
preparing = false,
|
||||
coachQuestion,
|
||||
coachScope,
|
||||
coachAutoSend,
|
||||
}: InsightStatusCardProps) {
|
||||
const { t } = useTranslations();
|
||||
const flags = useFeatureFlags();
|
||||
@@ -248,7 +254,11 @@ export function InsightStatusCard({
|
||||
caller supplied an opener. */}
|
||||
{coachQuestion ? (
|
||||
<div className="flex justify-end">
|
||||
<AskCoachAction question={coachQuestion} scope={coachScope} />
|
||||
<AskCoachAction
|
||||
question={coachQuestion}
|
||||
scope={coachScope}
|
||||
autoSend={coachAutoSend}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</CardContent>
|
||||
|
||||
@@ -56,6 +56,9 @@ export function LayoutCoachMount() {
|
||||
// opened from a metric surface or insight card is pre-narrowed to
|
||||
// the relevant source(s).
|
||||
scope={launch.scope}
|
||||
// Auto-send the prefill as the first turn when the launch requested it
|
||||
// (assessment hand-off), so the answer lands without a manual send.
|
||||
autoSend={launch.autoSend}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -46,12 +46,9 @@ export function MetricStatusCard({
|
||||
// carry a snapshot block. Unmapped metrics still get a metric-named
|
||||
// opener, just against the default snapshot.
|
||||
const coachSource = scopeSourceFromMetricKey(metric);
|
||||
const coachQuestion = `Walk me through my ${metric
|
||||
.toLowerCase()
|
||||
.replace(
|
||||
/_/g,
|
||||
" ",
|
||||
)} assessment — what does it mean and what should I do about it?`;
|
||||
const coachQuestion = t("insights.coach.assessmentPrompt", {
|
||||
metric: metric.toLowerCase().replace(/_/g, " "),
|
||||
});
|
||||
|
||||
return (
|
||||
<InsightStatusCard
|
||||
@@ -62,6 +59,7 @@ export function MetricStatusCard({
|
||||
updatedAt={status?.updatedAt ?? null}
|
||||
coachQuestion={coachQuestion}
|
||||
coachScope={coachSource ? { metric: coachSource } : undefined}
|
||||
coachAutoSend
|
||||
// Same hydration gate as `<SlugInsightStatusCard>`: the hook is
|
||||
// `enabled: isAuthenticated && enabled`, and both inputs can settle
|
||||
// before a late-hydrating boundary replays its first render — the
|
||||
|
||||
Reference in new issue
Block a user