add useEffect to prevent chat lock on fail of onClose method (#342)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-05-25 06:29:39 -03:00 committed by GitHub
commit 3791247545
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,7 +15,7 @@ import { sendAllProps } from "../../types/api";
import { ChatMessageType, ChatType } from "../../types/chat";
import ChatInput from "./chatInput";
import _ from "lodash";
import _, { set } from "lodash";
export default function ChatModal({
flow,
@ -100,9 +100,9 @@ export default function ChatModal({
function handleOnClose(event: CloseEvent) {
if (isOpen.current) {
setErrorData({ title: event.reason });
setLockChat(false);
setTimeout(() => {
connectWS();
setLockChat(false);
}, 1000);
}
}
@ -235,6 +235,13 @@ export default function ChatModal({
};
}, []);
useEffect(() => {
if((ws.current.readyState=== ws.current.CLOSED || ws.current.readyState=== ws.current.CLOSING)){
connectWS();
setLockChat(false);
}
},[lockChat]);
async function sendAll(data: sendAllProps) {
try {
if (ws) {
@ -339,6 +346,7 @@ export default function ChatModal({
function clearChat() {
setChatHistory([]);
ws.current.send(JSON.stringify({ clear_history: true }));
if(lockChat) setLockChat(false);
}
function setModalOpen(x: boolean) {