1
- import { useState } from 'react' ;
1
+ import { useMemo , useState } from 'react' ;
2
2
import { useModal } from '@ebay/nice-modal-react' ;
3
3
import CableIcon from '@mui/icons-material/Cable' ;
4
4
import ConstructionIcon from '@mui/icons-material/Construction' ;
5
5
import DeleteIcon from '@mui/icons-material/Delete' ;
6
6
import ForumIcon from '@mui/icons-material/Forum' ;
7
7
import LoginIcon from '@mui/icons-material/Login' ;
8
+ import NotificationsActiveIcon from '@mui/icons-material/NotificationsActive' ;
8
9
import SettingsIcon from '@mui/icons-material/Settings' ;
9
10
import SettingsInputComponentIcon from '@mui/icons-material/SettingsInputComponent' ;
10
11
import SportsEsportsIcon from '@mui/icons-material/SportsEsports' ;
11
12
import Avatar from '@mui/material/Avatar' ;
12
13
import Box from '@mui/material/Box' ;
13
14
import Button from '@mui/material/Button' ;
14
15
import Link from '@mui/material/Link' ;
16
+ import List from '@mui/material/List' ;
17
+ import ListItemText from '@mui/material/ListItemText' ;
15
18
import Stack from '@mui/material/Stack' ;
19
+ import Tooltip from '@mui/material/Tooltip' ;
16
20
import Typography from '@mui/material/Typography' ;
17
21
import Grid from '@mui/material/Unstable_Grid2' ;
18
22
import { useForm } from '@tanstack/react-form' ;
@@ -167,6 +171,12 @@ const GeneralSection = ({
167
171
settings : PersonSettings ;
168
172
mutate : ( s : PersonSettings ) => void ;
169
173
} ) => {
174
+ const [ notifPerms , setNotifPerms ] = useState ( Notification . permission ) ;
175
+
176
+ const notificationsSupported = useMemo ( ( ) => {
177
+ return 'Notification' in window ;
178
+ } , [ ] ) ;
179
+
170
180
const { Field, Subscribe, handleSubmit, reset } = useForm ( {
171
181
onSubmit : async ( { value } ) => {
172
182
mutate ( { ...settings , ...value } ) ;
@@ -177,6 +187,10 @@ const GeneralSection = ({
177
187
}
178
188
} ) ;
179
189
190
+ const togglePerms = async ( ) => {
191
+ setNotifPerms ( await Notification . requestPermission ( ) ) ;
192
+ } ;
193
+
180
194
return (
181
195
< TabSection
182
196
tab = { 'general' }
@@ -192,6 +206,70 @@ const GeneralSection = ({
192
206
} }
193
207
>
194
208
< Grid container spacing = { 2 } >
209
+ { notificationsSupported && (
210
+ < Grid xs = { 12 } >
211
+ < div >
212
+ < Grid container spacing = { 1 } >
213
+ < Grid md = { 6 } xs = { 12 } >
214
+ < Stack spacing = { 1 } >
215
+ < Typography > Show desktop notifications?</ Typography >
216
+ { notifPerms != 'granted' ? (
217
+ < Button
218
+ variant = { 'contained' }
219
+ color = { 'success' }
220
+ onClick = { togglePerms }
221
+ startIcon = { < NotificationsActiveIcon /> }
222
+ >
223
+ Enable Desktop Notifications
224
+ </ Button >
225
+ ) : (
226
+ < Tooltip
227
+ title = {
228
+ 'Please see the links to the right for instructions on how to disable'
229
+ }
230
+ >
231
+ < span >
232
+ < Button
233
+ disabled = { true }
234
+ variant = { 'contained' }
235
+ color = { 'success' }
236
+ onClick = { togglePerms }
237
+ startIcon = { < NotificationsActiveIcon /> }
238
+ >
239
+ Desktop Notifications Enabled
240
+ </ Button >
241
+ </ span >
242
+ </ Tooltip >
243
+ ) }
244
+ </ Stack >
245
+ </ Grid >
246
+ < Grid md = { 6 } xs = { 12 } >
247
+ < Typography > How to disable notifications: </ Typography >
248
+ < List >
249
+ < ListItemText >
250
+ < Link
251
+ href = {
252
+ 'https://support.google.com/chrome/answer/114662?sjid=2540186662959230327-NC&visit_id=638611827496769425-656746251&rd=1'
253
+ }
254
+ >
255
+ Google Chrome
256
+ </ Link >
257
+ </ ListItemText >
258
+ < ListItemText >
259
+ < Link
260
+ href = {
261
+ 'https://support.mozilla.org/en-US/kb/push-notifications-firefox'
262
+ }
263
+ >
264
+ Mozilla Firefox
265
+ </ Link >
266
+ </ ListItemText >
267
+ </ List >
268
+ </ Grid >
269
+ </ Grid >
270
+ </ div >
271
+ </ Grid >
272
+ ) }
195
273
< Grid xs = { 12 } >
196
274
< Field
197
275
name = { 'stats_hidden' }
0 commit comments