websocket 连接重复初始化

dev/chat
Lei OT 1 year ago
parent 396f266a78
commit 62b7a1f0e6

@ -31,15 +31,15 @@ function DesktopApp() {
}, [href])
const totalNotify = useConversationStore((state) => state.totalNotify);
useEffect(() => {
if (loginUser.userId > 0) {
useConversationStore.getState().connectWebsocket(loginUser.userId);
useConversationStore.getState().fetchInitialData(loginUser.userId); // userIdStr
}
return () => {
useConversationStore.getState().disconnectWebsocket();
}
}, [])
// useEffect(() => {
// if (loginUser.userId > 0) {
// useConversationStore.getState().connectWebsocket(loginUser.userId);
// useConversationStore.getState().fetchInitialData(loginUser.userId); // userIdStr
// }
// return () => {
// useConversationStore.getState().disconnectWebsocket();
// }
// }, [])
useEffect(() => {
Notification.requestPermission();
@ -63,19 +63,19 @@ function DesktopApp() {
/**
* 标签页标题闪烁
*/
const [isTitleVisible, setIsTitleVisible] = useState(true);
useEffect(() => {
let interval;
if (totalNotify > 0) {
interval = setInterval(() => {
document.title = isTitleVisible ? `🔔🔥💬【${totalNotify}条新消息】` : '______________';
setIsTitleVisible(!isTitleVisible);
}, 500);
} else {
document.title = '聊天式销售平台';
}
return () => clearInterval(interval);
}, [totalNotify, isTitleVisible]);
// const [isTitleVisible, setIsTitleVisible] = useState(true);
// useEffect(() => {
// let interval;
// if (totalNotify > 0) {
// interval = setInterval(() => {
// document.title = isTitleVisible ? `🔔🔥💬${totalNotify}` : '______________';
// setIsTitleVisible(!isTitleVisible);
// }, 500);
// } else {
// document.title = '';
// }
// return () => clearInterval(interval);
// }, [totalNotify, isTitleVisible]);
return (
<Layout>

Loading…
Cancel
Save