Skip to content

Commit

Permalink
fix: Commit changes bug (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
UtkarshMishra-Microsoft authored Dec 18, 2024
1 parent 131c323 commit 93b84ed
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions code/frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Chat = () => {
const lastQuestionRef = useRef<string>("");
const chatMessageStreamEnd = useRef<HTMLDivElement | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isGenerating, setIsGenerating] = useState<boolean>(false); // Add this state
const [showLoadingMessage, setShowLoadingMessage] = useState<boolean>(false);
const [isAssistantAPILoading, setIsAssistantAPILoading] = useState(false);
const [isSendButtonDisabled, setSendButtonDisabled] = useState(false);
Expand Down Expand Up @@ -185,7 +186,7 @@ const Chat = () => {
text: "Clear all chat history",
disabled:
!chatHistory.length ||
isLoading ||
isGenerating ||
fetchingConvMessages ||
fetchingChatHistory,
iconProps: { iconName: "Delete" },
Expand All @@ -194,7 +195,7 @@ const Chat = () => {
const makeApiRequest = async (question: string) => {
lastQuestionRef.current = question;

setIsLoading(true);
setIsGenerating(true);
setShowLoadingMessage(true);
const abortController = new AbortController();
abortFuncs.current.unshift(abortController);
Expand Down Expand Up @@ -274,7 +275,7 @@ const Chat = () => {
}
setAnswers([...answers, userMessage]);
} finally {
setIsLoading(false);
setIsGenerating(false);
setShowLoadingMessage(false);
abortFuncs.current = abortFuncs.current.filter(
(a) => a !== abortController
Expand Down Expand Up @@ -371,7 +372,7 @@ const Chat = () => {
const stopGenerating = () => {
abortFuncs.current.forEach((a) => a.abort());
setShowLoadingMessage(false);
setIsLoading(false);
setIsGenerating(false);
};

useEffect(() => {
Expand Down Expand Up @@ -485,6 +486,10 @@ const Chat = () => {
};

const onSelectConversation = async (id: string) => {
if (isGenerating) {
// If response is being generated, prevent switching threads
return;
}
if (!id) {
console.error("No conversation Id found");
return;
Expand Down Expand Up @@ -623,7 +628,7 @@ const Chat = () => {
) : (
<div
className={styles.chatMessageStream}
style={{ marginBottom: isLoading ? "40px" : "0px" }}
style={{ marginBottom: isGenerating ? "40px" : "0px" }}
>
{fetchingConvMessages && (
<div className={styles.fetchMessagesSpinner}>
Expand Down Expand Up @@ -697,7 +702,7 @@ const Chat = () => {
</div>

<Stack horizontal className={styles.chatInput}>
{isLoading && (
{isGenerating && (
<Stack
horizontal
className={styles.stopGeneratingContainer}
Expand Down Expand Up @@ -725,10 +730,10 @@ const Chat = () => {
className={`${styles.clearChatBroom} ${styles.mobileclearChatBroom}`}
style={{
background:
isLoading || answers.length === 0
isGenerating || answers.length === 0
? "#BDBDBD"
: "radial-gradient(109.81% 107.82% at 100.1% 90.19%, #0F6CBD 33.63%, #2D87C3 70.31%, #8DDDD8 100%)",
cursor: isLoading || answers.length === 0 ? "" : "pointer",
cursor: isGenerating || answers.length === 0 ? "" : "pointer",
}}
onClick={clearChat}
onKeyDown={(e) =>
Expand All @@ -741,7 +746,7 @@ const Chat = () => {
<QuestionInput
clearOnSend
placeholder="Type a new question..."
disabled={isLoading}
disabled={isGenerating}
onSend={(question) => makeApiRequest(question)}
recognizedText={recognizedText}
isSendButtonDisabled={isSendButtonDisabled}
Expand Down

0 comments on commit 93b84ed

Please sign in to comment.