From 1d7b5d648a31ff93883c1a73c4cff6d8fb3ade70 Mon Sep 17 00:00:00 2001
From: Patrick O'Sullivan
Date: Tue, 5 Apr 2022 09:44:28 -0500
Subject: [PATCH] grid: Move browser not. toggle into notification tab, remove
dnd
---
.../src/nav/preferences/InterfacePrefs.tsx | 32 -----------
.../src/nav/preferences/NotificationPrefs.tsx | 53 ++++++++++++-------
2 files changed, 34 insertions(+), 51 deletions(-)
diff --git a/pkg/grid/src/nav/preferences/InterfacePrefs.tsx b/pkg/grid/src/nav/preferences/InterfacePrefs.tsx
index 7287c3ebb6..c86592a6e6 100644
--- a/pkg/grid/src/nav/preferences/InterfacePrefs.tsx
+++ b/pkg/grid/src/nav/preferences/InterfacePrefs.tsx
@@ -23,14 +23,6 @@ export function InterfacePrefs() {
.putEntry('browserSettings', 'settings', JSON.stringify(newSettings));
}
};
- const setBrowserNotifications = (setting: boolean) => {
- const newSettings = [{ browserId, browserNotifications: setting, protocolHandling }];
- if (!settings.includes(newSettings)) {
- useSettingsState
- .getState()
- .putEntry('browserSettings', 'settings', JSON.stringify(newSettings));
- }
- };
const toggleProtoHandling = async () => {
if (!protocolHandling && window?.navigator?.registerProtocolHandler) {
@@ -54,15 +46,6 @@ export function InterfacePrefs() {
}
};
- const toggleNotifications = async () => {
- if (!browserNotifications) {
- Notification.requestPermission();
- setBrowserNotifications(true);
- } else {
- setBrowserNotifications(false);
- }
- };
-
return (
<>
Interface Settings
@@ -84,21 +67,6 @@ export function InterfacePrefs() {
)}
-
-
- Show desktop notifications in this browser.
- {!secure && (
- <>
- , requires HTTPS
- >
- )}
-
-
>
);
diff --git a/pkg/grid/src/nav/preferences/NotificationPrefs.tsx b/pkg/grid/src/nav/preferences/NotificationPrefs.tsx
index 8d70dfb139..2ae8d983ff 100644
--- a/pkg/grid/src/nav/preferences/NotificationPrefs.tsx
+++ b/pkg/grid/src/nav/preferences/NotificationPrefs.tsx
@@ -3,14 +3,13 @@ import React from 'react';
import { Setting } from '../../components/Setting';
import { pokeOptimisticallyN } from '../../state/base';
import { HarkState, reduceGraph, useHarkStore } from '../../state/hark';
-import { useSettingsState, SettingsState } from '../../state/settings';
-
-const selDnd = (s: SettingsState) => s.display.doNotDisturb;
-async function toggleDnd() {
- const state = useSettingsState.getState();
- const curr = selDnd(state);
- await state.putEntry('display', 'doNotDisturb', !curr);
-}
+import { useBrowserId } from '../../state/local';
+import {
+ useSettingsState,
+ useBrowserNotifications,
+ useBrowserSettings,
+ useProtocolHandling
+} from '../../state/settings';
const selMentions = (s: HarkState) => s.notificationsGraphConfig.mentions;
async function toggleMentions() {
@@ -19,27 +18,43 @@ async function toggleMentions() {
}
export const NotificationPrefs = () => {
- const doNotDisturb = useSettingsState(selDnd);
const mentions = useHarkStore(selMentions);
+ const settings = useBrowserSettings();
+ const browserId = useBrowserId();
+ const browserNotifications = useBrowserNotifications(browserId);
+ const protocolHandling = useProtocolHandling(browserId);
const secure = window.location.protocol === 'https:' || window.location.hostname === 'localhost';
+ const setBrowserNotifications = (setting: boolean) => {
+ const newSettings = [{ browserId, browserNotifications: setting, protocolHandling }];
+ if (!settings.includes(newSettings)) {
+ useSettingsState
+ .getState()
+ .putEntry('browserSettings', 'settings', JSON.stringify(newSettings));
+ }
+ };
+
+ const toggleNotifications = async () => {
+ if (!browserNotifications) {
+ Notification.requestPermission();
+ setBrowserNotifications(true);
+ } else {
+ setBrowserNotifications(false);
+ }
+ };
+
return (
<>
Notifications
- Block visual desktop notifications whenever Urbit software produces a notification
- badge.
-
-
- Turning this "off" will prompt your browser to ask if you'd like to
- enable notifications
+ Show desktop notifications in this browser.
{!secure && (
<>
, requires HTTPS