History

fix(web): keep multi-select questions open after the first click (#6646)

RaitP1 committed 3 months ago

Commit 1a5ff421 parent b72d5d71 file · +19 −16Browse files

Unified · Split

apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx+19−16
@@ -1,5 +1,5 @@
11 import { type ApprovalRequestId } from "@t3tools/contracts";
2−import { memo, useEffect, useEffectEvent, useRef, useState } from "react";
2+import { memo, useCallback, useEffect, useRef, useState } from "react";
33 import { type PendingUserInput } from "../../session-logic";
44 import {
55 derivePendingUserInputProgress,
@@ -109,21 +109,24 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( · 103 unmodified lines
109109 };
110110 }, []);
111111
112− const handleOptionSelection = useEffectEvent((questionId: string, optionLabel: string) => {
113− if (activeQuestion?.multiSelect) {
112+ const handleOptionSelection = useCallback(
113+ (questionId: string, optionLabel: string) => {
114+ if (activeQuestion?.multiSelect) {
115+ onToggleOption(questionId, optionLabel);
116+ return;
117+ }
118+ setOptimisticSingleSelect({ questionId, optionLabel });
114119 onToggleOption(questionId, optionLabel);
115− return;
116− }
117− setOptimisticSingleSelect({ questionId, optionLabel });
118− onToggleOption(questionId, optionLabel);
119− if (autoAdvanceTimerRef.current !== null) {
120− window.clearTimeout(autoAdvanceTimerRef.current);
121− }
122− autoAdvanceTimerRef.current = window.setTimeout(() => {
123− autoAdvanceTimerRef.current = null;
124− onAdvanceRef.current();
125− }, 200);
126− });
120+ if (autoAdvanceTimerRef.current !== null) {
121+ window.clearTimeout(autoAdvanceTimerRef.current);
122+ }
123+ autoAdvanceTimerRef.current = window.setTimeout(() => {
124+ autoAdvanceTimerRef.current = null;
125+ onAdvanceRef.current();
126+ }, 200);
127+ },
128+ [activeQuestion, onToggleOption],
129+ );
127130
128131 // Keyboard shortcut: number keys 1-9 select corresponding options when focus is
129132 // outside editable fields. Multi-select prompts toggle options in place; single-
@@ -154,7 +157,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( · 24 unmodified lines
154157 };
155158 document.addEventListener("keydown", handler);
156159 return () => document.removeEventListener("keydown", handler);
157− }, [activeQuestion, isCollapsed, isResponding]);
160+ }, [activeQuestion, handleOptionSelection, isCollapsed, isResponding]);
158161
159162 if (!activeQuestion) {
160163 return null;