Skip to content

Commit f656241

Browse files
fix: Disable send button until speech recording stopped (#1131)
1 parent 89d5b3f commit f656241

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

code/frontend/src/components/QuestionInput/QuestionInput.module.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
height: 23px;
3636
}
3737

38+
.SendButtonDisabled{
39+
pointer-events: none;
40+
width: 24px;
41+
height: 23px;
42+
margin-right: 12px;
43+
}
44+
3845
.questionInputSendButtonDisabled {
3946
/* opacity: 0.4; */
4047
width: 24px;
@@ -60,6 +67,10 @@
6067
height: 30px;
6168
}
6269

70+
.microphoneIcon ,.microphoneIconActive{
71+
height: 1.3em;
72+
}
73+
6374
.questionInputMicrophone {
6475
width: 24px;
6576
height: 24px;
@@ -70,8 +81,11 @@
7081
display: flex;
7182
flex-direction: column;
7283
align-items: center;
73-
margin-right: 12px;
74-
margin-top: 25px;
84+
margin-right: 1rem;
85+
margin-top: 0.3rem;
86+
width: 3%;
87+
min-width: 3%;
88+
height: 70px;
7589
}
7690

7791

code/frontend/src/components/QuestionInput/QuestionInput.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props {
1111
onMicrophoneClick: () => void;
1212
onStopClick: () => void;
1313
disabled: boolean;
14+
isSendButtonDisabled:boolean;
1415
placeholder?: string;
1516
clearOnSend?: boolean;
1617
recognizedText: string;
@@ -24,6 +25,7 @@ export const QuestionInput = ({
2425
onMicrophoneClick,
2526
onStopClick,
2627
disabled,
28+
isSendButtonDisabled,
2729
placeholder,
2830
clearOnSend,
2931
recognizedText,
@@ -131,26 +133,28 @@ export const QuestionInput = ({
131133
</div>
132134

133135
{/* Send Button */}
134-
<div
135-
role="button"
136-
tabIndex={0}
137-
aria-label="Ask question button"
138-
onClick={sendQuestion}
139-
onKeyDown={(e) =>
140-
e.key === "Enter" || e.key === " " ? sendQuestion() : null
141-
}
142-
className={styles.questionInputSendButtonContainer}
143-
>
144-
{disabled ? (
145-
<SendRegular className={styles.questionInputSendButtonDisabled} />
146-
) : (
147-
<img
148-
src={Send}
149-
className={styles.questionInputSendButton}
150-
alt="Send"
151-
/>
152-
)}
153-
</div>
136+
{isSendButtonDisabled?( <SendRegular className={styles.SendButtonDisabled} />):(
137+
<div
138+
role="button"
139+
tabIndex={0}
140+
aria-label="Ask question button"
141+
onClick={sendQuestion}
142+
onKeyDown={(e) =>
143+
e.key === "Enter" || e.key === " " ? sendQuestion() : null
144+
}
145+
className={styles.questionInputSendButtonContainer}
146+
>
147+
{disabled? (
148+
<SendRegular className={styles.questionInputSendButtonDisabled} />
149+
) : (
150+
<img
151+
src={Send}
152+
className={styles.questionInputSendButton}
153+
alt="Send"
154+
/>
155+
)}
156+
</div>
157+
)}
154158
</div>
155159
</Stack>
156160
);

code/frontend/src/pages/chat/Chat.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const Chat = () => {
3434
const chatMessageStreamEnd = useRef<HTMLDivElement | null>(null);
3535
const [isLoading, setIsLoading] = useState<boolean>(false);
3636
const [showLoadingMessage, setShowLoadingMessage] = useState<boolean>(false);
37+
38+
const [isSendButtonDisabled, setSendButtonDisabled] = useState(false);
3739
const [activeCitation, setActiveCitation] =
3840
useState<
3941
[
@@ -180,16 +182,16 @@ const Chat = () => {
180182
}
181183
setIsRecognizing(false);
182184
setRecognizedText("");
185+
setSendButtonDisabled(false);
183186
setIsListening(false);
184187
}
185188
};
186189

187190
const onMicrophoneClick = async () => {
188191
if (!isRecognizing) {
189-
// console.log("Starting speech recognition...");
192+
setSendButtonDisabled(true);
190193
await startSpeechRecognition();
191194
} else {
192-
// console.log("Stopping speech recognition...");
193195
stopSpeechRecognition();
194196
setRecognizedText(userMessage);
195197
}
@@ -355,6 +357,7 @@ const Chat = () => {
355357
disabled={isLoading}
356358
onSend={(question) => makeApiRequest(question)}
357359
recognizedText={recognizedText}
360+
isSendButtonDisabled={isSendButtonDisabled}
358361
onMicrophoneClick={onMicrophoneClick}
359362
onStopClick={stopSpeechRecognition}
360363
isListening={isListening}

0 commit comments

Comments
 (0)