lbry-desktop/web/component/browserNotificationSettings/view.jsx
Dan Peterson 704452732a
Add hints if an error occurs subscribing to notifications (#143)
* Add hints if an error occurs subscribing to notifications

* Update import (type/linting issue)

* disable optimization for debugging

* Revert "disable optimization for debugging"

This reverts commit 5b837f94e97b7488a7dc565e7f74d399e19c286f.

* improve detection of notification support + improve ux / ui surrounding that

* update translations
2021-11-01 14:51:23 -04:00

38 lines
1.3 KiB
JavaScript

// @flow
import * as React from 'react';
import SettingsRow from 'component/settingsRow';
import { FormField } from 'component/common/form';
import useBrowserNotifications from '$web/component/browserNotificationSettings/use-browser-notifications';
import { BrowserNotificationHints, BrowserNotificationsBlocked } from '$web/component/browserNotificationHints';
const BrowserNotificationSettings = () => {
const { pushSupported, pushEnabled, pushPermission, pushToggle, pushErrorModal } = useBrowserNotifications();
const pushBlocked = pushPermission === 'denied';
const renderHints = () => (!pushSupported ? <BrowserNotificationHints /> : null);
const renderBlocked = () => (pushBlocked ? <BrowserNotificationsBlocked /> : null);
return (
<>
<SettingsRow
title={__('Browser Notifications')}
subtitle={__("Receive push notifications in this browser, even when you're not on odysee.com")}
disabled={!pushSupported || pushBlocked}
>
<FormField
type="checkbox"
name="browserNotification"
disabled={!pushSupported || pushBlocked}
onChange={pushToggle}
checked={pushEnabled}
/>
</SettingsRow>
{renderHints()}
{renderBlocked()}
{pushErrorModal()}
</>
);
};
export default BrowserNotificationSettings;