add useEffect to prevent chat lock on fail of onClose method (#342)
This commit is contained in:
commit
3791247545
1 changed files with 10 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue