fix/update loading state when streaming is complete

This commit is contained in:
tobiadefami
2025-02-19 03:06:29 +01:00
parent 14c3ee3bea
commit 1ef5c69c3b

View File

@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import { CellUpdate, ChatMessage } from "@/types/api";
import { Check, X, Send, Trash2, Loader2, Square } from "lucide-react";
@@ -22,6 +22,13 @@ const ChatBox = ({
const [message, setMessage] = useState("");
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (chatHistory.length > 0) {
const lastMessage = chatHistory[chatHistory.length - 1];
setIsLoading(!!lastMessage.streaming);
}
}, [chatHistory]);
const handleSend = async () => {
if (message.trim() || isLoading) {
if (isLoading) {
@@ -36,8 +43,6 @@ const ChatBox = ({
await onSend(currentMessage); // Changed to await for streaming
} catch (error) {
console.error("Error details:", error);
} finally {
setIsLoading(false);
}
}
};