Skip to content

Commit 8eafe05

Browse files
t3dotggclaude
andauthored
revert: "fix(clients): show question option previews" (pingdotgg#21933) (pingdotgg#22229)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b14ae64 commit 8eafe05

4 files changed

Lines changed: 17 additions & 238 deletions

File tree

‎apps/mobile/src/features/threads/PendingUserInputCard.tsx‎

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button } from "../../components/ui/Button";
22
import { QuestionAttachments } from "./QuestionAttachments";
33
import type { RuntimeRequestId } from "@t3tools/contracts";
44
import type { ThreadUserInputQuestion } from "@t3tools/client-runtime/state/thread-requests";
5-
import { useCallback, useRef, useState } from "react";
5+
import { useCallback, useRef } from "react";
66
import { Platform, Pressable, ScrollView, View, type LayoutChangeEvent } from "react-native";
77
import Animated, {
88
Easing,
@@ -79,22 +79,6 @@ function QuestionText(props: { readonly markdown: string }) {
7979
}
8080

8181
export function PendingUserInputCard(props: PendingUserInputCardProps) {
82-
const [focusedOption, setFocusedOption] = useState<{
83-
requestId: RuntimeRequestId;
84-
questionId: string;
85-
optionIndex: number;
86-
} | null>(null);
87-
const focusedQuestion = props.pendingUserInput.questions.find(
88-
(question) => question.id === focusedOption?.questionId,
89-
);
90-
if (
91-
focusedOption &&
92-
(focusedOption.requestId !== props.pendingUserInput.requestId ||
93-
!focusedQuestion ||
94-
(props.drafts[focusedQuestion.id]?.customAnswer?.trim().length ?? 0) > 0)
95-
) {
96-
setFocusedOption(null);
97-
}
9882
const questionCount = props.pendingUserInput.questions.length;
9983
const canRespond = props.pendingUserInput.responseCapability !== "not_resumable";
10084
const isResponding = props.respondingUserInputId === props.pendingUserInput.requestId;
@@ -254,55 +238,35 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
254238
) : null}
255239
{props.pendingUserInput.questions.map((question) => {
256240
const draft = props.drafts[question.id];
257-
const customAnswerActive = (draft?.customAnswer?.trim().length ?? 0) > 0;
258-
const selectedOptionValue = draft?.selectedOptionValues?.at(-1);
259-
const savedOptionMatches = question.options.filter(
260-
(option) => (option.value ?? option.label.trim()) === selectedOptionValue,
261-
);
262-
const previewOption = customAnswerActive
263-
? undefined
264-
: focusedOption?.requestId === props.pendingUserInput.requestId &&
265-
focusedOption.questionId === question.id
266-
? question.options[focusedOption.optionIndex]
267-
: savedOptionMatches.length === 1
268-
? savedOptionMatches[0]
269-
: undefined;
270241
return (
271242
<View key={question.id} className="gap-2 pt-1">
272243
<Text className="font-t3-bold text-xs uppercase tracking-[1px] text-foreground-muted">
273244
{question.header}
274245
</Text>
275246
<QuestionText markdown={question.question} />
276247
<View className="gap-2">
277-
{question.options.map((option, optionIndex) => {
248+
{question.options.map((option) => {
278249
const optionValue = option.value ?? option.label.trim();
279250
const selected = isPendingUserInputOptionSelected(question, draft, optionValue);
280251
const description =
281252
option.description !== option.label ? option.description : undefined;
282253
return (
283254
<Pressable
284-
// Options keep their positions within a question and may share answer values.
285-
// oxlint-disable-next-line react/no-array-index-key
286-
key={`${question.id}:${optionIndex}`}
255+
key={optionValue}
287256
accessibilityRole={question.multiSelect ? "checkbox" : "radio"}
288257
accessibilityState={{ checked: selected, disabled: responseDisabled }}
289258
disabled={responseDisabled}
290259
className={cn(
291260
"min-h-12 w-full rounded-2xl border px-3.5 py-3",
292261
selected ? "border-primary bg-primary/10" : "border-border bg-input",
293262
)}
294-
onPress={() => {
295-
setFocusedOption({
296-
requestId: props.pendingUserInput.requestId,
297-
questionId: question.id,
298-
optionIndex,
299-
});
263+
onPress={() =>
300264
props.onSelectOption(
301265
props.pendingUserInput.requestId,
302266
question,
303267
optionValue,
304-
);
305-
}}
268+
)
269+
}
306270
>
307271
<View className="min-w-0 flex-1 gap-0.5">
308272
<Text
@@ -323,29 +287,16 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
323287
);
324288
})}
325289
</View>
326-
{previewOption?.preview?.trim() ? (
327-
<View className="gap-1.5 rounded-2xl border border-border bg-input p-3.5">
328-
<Text className="font-t3-bold text-xs text-foreground-muted">
329-
Preview · {previewOption.label}
330-
</Text>
331-
<QuestionText markdown={previewOption.preview} />
332-
</View>
333-
) : null}
334290
{question.allowCustomAnswer !== false ? (
335291
<QuestionAttachments
336292
requestId={props.pendingUserInput.requestId}
337293
question={question}
338294
questions={props.pendingUserInput.questions}
339295
disabled={responseDisabled}
340296
value={draft?.customAnswer ?? ""}
341-
onChangeText={(value) => {
342-
setFocusedOption(null);
343-
props.onChangeCustomAnswer(
344-
props.pendingUserInput.requestId,
345-
question.id,
346-
value,
347-
);
348-
}}
297+
onChangeText={(value) =>
298+
props.onChangeCustomAnswer(props.pendingUserInput.requestId, question.id, value)
299+
}
349300
onInputFocusChange={props.onInputFocusChange}
350301
/>
351302
) : null}

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

Lines changed: 3 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import { createRoot, type Root } from "react-dom/client";
1111
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
1212

1313
import {
14-
setPendingUserInputCustomAnswer,
1514
togglePendingUserInputOptionSelection,
1615
type PendingUserInputDraftAnswer,
1716
} from "../../pendingUserInput";
18-
import type { PendingUserInput } from "../../session-logic";
1917

2018
vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
2119
...(await importOriginal()),
@@ -42,48 +40,17 @@ const prompt = {
4240
})),
4341
};
4442

45-
const previewPrompt = {
46-
...prompt,
47-
questions: prompt.questions.map((question, index) => ({
48-
...question,
49-
options: ["First", "Second"].map((label) => ({
50-
label,
51-
value: index === 1 ? label : "same-answer",
52-
description: "",
53-
preview: `Preview body: ${label}, question ${index + 1}`,
54-
})),
55-
})),
56-
};
57-
58-
function Questions({
59-
initialIndex = 0,
60-
pendingPrompt = prompt,
61-
}: {
62-
initialIndex?: number;
63-
pendingPrompt?: PendingUserInput;
64-
}) {
43+
function Questions({ initialIndex = 0 }: { initialIndex?: number }) {
6544
const [questionIndex, setQuestionIndex] = useState(initialIndex);
6645
const [answers, setAnswers] = useState<Record<string, PendingUserInputDraftAnswer>>({});
67-
const question = pendingPrompt.questions[questionIndex]!;
6846
const advance = () => setQuestionIndex(questionIndex + 1);
6947
return (
7048
<>
7149
<output>{questionIndex}</output>
7250
<button onClick={advance}>Next</button>
7351
<button onClick={() => setQuestionIndex(questionIndex - 1)}>Previous</button>
74-
<input
75-
aria-label="Custom answer"
76-
value={answers[question.id]?.customAnswer ?? ""}
77-
onChange={(event) => {
78-
const value = event.currentTarget.value;
79-
setAnswers((existing) => ({
80-
...existing,
81-
[question.id]: setPendingUserInputCustomAnswer(existing[question.id], value, question),
82-
}));
83-
}}
84-
/>
8552
<ComposerPendingUserInputPanel
86-
pendingUserInputs={[pendingPrompt]}
53+
pendingUserInputs={[prompt]}
8754
cwd="/repo"
8855
threadRef={threadRef}
8956
disabled={false}
@@ -92,7 +59,7 @@ function Questions({
9259
questionIndex={questionIndex}
9360
onAdvance={advance}
9461
onToggleOption={(questionId, value) => {
95-
const question = pendingPrompt.questions.find((entry) => entry.id === questionId)!;
62+
const question = prompt.questions.find((entry) => entry.id === questionId)!;
9663
setAnswers((existing) => ({
9764
...existing,
9865
[questionId]: togglePendingUserInputOptionSelection(
@@ -325,94 +292,3 @@ it("isolates drafts by environment, thread and request and discards only resolve
325292
);
326293
}
327294
});
328-
329-
function expectPreview(text: string | null) {
330-
const previews = [...container.querySelectorAll("p")]
331-
.map((element) => element.textContent)
332-
.filter((content) => content?.startsWith("Preview body:"));
333-
expect(previews).toEqual(text === null ? [] : [`Preview body: ${text}`]);
334-
}
335-
336-
async function typeCustomAnswer(value: string) {
337-
const input = container.querySelector("input")!;
338-
await act(async () => {
339-
input.focus();
340-
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, value);
341-
input.dispatchEvent(new Event("input", { bubbles: true }));
342-
});
343-
}
344-
345-
it("previews options by focus, click, and shortcut index but only restores unambiguous saved selections", async () => {
346-
await act(async () => root.render(<Questions pendingPrompt={previewPrompt} />));
347-
expectPreview("First, question 1");
348-
349-
await act(async () => buttonWithText("Second").focus());
350-
expectPreview("Second, question 1");
351-
await act(async () => buttonWithText("First").focus());
352-
expectPreview("First, question 1");
353-
354-
await act(async () => buttonWithText("Second").click());
355-
expectPreview("Second, question 1");
356-
await act(async () => document.dispatchEvent(new KeyboardEvent("keydown", { key: "1" })));
357-
expectPreview("First, question 1");
358-
await act(async () => document.dispatchEvent(new KeyboardEvent("keydown", { key: "2" })));
359-
expectPreview("Second, question 1");
360-
361-
await act(async () => vi.advanceTimersByTime(200));
362-
expect(activeIndex()).toBe("1");
363-
expectPreview("First, question 2");
364-
365-
await act(async () => buttonWithText("Second").focus());
366-
expectPreview("Second, question 2");
367-
await act(async () =>
368-
root.render(
369-
<Questions
370-
pendingPrompt={{ ...previewPrompt, requestId: RuntimeRequestId.make("replacement") }}
371-
/>,
372-
),
373-
);
374-
expectPreview("First, question 2");
375-
376-
await act(async () => buttonWithText("Second").click());
377-
expectPreview("Second, question 2");
378-
await navigate("Next");
379-
expectPreview("First, question 3");
380-
await navigate("Previous");
381-
expectPreview("Second, question 2");
382-
383-
await navigate("Previous");
384-
expectPreview(null);
385-
await act(async () =>
386-
root.render(
387-
<Questions
388-
pendingPrompt={{ ...previewPrompt, requestId: RuntimeRequestId.make("remounted") }}
389-
/>,
390-
),
391-
);
392-
expectPreview(null);
393-
await act(async () => buttonWithText("Second").click());
394-
expectPreview("Second, question 1");
395-
});
396-
397-
it("hides and clears hovered or focused previews while a custom answer is active", async () => {
398-
await act(async () => root.render(<Questions pendingPrompt={previewPrompt} />));
399-
await act(async () =>
400-
buttonWithText("Second").dispatchEvent(new MouseEvent("mouseover", { bubbles: true })),
401-
);
402-
expectPreview("Second, question 1");
403-
404-
await typeCustomAnswer("Use a different approach");
405-
expectPreview(null);
406-
await typeCustomAnswer("");
407-
expectPreview("First, question 1");
408-
409-
await typeCustomAnswer("Use a different approach");
410-
await act(async () => buttonWithText("Second").focus());
411-
expectPreview(null);
412-
await act(async () =>
413-
buttonWithText("Second").dispatchEvent(new MouseEvent("mouseover", { bubbles: true })),
414-
);
415-
expectPreview(null);
416-
await typeCustomAnswer("");
417-
expectPreview("First, question 1");
418-
});

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
9191
questionId: string;
9292
optionValue: string;
9393
} | null>(null);
94-
const [focusedOption, setFocusedOption] = useState<{
95-
questionId: string;
96-
optionIndex: number;
97-
} | null>(null);
9894
const [collapsedQuestionId, setCollapsedQuestionId] = useState<string | null>(null);
9995
// The active question keys the shortcut listener, so it must keep its identity across renders.
10096
const progress = derivePendingUserInputProgress(prompt.questions, answers, questionIndex);
@@ -106,23 +102,6 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
106102
!customAnswerActive && progress.selectedOptionValues.includes(option.value ?? option.label),
107103
);
108104
const isCollapsed = collapsedQuestionId !== null && collapsedQuestionId === activeQuestion?.id;
109-
const selectedOptionValue = progress.selectedOptionValues.at(-1);
110-
const savedOptionMatches = activeQuestion?.options.filter(
111-
(option) => (option.value ?? option.label) === selectedOptionValue,
112-
);
113-
const previewOption = customAnswerActive
114-
? undefined
115-
: focusedOption && focusedOption.questionId === activeQuestion?.id
116-
? activeQuestion?.options[focusedOption.optionIndex]
117-
: selectedOptionValue === undefined
118-
? activeQuestion?.options[0]
119-
: savedOptionMatches?.length === 1
120-
? savedOptionMatches[0]
121-
: undefined;
122-
123-
if (focusedOption && (focusedOption.questionId !== activeQuestion?.id || customAnswerActive)) {
124-
setFocusedOption(null);
125-
}
126105

127106
// The optimistic pick is dropped once the draft confirms it or the question moves on.
128107
if (
@@ -148,9 +127,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
148127
return clearAutoAdvance;
149128
}, [activeQuestion?.id, disabled]);
150129

151-
const handleOptionSelection = (questionId: string, optionValue: string, optionIndex: number) => {
130+
const handleOptionSelection = (questionId: string, optionValue: string) => {
152131
if (disabled || isResponding) return;
153-
setFocusedOption({ questionId, optionIndex });
154132
if (activeQuestion?.multiSelect) {
155133
onToggleOption(questionId, optionValue);
156134
return;
@@ -189,7 +167,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
189167
const option = activeQuestion.options[optionIndex];
190168
if (!option) return;
191169
event.preventDefault();
192-
selectOptionFromShortcut(activeQuestion.id, option.value ?? option.label, optionIndex);
170+
selectOptionFromShortcut(activeQuestion.id, option.value ?? option.label);
193171
};
194172
document.addEventListener("keydown", handler);
195173
return () => document.removeEventListener("keydown", handler);
@@ -305,19 +283,11 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
305283
);
306284
return (
307285
<button
308-
// Options keep their positions within a question and may share answer values.
309-
// oxlint-disable-next-line react/no-array-index-key
310-
key={`${activeQuestion.id}:${index}`}
286+
key={`${activeQuestion.id}:${optionValue}`}
311287
type="button"
312288
disabled={disabled || isResponding}
313-
onMouseEnter={() =>
314-
setFocusedOption({ questionId: activeQuestion.id, optionIndex: index })
315-
}
316-
onFocus={() =>
317-
setFocusedOption({ questionId: activeQuestion.id, optionIndex: index })
318-
}
319289
onClick={() => {
320-
handleOptionSelection(activeQuestion.id, optionValue, index);
290+
handleOptionSelection(activeQuestion.id, optionValue);
321291
}}
322292
className={className}
323293
>
@@ -326,23 +296,6 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
326296
);
327297
})}
328298
</div>
329-
{previewOption?.preview?.trim() ? (
330-
<section
331-
aria-label={`Preview: ${previewOption.label}`}
332-
className="mt-2 min-w-0 rounded-md border border-border/60 bg-muted/25 p-2.5"
333-
>
334-
<p className="mb-1.5 text-3xs font-medium text-muted-foreground">
335-
Preview · {previewOption.label}
336-
</p>
337-
<ChatMarkdown
338-
key={`${activeQuestion.id}:${activeQuestion.options.indexOf(previewOption)}`}
339-
text={previewOption.preview}
340-
cwd={cwd}
341-
threadRef={threadRef}
342-
parseRawHtml={false}
343-
/>
344-
</section>
345-
) : null}
346299
</ComposerBanner.Body>
347300
</ComposerBanner.Scroll>
348301
</CollapsiblePanel>

0 commit comments

Comments
 (0)