Skip to content

Commit 93b84ed

Browse files
fix: Commit changes bug (#1568)
1 parent 131c323 commit 93b84ed

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const Chat = () => {
6969
const lastQuestionRef = useRef<string>("");
7070
const chatMessageStreamEnd = useRef<HTMLDivElement | null>(null);
7171
const [isLoading, setIsLoading] = useState<boolean>(false);
72+
const [isGenerating, setIsGenerating] = useState<boolean>(false); // Add this state
7273
const [showLoadingMessage, setShowLoadingMessage] = useState<boolean>(false);
7374
const [isAssistantAPILoading, setIsAssistantAPILoading] = useState(false);
7475
const [isSendButtonDisabled, setSendButtonDisabled] = useState(false);
@@ -185,7 +186,7 @@ const Chat = () => {
185186
text: "Clear all chat history",
186187
disabled:
187188
!chatHistory.length ||
188-
isLoading ||
189+
isGenerating ||
189190
fetchingConvMessages ||
190191
fetchingChatHistory,
191192
iconProps: { iconName: "Delete" },
@@ -194,7 +195,7 @@ const Chat = () => {
194195
const makeApiRequest = async (question: string) => {
195196
lastQuestionRef.current = question;
196197

197-
setIsLoading(true);
198+
setIsGenerating(true);
198199
setShowLoadingMessage(true);
199200
const abortController = new AbortController();
200201
abortFuncs.current.unshift(abortController);
@@ -274,7 +275,7 @@ const Chat = () => {
274275
}
275276
setAnswers([...answers, userMessage]);
276277
} finally {
277-
setIsLoading(false);
278+
setIsGenerating(false);
278279
setShowLoadingMessage(false);
279280
abortFuncs.current = abortFuncs.current.filter(
280281
(a) => a !== abortController
@@ -371,7 +372,7 @@ const Chat = () => {
371372
const stopGenerating = () => {
372373
abortFuncs.current.forEach((a) => a.abort());
373374
setShowLoadingMessage(false);
374-
setIsLoading(false);
375+
setIsGenerating(false);
375376
};
376377

377378
useEffect(() => {
@@ -485,6 +486,10 @@ const Chat = () => {
485486
};
486487

487488
const onSelectConversation = async (id: string) => {
489+
if (isGenerating) {
490+
// If response is being generated, prevent switching threads
491+
return;
492+
}
488493
if (!id) {
489494
console.error("No conversation Id found");
490495
return;
@@ -623,7 +628,7 @@ const Chat = () => {
623628
) : (
624629
<div
625630
className={styles.chatMessageStream}
626-
style={{ marginBottom: isLoading ? "40px" : "0px" }}
631+
style={{ marginBottom: isGenerating ? "40px" : "0px" }}
627632
>
628633
{fetchingConvMessages && (
629634
<div className={styles.fetchMessagesSpinner}>
@@ -697,7 +702,7 @@ const Chat = () => {
697702
</div>
698703

699704
<Stack horizontal className={styles.chatInput}>
700-
{isLoading && (
705+
{isGenerating && (
701706
<Stack
702707
horizontal
703708
className={styles.stopGeneratingContainer}
@@ -725,10 +730,10 @@ const Chat = () => {
725730
className={`${styles.clearChatBroom} ${styles.mobileclearChatBroom}`}
726731
style={{
727732
background:
728-
isLoading || answers.length === 0
733+
isGenerating || answers.length === 0
729734
? "#BDBDBD"
730735
: "radial-gradient(109.81% 107.82% at 100.1% 90.19%, #0F6CBD 33.63%, #2D87C3 70.31%, #8DDDD8 100%)",
731-
cursor: isLoading || answers.length === 0 ? "" : "pointer",
736+
cursor: isGenerating || answers.length === 0 ? "" : "pointer",
732737
}}
733738
onClick={clearChat}
734739
onKeyDown={(e) =>
@@ -741,7 +746,7 @@ const Chat = () => {
741746
<QuestionInput
742747
clearOnSend
743748
placeholder="Type a new question..."
744-
disabled={isLoading}
749+
disabled={isGenerating}
745750
onSend={(question) => makeApiRequest(question)}
746751
recognizedText={recognizedText}
747752
isSendButtonDisabled={isSendButtonDisabled}

0 commit comments

Comments
 (0)