Add initialization status to push notification hook. Can be used to better control render strategy in cmpnts utilizing it. (#284)
This commit is contained in:
parent
6d217dbc50
commit
c242c37869
2 changed files with 17 additions and 3 deletions
|
@ -8,10 +8,19 @@ import Button from 'component/button';
|
||||||
import usePersistedState from 'effects/use-persisted-state';
|
import usePersistedState from 'effects/use-persisted-state';
|
||||||
|
|
||||||
export const BrowserNotificationBanner = () => {
|
export const BrowserNotificationBanner = () => {
|
||||||
const { pushSupported, pushEnabled, pushPermission, pushToggle, pushErrorModal } = useBrowserNotifications();
|
const {
|
||||||
|
pushInitialized,
|
||||||
|
pushSupported,
|
||||||
|
pushEnabled,
|
||||||
|
pushPermission,
|
||||||
|
pushToggle,
|
||||||
|
pushErrorModal,
|
||||||
|
} = useBrowserNotifications();
|
||||||
const [hasAcknowledgedPush, setHasAcknowledgedPush] = usePersistedState('push-nag', false);
|
const [hasAcknowledgedPush, setHasAcknowledgedPush] = usePersistedState('push-nag', false);
|
||||||
|
|
||||||
if (!pushSupported || pushEnabled || pushPermission === 'denied' || hasAcknowledgedPush) return null;
|
if (!pushInitialized || !pushSupported || pushEnabled || pushPermission === 'denied' || hasAcknowledgedPush) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const handleClose = () => setHasAcknowledgedPush(true);
|
const handleClose = () => setHasAcknowledgedPush(true);
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,17 @@ export default () => {
|
||||||
const [pushEnabled, setPushEnabled] = useState(false);
|
const [pushEnabled, setPushEnabled] = useState(false);
|
||||||
const [pushSupported, setPushSupported] = useState(true);
|
const [pushSupported, setPushSupported] = useState(true);
|
||||||
const [encounteredError, setEncounteredError] = useState(false);
|
const [encounteredError, setEncounteredError] = useState(false);
|
||||||
|
const [pushInitialized, setPushInitialized] = useState(false);
|
||||||
|
|
||||||
const [user] = useState(selectUser(store.getState()));
|
const [user] = useState(selectUser(store.getState()));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPushSupported(pushNotifications.supported);
|
setPushSupported(pushNotifications.supported);
|
||||||
if (pushNotifications.supported) {
|
if (pushNotifications.supported) {
|
||||||
pushNotifications.subscribed(user.id).then((isSubscribed: boolean) => setSubscribed(isSubscribed));
|
pushNotifications.subscribed(user.id).then((isSubscribed: boolean) => {
|
||||||
|
setSubscribed(isSubscribed);
|
||||||
|
setPushInitialized(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
@ -59,6 +63,7 @@ export default () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
pushInitialized,
|
||||||
pushSupported,
|
pushSupported,
|
||||||
pushEnabled,
|
pushEnabled,
|
||||||
pushPermission,
|
pushPermission,
|
||||||
|
|
Loading…
Reference in a new issue