From 940844c91f58df2209c2c0c03fc1d27aead42f1e Mon Sep 17 00:00:00 2001 From: canove Date: Thu, 30 Jul 2020 11:26:39 -0300 Subject: [PATCH] fix: clean last notifications when visible = true --- frontend/src/components/TicketsList/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/components/TicketsList/index.js b/frontend/src/components/TicketsList/index.js index 45d2e07..8250ead 100644 --- a/frontend/src/components/TicketsList/index.js +++ b/frontend/src/components/TicketsList/index.js @@ -317,16 +317,24 @@ const TicketsList = () => { const options = { body: `${data.message.body} - ${format(new Date(), "HH:mm")}`, icon: data.contact.profilePicUrl, + tag: data.ticket.id, }; let notification = new Notification( `Mensagem de ${data.contact.name}`, options ); + notification.onclick = function (event) { event.preventDefault(); // window.open(`/chat/${data.ticket.id}`, "_self"); }; + document.addEventListener("visibilitychange", () => { + if (document.visibilityState === "visible") { + notification.close(); + } + }); + document.getElementById("sound").play(); };