Skip to content

Commit 16233e7

Browse files
voida6claudemaria-rcks
authored
fix(web): typed answer moved to the draft by an option click is announced (#24331)
Co-authored-by: Claude Sonnet 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 846de87 commit 16233e7

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1717
}));
1818

1919
import { act, fakeTimers, render } from "../../../test/render";
20+
import { useComposerDraftStore } from "../../composerDraftStore";
2021
import { makeThreadProjectionFixture } from "../../test-fixtures";
22+
import { toastManager } from "../ui/toast";
2123
import { usePendingThreadRequests } from "./usePendingThreadRequests";
2224

2325
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
@@ -89,7 +91,8 @@ function useProbeRequests({ environmentId, projection, loading = false }: ProbeP
8991
serverProjection: loading ? null : projection,
9092
supportsQuestionAttachments: false,
9193
composerDraftTarget: { environmentId, threadId: projection.thread.id },
92-
setComposerDraftPrompt: () => {},
94+
setComposerDraftPrompt: (target, prompt) =>
95+
useComposerDraftStore.getState().setPrompt(target, prompt),
9396
promptRef,
9497
composerRef,
9598
setThreadError: () => {},
@@ -141,6 +144,43 @@ it("retains answers, selections and question position after leaving chat, includ
141144
expect(requests).toMatchObject(expected);
142145
});
143146

147+
it("tells the user when an option click moves their typed answer into the hidden composer draft", async () => {
148+
using _timers = fakeTimers();
149+
const environmentId = EnvironmentId.make("displaced-environment");
150+
const draftTarget = { environmentId, threadId: threadRef.threadId };
151+
const draftPrompt = () => useComposerDraftStore.getState().getComposerDraft(draftTarget)?.prompt;
152+
using toast = vi.spyOn(toastManager, "add");
153+
await using _screen = await render(
154+
<PendingRequestsProbe
155+
environmentId={environmentId}
156+
projection={questionProjection(threadRef.threadId)}
157+
/>,
158+
);
159+
160+
await act(() => requests.onSelectActivePendingUserInputOption("question-0", "Incremental"));
161+
expect(toast).not.toHaveBeenCalled();
162+
163+
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", "first try"));
164+
await act(() => requests.onSelectActivePendingUserInputOption("question-0", "Incremental"));
165+
expect(draftPrompt()).toBe("first try");
166+
expect(toast).toHaveBeenCalledTimes(1);
167+
expect(toast).toHaveBeenCalledWith(
168+
expect.objectContaining({
169+
type: "info",
170+
title: "Your typed text was set aside",
171+
description: "It will be back in the composer once the question is answered.",
172+
data: { threadRef: draftTarget },
173+
}),
174+
);
175+
176+
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", "second try"));
177+
expect(draftPrompt()).toBe("first try");
178+
expect(requests.activePendingDraftAnswers["question-0"]).toMatchObject({
179+
customAnswer: "second try",
180+
});
181+
expect(toast).toHaveBeenCalledTimes(1);
182+
});
183+
144184
function QuestionPositionProbe(props: ProbeProps) {
145185
const state = useProbeRequests(props);
146186
return (

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import { readEnvironmentScope } from "../../state/session";
5050
import { threadEnvironment } from "../../state/threads";
5151
import { useAtomCommand } from "../../state/use-atom-command";
5252
import { useOrchestrationCommand } from "../../state/use-orchestration-command";
53+
import { toastManager } from "../ui/toast";
54+
5355
import type { ChatComposerHandle } from "./ChatComposer";
5456

5557
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
@@ -403,6 +405,12 @@ export function usePendingThreadRequests(input: {
403405
const nextPrompt = carryDisplacedCustomAnswerIntoPrompt(currentPrompt, displacedAnswer);
404406
if (nextPrompt !== currentPrompt) {
405407
setComposerDraftPrompt(composerDraftTarget, nextPrompt);
408+
toastManager.add({
409+
type: "info",
410+
title: "Your typed text was set aside",
411+
description: "It will be back in the composer once the question is answered.",
412+
data: { threadRef: activeThreadId ? { environmentId, threadId: activeThreadId } : null },
413+
});
406414
if (activeThreadId) {
407415
const store = useComposerDraftStore.getState();
408416
const questionTarget = questionAttachmentDraftId(

0 commit comments

Comments
 (0)