mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
improvement: consider loading in all websockets handlers
This commit is contained in:
@@ -28,6 +28,8 @@ import ContactsSekeleton from "../../components/ContactsSekeleton";
|
||||
import ContactModal from "../../components/ContactModal";
|
||||
import ConfirmationModal from "../../components/ConfirmationModal/";
|
||||
|
||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
mainContainer: {
|
||||
flex: 1,
|
||||
@@ -103,23 +105,23 @@ const Contacts = () => {
|
||||
}, [searchParam, page, rowsPerPage]);
|
||||
|
||||
useEffect(() => {
|
||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||
|
||||
socket.on("contact", data => {
|
||||
if (data.action === "update" || data.action === "create") {
|
||||
updateContacts(data.contact);
|
||||
}
|
||||
|
||||
if (data.action === "delete") {
|
||||
deleteContact(data.contactId);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
socket.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
socket.on("contact", data => {
|
||||
if ((data.action === "update" || data.action === "create") && !loading) {
|
||||
updateContacts(data.contact);
|
||||
}
|
||||
|
||||
if (data.action === "delete" && !loading) {
|
||||
deleteContact(data.contactId);
|
||||
}
|
||||
});
|
||||
}, [loading]);
|
||||
|
||||
const updateContacts = contact => {
|
||||
setContacts(prevState => {
|
||||
const contactIndex = prevState.findIndex(c => c.id === contact.id);
|
||||
|
||||
@@ -10,6 +10,8 @@ import Paper from "@material-ui/core/Paper";
|
||||
import SessionInfo from "../../components/SessionInfo";
|
||||
import Qrcode from "../../components/Qrcode";
|
||||
|
||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
root: {
|
||||
display: "flex",
|
||||
@@ -53,8 +55,6 @@ const WhatsAuth = () => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||
|
||||
socket.on("qrcode", data => {
|
||||
if (data.action === "update") {
|
||||
setQrCode(data.qr);
|
||||
@@ -74,8 +74,6 @@ const WhatsAuth = () => {
|
||||
};
|
||||
}, [history]);
|
||||
|
||||
console.log(session);
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Grid container spacing={3}>
|
||||
|
||||
Reference in New Issue
Block a user