mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
improvement: consider loading in all websockets handlers
This commit is contained in:
@@ -25,6 +25,8 @@ import TabPanel from "../TabPanel";
|
|||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
|
||||||
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
ticketsWrapper: {
|
ticketsWrapper: {
|
||||||
position: "relative",
|
position: "relative",
|
||||||
@@ -207,18 +209,22 @@ const Tickets = () => {
|
|||||||
}, [searchParam, pageNumber, token, tab]);
|
}, [searchParam, pageNumber, token, tab]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
|
||||||
|
|
||||||
socket.emit("joinNotification");
|
socket.emit("joinNotification");
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
socket.disconnect();
|
||||||
|
};
|
||||||
|
}, [ticketId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
socket.on("ticket", data => {
|
socket.on("ticket", data => {
|
||||||
if (data.action === "updateUnread") {
|
if (data.action === "updateUnread" && !loading) {
|
||||||
resetUnreadMessages(data);
|
resetUnreadMessages(data);
|
||||||
}
|
}
|
||||||
if (data.action === "updateStatus" || data.action === "create") {
|
if (data.action === "updateStatus" || data.action === "create") {
|
||||||
updateTickets(data);
|
updateTickets(data);
|
||||||
}
|
}
|
||||||
if (data.action === "delete") {
|
if (data.action === "delete" && !loading) {
|
||||||
deleteTicket(data);
|
deleteTicket(data);
|
||||||
if (ticketId && data.ticketId === +ticketId) {
|
if (ticketId && data.ticketId === +ticketId) {
|
||||||
toast.warn("O ticket que você estava foi deletado.");
|
toast.warn("O ticket que você estava foi deletado.");
|
||||||
@@ -228,7 +234,7 @@ const Tickets = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("appMessage", data => {
|
socket.on("appMessage", data => {
|
||||||
if (data.action === "create") {
|
if (data.action === "create" && !loading) {
|
||||||
updateTickets(data);
|
updateTickets(data);
|
||||||
if (
|
if (
|
||||||
(ticketId &&
|
(ticketId &&
|
||||||
@@ -240,11 +246,7 @@ const Tickets = () => {
|
|||||||
showDesktopNotification(data);
|
showDesktopNotification(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}, [history, ticketId, userId, loading]);
|
||||||
return () => {
|
|
||||||
socket.disconnect();
|
|
||||||
};
|
|
||||||
}, [ticketId, userId, history]);
|
|
||||||
|
|
||||||
const loadMore = () => {
|
const loadMore = () => {
|
||||||
setPageNumber(prevState => prevState + 1);
|
setPageNumber(prevState => prevState + 1);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import ContactsSekeleton from "../../components/ContactsSekeleton";
|
|||||||
import ContactModal from "../../components/ContactModal";
|
import ContactModal from "../../components/ContactModal";
|
||||||
import ConfirmationModal from "../../components/ConfirmationModal/";
|
import ConfirmationModal from "../../components/ConfirmationModal/";
|
||||||
|
|
||||||
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
mainContainer: {
|
mainContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -103,23 +105,23 @@ const Contacts = () => {
|
|||||||
}, [searchParam, page, rowsPerPage]);
|
}, [searchParam, page, rowsPerPage]);
|
||||||
|
|
||||||
useEffect(() => {
|
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 () => {
|
return () => {
|
||||||
socket.disconnect();
|
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 => {
|
const updateContacts = contact => {
|
||||||
setContacts(prevState => {
|
setContacts(prevState => {
|
||||||
const contactIndex = prevState.findIndex(c => c.id === contact.id);
|
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 SessionInfo from "../../components/SessionInfo";
|
||||||
import Qrcode from "../../components/Qrcode";
|
import Qrcode from "../../components/Qrcode";
|
||||||
|
|
||||||
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -53,8 +55,6 @@ const WhatsAuth = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
|
||||||
|
|
||||||
socket.on("qrcode", data => {
|
socket.on("qrcode", data => {
|
||||||
if (data.action === "update") {
|
if (data.action === "update") {
|
||||||
setQrCode(data.qr);
|
setQrCode(data.qr);
|
||||||
@@ -74,8 +74,6 @@ const WhatsAuth = () => {
|
|||||||
};
|
};
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
console.log(session);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Grid container spacing={3}>
|
<Grid container spacing={3}>
|
||||||
|
|||||||
Reference in New Issue
Block a user