2021-10-27 16:38:10 +02:00
|
|
|
// @flow
|
2021-11-01 19:51:23 +01:00
|
|
|
import * as React from 'react';
|
2021-10-27 16:38:10 +02:00
|
|
|
import SettingsRow from 'component/settingsRow';
|
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
import useBrowserNotifications from '$web/component/browserNotificationSettings/use-browser-notifications';
|
2021-11-01 19:51:23 +01:00
|
|
|
import { BrowserNotificationHints, BrowserNotificationsBlocked } from '$web/component/browserNotificationHints';
|
2021-10-27 16:38:10 +02:00
|
|
|
|
|
|
|
const BrowserNotificationSettings = () => {
|
2021-11-01 19:51:23 +01:00
|
|
|
const { pushSupported, pushEnabled, pushPermission, pushToggle, pushErrorModal } = useBrowserNotifications();
|
|
|
|
|
|
|
|
const pushBlocked = pushPermission === 'denied';
|
2021-10-27 16:38:10 +02:00
|
|
|
|
2021-11-01 19:51:23 +01:00
|
|
|
const renderHints = () => (!pushSupported ? <BrowserNotificationHints /> : null);
|
|
|
|
const renderBlocked = () => (pushBlocked ? <BrowserNotificationsBlocked /> : null);
|
2021-10-27 16:38:10 +02:00
|
|
|
|
|
|
|
return (
|
2021-11-01 19:51:23 +01:00
|
|
|
<>
|
|
|
|
<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()}
|
|
|
|
</>
|
2021-10-27 16:38:10 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default BrowserNotificationSettings;
|