| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | import { type ApprovalRequestId } from "@t3tools/contracts"; | 1 | import { type ApprovalRequestId } from "@t3tools/contracts"; |
| 2 | import { memo, useEffect, useEffectEvent, useRef, useState } from "react"; | 2 | import { memo, useCallback, useEffect, useRef, useState } from "react"; |
| 3 | import { type PendingUserInput } from "../../session-logic"; | 3 | import { type PendingUserInput } from "../../session-logic"; |
| 4 | import { | 4 | import { |
| 5 | derivePendingUserInputProgress, | 5 | derivePendingUserInputProgress, |
| ... | @@ -109,21 +109,24 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( | ... | @@ -109,21 +109,24 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( |
| 109 | }; | 109 | }; |
| 110 | }, []); | 110 | }, []); |
| 111 | | 111 | |
| 112 | const handleOptionSelection = useEffectEvent((questionId: string, optionLabel: string) => { | 112 | const handleOptionSelection = useCallback( |
| 113 | if (activeQuestion?.multiSelect) { | 113 | (questionId: string, optionLabel: string) => { |
| | 114 | if (activeQuestion?.multiSelect) { |
| | 115 | onToggleOption(questionId, optionLabel); |
| | 116 | return; |
| | 117 | } |
| | 118 | setOptimisticSingleSelect({ questionId, optionLabel }); |
| 114 | onToggleOption(questionId, optionLabel); | 119 | onToggleOption(questionId, optionLabel); |
| 115 | return; | 120 | if (autoAdvanceTimerRef.current !== null) { |
| 116 | } | 121 | window.clearTimeout(autoAdvanceTimerRef.current); |
| 117 | setOptimisticSingleSelect({ questionId, optionLabel }); | 122 | } |
| 118 | onToggleOption(questionId, optionLabel); | 123 | autoAdvanceTimerRef.current = window.setTimeout(() => { |
| 119 | if (autoAdvanceTimerRef.current !== null) { | 124 | autoAdvanceTimerRef.current = null; |
| 120 | window.clearTimeout(autoAdvanceTimerRef.current); | 125 | onAdvanceRef.current(); |
| 121 | } | 126 | }, 200); |
| 122 | autoAdvanceTimerRef.current = window.setTimeout(() => { | 127 | }, |
| 123 | autoAdvanceTimerRef.current = null; | 128 | [activeQuestion, onToggleOption], |
| 124 | onAdvanceRef.current(); | 129 | ); |
| 125 | }, 200); | | |
| 126 | }); | | |
| 127 | | 130 | |
| 128 | // Keyboard shortcut: number keys 1-9 select corresponding options when focus is | 131 | // Keyboard shortcut: number keys 1-9 select corresponding options when focus is |
| 129 | // outside editable fields. Multi-select prompts toggle options in place; single- | 132 | // outside editable fields. Multi-select prompts toggle options in place; single- |
| ... | @@ -154,7 +157,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( | ... | @@ -154,7 +157,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard( |
| 154 | }; | 157 | }; |
| 155 | document.addEventListener("keydown", handler); | 158 | document.addEventListener("keydown", handler); |
| 156 | return () => document.removeEventListener("keydown", handler); | 159 | return () => document.removeEventListener("keydown", handler); |
| 157 | }, [activeQuestion, isCollapsed, isResponding]); | 160 | }, [activeQuestion, handleOptionSelection, isCollapsed, isResponding]); |
| 158 | | 161 | |
| 159 | if (!activeQuestion) { | 162 | if (!activeQuestion) { |
| 160 | return null; | 163 | return null; |