diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index cdbe62c..5fcc2d7 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -72,13 +72,16 @@ function LandingMessage({ isSupported }: { isSupported: boolean }) { } function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { - const { subscribeToPush, requestPermission } = usePush() - - return + const { subscribeToPush, requestPermission, canSendPush } = usePush() async function subscribe() { console.log("Hey the thing was clicked wow") - await requestPermission() + requestPermission() + } + + useEffect(() => { + if (!canSendPush) return + subscribeToPush( urlB64ToUint8Array(applicationServerPublicKey) as any, (subscription) => { @@ -94,7 +97,9 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { document.appendChild(errorDiv) } ) - } + }, [canSendPush]) + + return } const applicationServerPublicKey =