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
};
newWs.onclose = (e) => {
console.log(e.code);
console.log("close");
setLockChat(false);
};
newWs.onerror = (e) => {
window.alert("error");
};
setWs(newWs);
return () => {
@ -132,6 +135,12 @@ export default function ChatModal({
if (ref.current) ref.current.scrollIntoView({ behavior: "smooth" });
}, [chatHistory]);
useEffect(() => {
if (ws &&ws.readyState===ws.CLOSED) {
setLockChat(false);
}
}, [lockChat]);
function validateNode(n: NodeType): Array<string> {
if (!n.data?.node?.template || !Object.keys(n.data.node.template)) {
setNoticeData({
@ -195,20 +204,6 @@ export default function ChatModal({
chatHistory,
name: flow.name,
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 {
setErrorData({