Skip to content

Commit 3572971

Browse files
fedeinfeclaude
andcommitted
fix(web,mobile): question option previews are shown
Claude's AskUserQuestion options can carry a preview (mockup, snippet, image). The adapter and contract already pass it through, but neither question panel rendered it, so the reference never reached the user. Co-Authored-By: Claude <[email protected]>
1 parent 19a2bad commit 3572971

4 files changed

Lines changed: 96 additions & 52 deletions

File tree

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

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -247,44 +247,55 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
247247
const selected = isPendingUserInputOptionSelected(question, draft, optionValue);
248248
const description =
249249
option.description !== option.label ? option.description : undefined;
250+
const preview = option.preview?.trim();
250251
return (
251-
<Pressable
252-
key={optionValue}
253-
accessibilityRole={question.multiSelect ? "checkbox" : "radio"}
254-
accessibilityState={{ checked: selected, disabled: responseDisabled }}
255-
disabled={responseDisabled}
256-
className={cn(
257-
"min-h-12 w-full rounded-2xl border px-3.5 py-3",
258-
selected ? "border-primary bg-primary/10" : "border-border bg-input",
259-
)}
260-
onPress={() =>
261-
props.onSelectOption(
262-
props.pendingUserInput.requestId,
263-
question,
264-
optionValue,
265-
)
266-
}
267-
>
268-
<View className="min-w-0 flex-1 gap-0.5">
269-
<Text
270-
className={cn(
271-
"font-t3-bold text-sm",
272-
selected ? "text-foreground" : "text-foreground-secondary",
273-
)}
274-
style={proseDirectionStyle(option.label, setDirection)}
275-
>
276-
{option.label}
277-
</Text>
278-
{description ? (
252+
<View key={optionValue} className="gap-1.5">
253+
<Pressable
254+
accessibilityRole={question.multiSelect ? "checkbox" : "radio"}
255+
accessibilityState={{ checked: selected, disabled: responseDisabled }}
256+
disabled={responseDisabled}
257+
className={cn(
258+
"min-h-12 w-full rounded-2xl border px-3.5 py-3",
259+
selected ? "border-primary bg-primary/10" : "border-border bg-input",
260+
)}
261+
onPress={() =>
262+
props.onSelectOption(
263+
props.pendingUserInput.requestId,
264+
question,
265+
optionValue,
266+
)
267+
}
268+
>
269+
<View className="min-w-0 flex-1 gap-0.5">
279270
<Text
280-
className="font-sans text-sm leading-5 text-foreground-muted"
281-
style={proseDirectionStyle(description, setDirection)}
271+
className={cn(
272+
"font-t3-bold text-sm",
273+
selected ? "text-foreground" : "text-foreground-secondary",
274+
)}
275+
style={proseDirectionStyle(option.label, setDirection)}
282276
>
283-
{description}
277+
{option.label}
284278
</Text>
285-
) : null}
286-
</View>
287-
</Pressable>
279+
{description ? (
280+
<Text
281+
className="font-sans text-sm leading-5 text-foreground-muted"
282+
style={proseDirectionStyle(description, setDirection)}
283+
>
284+
{description}
285+
</Text>
286+
) : null}
287+
</View>
288+
</Pressable>
289+
{preview ? (
290+
<View className="mx-3.5 rounded-xl border border-border px-3 py-2">
291+
<QuestionText
292+
markdown={preview}
293+
environmentId={props.environmentId}
294+
setDirection={setDirection}
295+
/>
296+
</View>
297+
) : null}
298+
</View>
288299
);
289300
})}
290301
</View>

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
1111
type Question = {
1212
header: string;
1313
question: string;
14-
options: { label: string; description: string }[];
14+
options: { label: string; description: string; preview?: string }[];
1515
};
1616

1717
const renderPanel = (questions: Question[], questionIndex = 0) =>
@@ -98,3 +98,20 @@ it("keeps one direction for the whole set when a single question is Hebrew", asy
9898
.element(screen.getByText("גרסה 3 (חדשה!)", { exact: true }))
9999
.toHaveStyle({ direction: "rtl" });
100100
});
101+
102+
it("shows option previews next to their option, outside its button", async () => {
103+
await using screen = await renderPanel([
104+
{
105+
header: "Layout",
106+
question: "Which layout?",
107+
options: [
108+
{ label: "Sidebar", description: "Nav on the left", preview: "![Sidebar](mock.png)" },
109+
{ label: "Top bar", description: "Nav on top" },
110+
],
111+
},
112+
]);
113+
114+
const preview = screen.getByText("![Sidebar](mock.png)", { exact: true });
115+
await expect.element(preview).toBeVisible();
116+
expect(preview.element().closest("button")).toBeNull();
117+
});

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,35 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
310310
) : null}
311311
</>
312312
);
313+
const preview = option.preview?.trim();
313314
return (
314-
<button
315-
key={`${activeQuestion.id}:${optionValue}`}
316-
type="button"
317-
aria-pressed={isSelected}
318-
disabled={disabled || isResponding}
319-
onClick={() => {
320-
handleOptionSelection(activeQuestion.id, optionValue);
321-
}}
322-
className={className}
323-
>
324-
{content}
325-
</button>
315+
<div key={`${activeQuestion.id}:${optionValue}`}>
316+
<button
317+
type="button"
318+
aria-pressed={isSelected}
319+
disabled={disabled || isResponding}
320+
onClick={() => {
321+
handleOptionSelection(activeQuestion.id, optionValue);
322+
}}
323+
className={className}
324+
>
325+
{content}
326+
</button>
327+
{/* Outside the button: previews can hold links, and single-select advances on click. */}
328+
{preview ? (
329+
<div
330+
data-pending-user-input-option-preview
331+
className="mb-1.5 ms-9 me-9 rounded-md border border-border/60 bg-muted/20 px-3 py-2 sm:ms-8 sm:me-8"
332+
>
333+
<ChatMarkdown
334+
text={preview}
335+
cwd={cwd}
336+
threadRef={threadRef}
337+
className={cn("text-xs text-foreground/85", questionTextAlign)}
338+
/>
339+
</div>
340+
) : null}
341+
</div>
326342
);
327343
})}
328344
</div>

‎apps/web/src/pendingUserInput.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export function threadContextsReferencedByAnswer(
3232
return threadContexts.filter((record) => referencedIds.has(record.contextId));
3333
}
3434

35-
export interface PendingUserInputProgress {
35+
export interface PendingUserInputProgress<Question extends UserInputQuestion = UserInputQuestion> {
3636
questionIndex: number;
37-
activeQuestion: UserInputQuestion | null;
37+
activeQuestion: Question | null;
3838
activeDraft: PendingUserInputDraftAnswer | undefined;
3939
selectedOptionValues: ReadonlyArray<string>;
4040
customAnswer: string;
@@ -73,11 +73,11 @@ function countAnsweredPendingUserInputQuestions(
7373
}, 0);
7474
}
7575

76-
export function derivePendingUserInputProgress(
77-
questions: ReadonlyArray<UserInputQuestion>,
76+
export function derivePendingUserInputProgress<Question extends UserInputQuestion>(
77+
questions: ReadonlyArray<Question>,
7878
draftAnswers: Record<string, PendingUserInputDraftAnswer>,
7979
questionIndex: number,
80-
): PendingUserInputProgress {
80+
): PendingUserInputProgress<Question> {
8181
const normalizedQuestionIndex =
8282
questions.length === 0 ? 0 : Math.max(0, Math.min(questionIndex, questions.length - 1));
8383
const activeQuestion = questions[normalizedQuestionIndex] ?? null;

0 commit comments

Comments
 (0)