Skip to content

Commit a0b9b80

Browse files
voida6claude
andcommitted
fix(web): typed answer moved to the draft by an option click is announced
Clicking an option while a custom answer is typed moves that text into the thread draft so it is not lost. The question owns the composer, so the draft stayed out of sight and the text reappeared only after the question resolved. A toast, scoped to the thread, now says where the text went. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 6c21798 commit a0b9b80

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1414
default: (({ text }: { text: string }) => <p>{text}</p>) as never,
1515
}));
1616

17+
const toasts = vi.hoisted(() => ({ add: vi.fn() }));
18+
vi.mock(import("../ui/toast"), async (importOriginal) => {
19+
const actual = await importOriginal();
20+
return { ...actual, toastManager: { ...actual.toastManager, add: toasts.add } as never };
21+
});
22+
1723
import { act, fakeTimers, render } from "../../../test/render";
24+
import { useComposerDraftStore } from "../../composerDraftStore";
1825
import { makeThreadProjectionFixture } from "../../test-fixtures";
1926
import { usePendingThreadRequests } from "./usePendingThreadRequests";
2027

@@ -92,7 +99,8 @@ function PendingRequestsProbe({
9299
serverProjection: loading ? null : projection,
93100
supportsQuestionAttachments: false,
94101
composerDraftTarget: { environmentId, threadId: projection.thread.id },
95-
setComposerDraftPrompt: () => {},
102+
setComposerDraftPrompt: (target, prompt) =>
103+
useComposerDraftStore.getState().setPrompt(target, prompt),
96104
promptRef,
97105
composerRef,
98106
setThreadError: () => {},
@@ -138,6 +146,39 @@ it("retains answers, selections and question position after leaving chat, includ
138146
expect(requests).toMatchObject(expected);
139147
});
140148

149+
it("tells the user when an option click moves their typed answer into the hidden message draft", async () => {
150+
using _timers = fakeTimers();
151+
const environmentId = EnvironmentId.make("displaced-environment");
152+
const draftTarget = { environmentId, threadId: threadRef.threadId };
153+
const draftPrompt = () => useComposerDraftStore.getState().getComposerDraft(draftTarget)?.prompt;
154+
toasts.add.mockClear();
155+
await using _screen = await render(
156+
<PendingRequestsProbe
157+
environmentId={environmentId}
158+
projection={questionProjection(threadRef.threadId)}
159+
/>,
160+
);
161+
162+
await act(() => requests.onSelectActivePendingUserInputOption("question-0", "Incremental"));
163+
expect(toasts.add).not.toHaveBeenCalled();
164+
165+
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", "first try"));
166+
await act(() => requests.onSelectActivePendingUserInputOption("question-0", "Incremental"));
167+
expect(draftPrompt()).toBe("first try");
168+
expect(toasts.add).toHaveBeenCalledTimes(1);
169+
expect(toasts.add).toHaveBeenCalledWith(
170+
expect.objectContaining({ data: { threadRef: draftTarget } }),
171+
);
172+
173+
// Typing again replaces the option as the answer; the moved text stays put and is not announced twice.
174+
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", "second try"));
175+
expect(draftPrompt()).toBe("first try");
176+
expect(requests.activePendingDraftAnswers["question-0"]).toMatchObject({
177+
customAnswer: "second try",
178+
});
179+
expect(toasts.add).toHaveBeenCalledTimes(1);
180+
});
181+
141182
it("isolates drafts by environment, thread and request and discards only resolved requests", async () => {
142183
using _timers = fakeTimers();
143184
const environmentId = EnvironmentId.make("scope-environment");

‎apps/web/src/components/chat/usePendingThreadRequests.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { readEnvironmentScope } from "../../state/session";
5656
import { threadEnvironment } from "../../state/threads";
5757
import { useAtomCommand } from "../../state/use-atom-command";
5858
import { useOrchestrationCommand } from "../../state/use-orchestration-command";
59+
import { toastManager } from "../ui/toast";
5960
import type { ChatComposerHandle } from "./ChatComposer";
6061

6162
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
@@ -445,6 +446,13 @@ export function usePendingThreadRequests(input: {
445446
const nextPrompt = carryDisplacedCustomAnswerIntoPrompt(currentPrompt, displacedAnswer);
446447
if (nextPrompt !== currentPrompt) {
447448
setComposerDraftPrompt(composerDraftTarget, nextPrompt);
449+
// The question owns the box, so the draft is out of sight until it resolves.
450+
toastManager.add({
451+
type: "info",
452+
title: "Your typed text moved to the message draft",
453+
description: "It will be in the composer once the question is answered.",
454+
data: { threadRef: activeThreadId ? { environmentId, threadId: activeThreadId } : null },
455+
});
448456
if (activeThreadId) {
449457
const store = useComposerDraftStore.getState();
450458
const questionTarget = questionAttachmentDraftId(

0 commit comments

Comments
 (0)