@@ -7,9 +7,8 @@ import settings from '../../../client/state/settings';
7
7
import navigation from '../../../client/state/navigation' ;
8
8
import {
9
9
toggleSystemTheme ,
10
- toggleNotifications , toggleNotificationSounds ,
11
10
} from '../../../client/action/settings' ;
12
- import { usePermission } from '../../hooks/usePermission' ;
11
+ import { usePermissionState } from '../../hooks/usePermission' ;
13
12
14
13
import Text from '../../atoms/text/Text' ;
15
14
import IconButton from '../../atoms/button/IconButton' ;
@@ -230,23 +229,25 @@ function AppearanceSection() {
230
229
}
231
230
232
231
function NotificationsSection ( ) {
233
- const [ permission , setPermission ] = usePermission ( 'notifications' , window . Notification ?. permission ) ;
234
-
235
- const [ , updateState ] = useState ( { } ) ;
232
+ const notifPermission = usePermissionState ( 'notifications' , window . Notification ?. permission ?? "denied" ) ;
233
+ const [ showNotifications , setShowNotifications ] = useSetting ( settingsAtom , 'showNotifications' )
234
+ const [ isNotificationSounds , setIsNotificationSounds ] = useSetting ( settingsAtom , 'isNotificationSounds' )
236
235
237
236
const renderOptions = ( ) => {
238
237
if ( window . Notification === undefined ) {
239
238
return < Text className = "settings-notifications__not-supported" > Not supported in this browser.</ Text > ;
240
239
}
241
240
242
- if ( permission === 'granted' ) {
241
+ if ( notifPermission === 'denied' ) {
242
+ return < Text > Permission Denied</ Text >
243
+ }
244
+
245
+ if ( notifPermission === 'granted' ) {
243
246
return (
244
247
< Toggle
245
- isActive = { settings . _showNotifications }
248
+ isActive = { showNotifications }
246
249
onToggle = { ( ) => {
247
- toggleNotifications ( ) ;
248
- setPermission ( window . Notification ?. permission ) ;
249
- updateState ( { } ) ;
250
+ setShowNotifications ( ! showNotifications ) ;
250
251
} }
251
252
/>
252
253
) ;
@@ -255,7 +256,9 @@ function NotificationsSection() {
255
256
return (
256
257
< Button
257
258
variant = "primary"
258
- onClick = { ( ) => window . Notification . requestPermission ( ) . then ( setPermission ) }
259
+ onClick = { ( ) => window . Notification . requestPermission ( ) . then ( ( ) => {
260
+ setShowNotifications ( window . Notification ?. permission === 'granted' ) ;
261
+ } ) }
259
262
>
260
263
Request permission
261
264
</ Button >
@@ -275,8 +278,8 @@ function NotificationsSection() {
275
278
title = "Notification Sound"
276
279
options = { (
277
280
< Toggle
278
- isActive = { settings . isNotificationSounds }
279
- onToggle = { ( ) => { toggleNotificationSounds ( ) ; updateState ( { } ) ; } }
281
+ isActive = { isNotificationSounds }
282
+ onToggle = { ( ) => setIsNotificationSounds ( ! isNotificationSounds ) }
280
283
/>
281
284
) }
282
285
content = { < Text variant = "b3" > Play sound when new messages arrive.</ Text > }
0 commit comments