improvement: focus app when clicking desktop notification

This commit is contained in:
canove
2020-09-25 22:12:31 -03:00
parent eb23775948
commit 9d87522ad9
3 changed files with 29 additions and 30 deletions

View File

@@ -338,7 +338,7 @@ const MessagesList = () => {
} }
if (data.action === "delete") { if (data.action === "delete") {
toast.success("The deleted sucessfully."); toast.success("Ticket deleted sucessfully.");
history.push("/tickets"); history.push("/tickets");
} }
}); });

View File

@@ -108,16 +108,9 @@ const NotificationsPopOver = () => {
(data.ticket.userId !== userId && data.ticket.userId) (data.ticket.userId !== userId && data.ticket.userId)
) )
return; return;
showDesktopNotification(data); else {
} // show desktop notification
}); const { message, contact, ticket } = data;
return () => {
socket.disconnect();
};
}, [userId]);
const showDesktopNotification = ({ message, contact, ticket }) => {
const options = { const options = {
body: `${message.body} - ${format(new Date(), "HH:mm")}`, body: `${message.body} - ${format(new Date(), "HH:mm")}`,
icon: contact.profilePicUrl, icon: contact.profilePicUrl,
@@ -130,6 +123,7 @@ const NotificationsPopOver = () => {
notification.onclick = function (event) { notification.onclick = function (event) {
event.preventDefault(); // event.preventDefault(); //
window.focus();
history.push(`/tickets/${ticket.id}`); history.push(`/tickets/${ticket.id}`);
}; };
@@ -140,7 +134,14 @@ const NotificationsPopOver = () => {
}); });
soundAlert.current.play(); soundAlert.current.play();
}
}
});
return () => {
socket.disconnect();
}; };
}, [history, userId]);
const handleClick = useCallback(() => { const handleClick = useCallback(() => {
setIsOpen(!isOpen); setIsOpen(!isOpen);

View File

@@ -1,5 +1,4 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { useHistory } from "react-router-dom";
import { toast } from "react-toastify"; import { toast } from "react-toastify";
@@ -12,7 +11,6 @@ import ConfirmationModal from "../ConfirmationModal";
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => { const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
const [confirmationOpen, setConfirmationOpen] = useState(false); const [confirmationOpen, setConfirmationOpen] = useState(false);
const history = useHistory();
const handleDeleteTicket = async () => { const handleDeleteTicket = async () => {
try { try {