diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 08b682e8bc0fe..e444e8a6ca020 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1497,7 +1497,6 @@ export default function ChatView(props: ChatViewProps) { onSelectActivePendingUserInputOption: onSelectActivePendingUserInputOptionStable, onChangeActivePendingUserInputCustomAnswer, onAdvanceActivePendingUserInput, - onAdvanceActivePendingUserInputStable, onPreviousActivePendingUserInputQuestion: onPreviousActivePendingUserInputQuestionStable, } = usePendingThreadRequests({ environmentId, @@ -4015,9 +4014,6 @@ export default function ChatView(props: ChatViewProps) { onSelectActivePendingUserInputOption={ onSelectActivePendingUserInputOptionStable } - onAdvanceActivePendingUserInput={ - onAdvanceActivePendingUserInputStable - } onDismissActivePendingUserInput={onDismissUserInputStable} onPreviousActivePendingUserInputQuestion={ onPreviousActivePendingUserInputQuestionStable diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 7bd5c72cd5ca7..b36d045b26b16 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -515,7 +515,6 @@ export interface ChatComposerProps { onResume: () => void; onInterrupt: () => void; onSelectActivePendingUserInputOption: (questionId: string, optionValue: string) => void; - onAdvanceActivePendingUserInput: () => void; onDismissActivePendingUserInput: (requestId: RuntimeRequestId) => void; onPreviousActivePendingUserInputQuestion: () => void; onChangeActivePendingUserInputCustomAnswer: ( @@ -618,7 +617,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) onResume, onInterrupt, onSelectActivePendingUserInputOption, - onAdvanceActivePendingUserInput, onDismissActivePendingUserInput, onPreviousActivePendingUserInputQuestion, onChangeActivePendingUserInputCustomAnswer, @@ -3839,7 +3837,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) answers={activePendingDraftAnswers} questionIndex={activePendingQuestionIndex} onToggleOption={onSelectActivePendingUserInputOption} - onAdvance={onAdvanceActivePendingUserInput} onDismiss={onDismissActivePendingUserInput} /> ) : null} diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.browser.test.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.browser.test.tsx index 817ffd7a42990..6f6714b96dd4e 100644 --- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.browser.test.tsx +++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.browser.test.tsx @@ -36,7 +36,6 @@ function panel(onToggleOption: (questionId: string, optionValue: string) => void answers={{}} questionIndex={0} onToggleOption={onToggleOption} - onAdvance={vi.fn()} onDismiss={vi.fn()} /> ); diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.direction.browser.test.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.direction.browser.test.tsx index d6afda300e2b7..85a3bbf435a0e 100644 --- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.direction.browser.test.tsx +++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.direction.browser.test.tsx @@ -36,7 +36,6 @@ const renderPanel = (questions: Question[], questionIndex = 0) => answers={{}} questionIndex={questionIndex} onToggleOption={() => {}} - onAdvance={() => {}} onDismiss={() => {}} />, ); diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx index 9abda3c246362..dd8da7c9271c6 100644 --- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx +++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx @@ -21,6 +21,7 @@ import { DraftId, useComposerDraftStore } from "../../composerDraftStore"; import { makeThreadProjectionFixture } from "../../test-fixtures"; import { toastManager } from "../ui/toast"; import { usePendingThreadRequests, usePendingUserInputDraft } from "./usePendingThreadRequests"; +import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel"; const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") }; @@ -33,7 +34,10 @@ const prompt = { id: `question-${index}`, header: `Question ${index + 1}`, question: `Choose for question ${index + 1}`, - options: [{ label: "Incremental", description: "One module at a time" }], + options: [ + { label: "Incremental", description: "One module at a time" }, + { label: "All at once", description: "One release" }, + ], multiSelect: false, })), }; @@ -217,12 +221,16 @@ function QuestionPositionProbe(props: ProbeProps) { return ( <> Question {state.activePendingQuestionIndex + 1} - + @@ -230,18 +238,31 @@ function QuestionPositionProbe(props: ProbeProps) { ); } -it("stays on an unanswered question when the composer submits", async () => { +it("waits for explicit confirmation and lets the user correct a question's selection", async () => { await using screen = await render( , ); + using _timers = fakeTimers(); const submit = screen.getByRole("button", { name: "Submit" }); await userEvent.click(submit); await expect.element(screen.getByRole("status")).toHaveTextContent("Question 1"); - await userEvent.click(screen.getByRole("button", { name: "Choose Incremental" })); + const incremental = screen.getByRole("button", { name: /Incremental/ }); + const allAtOnce = screen.getByRole("button", { name: /All at once/ }); + await userEvent.click(incremental); + await act(() => vi.advanceTimersByTimeAsync(250)); + await expect.element(screen.getByRole("status")).toHaveTextContent("Question 1"); + await expect.element(incremental).toHaveAttribute("aria-pressed", "true"); + + await userEvent.keyboard("2"); + await act(() => vi.advanceTimersByTimeAsync(250)); + await expect.element(screen.getByRole("status")).toHaveTextContent("Question 1"); + await expect.element(incremental).toHaveAttribute("aria-pressed", "false"); + await expect.element(allAtOnce).toHaveAttribute("aria-pressed", "true"); + await userEvent.click(submit); await expect.element(screen.getByRole("status")).toHaveTextContent("Question 2"); }); diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx index a720459cac76a..7e87de25368b3 100644 --- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx +++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx @@ -1,9 +1,8 @@ import { type RuntimeRequestId, type ScopedThreadRef } from "@t3tools/contracts"; import { markdownProseDirection, textDirection } from "~/textDirection"; import { useGT } from "gt-react"; -import { memo, use, useEffect, useEffectEvent, useRef, useState } from "react"; +import { memo, use, useEffect, useEffectEvent, useState } from "react"; import { BackgroundThreadContext } from "./backgroundThread"; -import { useStableCallback } from "~/hooks/useStableCallback"; import { type PendingUserInput } from "../../session-logic"; import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input"; import { derivePendingUserInputProgress } from "../../pendingUserInput"; @@ -25,7 +24,6 @@ interface PendingUserInputPanelProps { answers: Record; questionIndex: number; onToggleOption: (questionId: string, optionValue: string) => void; - onAdvance: () => void; onDismiss: (requestId: RuntimeRequestId) => void; } @@ -38,7 +36,6 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn answers, questionIndex, onToggleOption, - onAdvance, onDismiss, }: PendingUserInputPanelProps) { if (pendingUserInputs.length === 0) return null; @@ -56,7 +53,6 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn answers={answers} questionIndex={questionIndex} onToggleOption={onToggleOption} - onAdvance={onAdvance} onDismiss={onDismiss} /> ); @@ -71,7 +67,6 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( answers, questionIndex, onToggleOption, - onAdvance, onDismiss, }: { prompt: PendingUserInput; @@ -82,19 +77,12 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( answers: Record; questionIndex: number; onToggleOption: (questionId: string, optionValue: string) => void; - onAdvance: () => void; onDismiss: (requestId: RuntimeRequestId) => void; }) { const gt = useGT(); // Message-mode requests remain answerable after their provider turn ends. const canRespond = prompt.responseCapability !== "not_resumable"; const responseDisabled = disabled || isResponding || !canRespond; - const autoAdvanceTimerRef = useRef(null); - const advance = useStableCallback(onAdvance); - const [optimisticSingleSelect, setOptimisticSingleSelect] = useState<{ - questionId: string; - optionValue: string; - } | null>(null); const [collapsedQuestionId, setCollapsedQuestionId] = useState(null); // Keep question identity stable for its shortcut listener. const progress = derivePendingUserInputProgress(prompt.questions, answers, questionIndex); @@ -107,44 +95,9 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( ); const isCollapsed = collapsedQuestionId !== null && collapsedQuestionId === activeQuestion?.id; - if ( - optimisticSingleSelect && - activeQuestion && - !activeQuestion.multiSelect && - (optimisticSingleSelect.questionId !== activeQuestion.id || - (!customAnswerActive && - progress.selectedOptionValues.includes(optimisticSingleSelect.optionValue))) - ) { - setOptimisticSingleSelect(null); - } - - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the auto-advance timer when the question changes, input is disabled, or the panel unmounts - useEffect(() => { - const clearAutoAdvance = () => { - if (autoAdvanceTimerRef.current !== null) { - window.clearTimeout(autoAdvanceTimerRef.current); - autoAdvanceTimerRef.current = null; - } - }; - if (disabled || activeQuestion?.id === undefined) clearAutoAdvance(); - return clearAutoAdvance; - }, [activeQuestion?.id, disabled]); - const handleOptionSelection = (questionId: string, optionValue: string) => { - if (disabled || isResponding) return; - if (activeQuestion?.multiSelect) { - onToggleOption(questionId, optionValue); - return; - } - setOptimisticSingleSelect({ questionId, optionValue }); + if (responseDisabled) return; onToggleOption(questionId, optionValue); - if (autoAdvanceTimerRef.current !== null) { - window.clearTimeout(autoAdvanceTimerRef.current); - } - autoAdvanceTimerRef.current = window.setTimeout(() => { - autoAdvanceTimerRef.current = null; - advance(); - }, 200); }; const selectOptionFromShortcut = useEffectEvent(handleOptionSelection); @@ -276,11 +229,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
{activeQuestion.options.map((option, index) => { const optionValue = option.value ?? option.label; - const isOptimisticallySelected = - optimisticSingleSelect?.questionId === activeQuestion.id && - optimisticSingleSelect.optionValue === optionValue; - const isSelected = - isOptimisticallySelected || draftSelectedOptions?.[index] === true; + const isSelected = draftSelectedOptions?.[index] === true; const className = cn( questionTextAlign, "group flex w-full items-start gap-2.5 rounded-md bg-transparent py-1.5 ps-2 sm:ps-1.5 outline-none transition-colors duration-150 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary/25", @@ -318,7 +267,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( ) : null} ); - // The preview sits outside the button: it can hold links, and a click on a single-select option advances. + // The preview sits outside the button because it can hold links. return (