fixed lockChat logic

This commit is contained in:
anovazzi1 2023-04-25 23:01:52 -03:00
commit 5d94b5cd9c

View file

@ -112,9 +112,12 @@ export default function ChatModal({
// Do something with the data received from the WebSocket // Do something with the data received from the WebSocket
}; };
newWs.onclose = (e) => { newWs.onclose = (e) => {
console.log(e.code); console.log("close");
setLockChat(false); setLockChat(false);
}; };
newWs.onerror = (e) => {
window.alert("error");
};
setWs(newWs); setWs(newWs);
return () => { return () => {
@ -132,6 +135,12 @@ export default function ChatModal({
if (ref.current) ref.current.scrollIntoView({ behavior: "smooth" }); if (ref.current) ref.current.scrollIntoView({ behavior: "smooth" });
}, [chatHistory]); }, [chatHistory]);
useEffect(() => {
if (ws &&ws.readyState===ws.CLOSED) {
setLockChat(false);
}
}, [lockChat]);
function validateNode(n: NodeType): Array<string> { function validateNode(n: NodeType): Array<string> {
if (!n.data?.node?.template || !Object.keys(n.data.node.template)) { if (!n.data?.node?.template || !Object.keys(n.data.node.template)) {
setNoticeData({ setNoticeData({
@ -195,20 +204,6 @@ export default function ChatModal({
chatHistory, chatHistory,
name: flow.name, name: flow.name,
description: flow.description, description: flow.description,
}).catch((error) => {
setErrorData({
title: error.message ?? "Unknown Error",
list: [error.response.data.detail],
});
setLockChat(false);
let lastMessage;
setChatHistory((chatHistory) => {
let newChat = chatHistory;
lastMessage = newChat.pop().message;
return newChat;
});
setChatValue(lastMessage);
}); });
} else { } else {
setErrorData({ setErrorData({