From 82cdd6a66d31c7eff53b70cd9d66c04e17c05c85 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Tue, 25 Oct 2022 10:33:17 +0800 Subject: [PATCH] fix: notification redirect --- src/common/component/Notification/index.tsx | 30 ++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/common/component/Notification/index.tsx b/src/common/component/Notification/index.tsx index d667431e..1e5ddbba 100644 --- a/src/common/component/Notification/index.tsx +++ b/src/common/component/Notification/index.tsx @@ -1,12 +1,12 @@ import { useEffect, memo } from "react"; -import { useNavigate } from "react-router-dom"; +// import { useNavigate } from "react-router-dom"; import useDeviceToken from "./useDeviceToken"; import { vapidKey } from "../../../app/config"; import { useUpdateDeviceTokenMutation } from "../../../app/services/auth"; let updated = false; let updating = false; const Notification = () => { - const navigateTo = useNavigate(); + // const navigateTo = useNavigate(); const token = useDeviceToken(vapidKey); const [updateDeviceToken] = useUpdateDeviceTokenMutation(); useEffect(() => { @@ -24,19 +24,19 @@ const Notification = () => { updateToken(token as string); }, [token]); - useEffect(() => { - const handleServiceWorkerMessage = (event: MessageEvent) => { - const { newPath } = event.data; - if (newPath) { - navigateTo(newPath); - } - }; - // https only - navigator.serviceWorker?.addEventListener("message", handleServiceWorkerMessage); - return () => { - navigator.serviceWorker?.removeEventListener("message", handleServiceWorkerMessage); - }; - }, []); + // useEffect(() => { + // const handleServiceWorkerMessage = (event: MessageEvent) => { + // const { newPath } = event.data; + // if (newPath && document.hidden) { + // navigateTo(newPath); + // } + // }; + // // https only + // navigator.serviceWorker?.addEventListener("message", handleServiceWorkerMessage); + // return () => { + // navigator.serviceWorker?.removeEventListener("message", handleServiceWorkerMessage); + // }; + // }, []); return null; };