import { useEffect, useCallback, useState } from 'react'; export function WithNotificationPermission({ children }) { let currentPermission = Notification.permission ?? 'default'; const [asking, setAsking] = useState(false); const requestPermission = useCallback(async () => { setAsking(true); try { await Notification.requestPermission(); } catch (_e) {}; // we'll re-render and look up the permission from Notification setAsking(false); }); if (currentPermission !== 'granted') { return ( <>
To show notifications we need permission:
{currentPermission === 'denied' ?
Notification permission was denied. You may need to clear the browser setting to try again.
:You can revoke this any time
} > ); } return children; }