From a07f028b75a73cb92379ed3cd40dc1ce669e8522 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 12 Oct 2024 16:58:54 -0400 Subject: [PATCH] Add even more logging --- app/install/EnableNotifications.tsx | 16 +++++++++++++++- app/routes/_index.tsx | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/install/EnableNotifications.tsx b/app/install/EnableNotifications.tsx index 6e6800c..35b1bff 100644 --- a/app/install/EnableNotifications.tsx +++ b/app/install/EnableNotifications.tsx @@ -26,6 +26,7 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { const { subscribeToPush, requestPermission, canSendPush } = usePush() const [error, setError] = useState() + const [log, setLog] = useState([]) function subscribe() { requestPermission() @@ -34,15 +35,25 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { useEffect(() => { if (!canSendPush) return + setLog((prev) => [...prev, "Subscribing to push notifications"]) + subscribeToPush( urlB64ToUint8Array(pushPublicKey) as any, (subscription) => { + setLog((prev) => [ + ...prev, + `controller is undefined? ${navigator.serviceWorker.controller === undefined}`, + ]) + setLog((prev) => [ + ...prev, + `subscriptions: ${JSON.stringify(subscription.toJSON())}`, + ]) try { navigator.serviceWorker.controller?.postMessage({ type: "subscribed", subscription: subscription.toJSON(), }) - onSubscribe() + // onSubscribe() } catch (error) { setError(error as Error) } @@ -57,6 +68,9 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { <>
{error?.toString()}
+ {log.map((log, index) => ( +
{log}
+ ))} ) } diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index dfa7a1f..217913e 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -97,7 +97,7 @@ function TackUpNow({ useEffect(() => { window.addEventListener("message", (event) => - setMessages((prev) => [...prev, event.data]) + setMessages((prev) => [...prev, JSON.stringify(event.data)]) ) }, [])