generated from ZanzyTHEbar/SolidJSTauri
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaddNotification.ts
More file actions
68 lines (63 loc) · 2.25 KB
/
addNotification.ts
File metadata and controls
68 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { NOTIFICATION_ACTION, NOTIFICATION_TYPE } from '@interfaces/notifications/enums'
import { NotificationAction, Notifications } from '@store/notifications/notifications'
import { enableNotifications, globalNotificationsType } from '@store/notifications/selectors'
import { toast } from 'solid-sonner'
import { checkPermission } from './checkPermission'
import { handleSound } from './handleSound'
const mapNotificationCallback = (
type: NOTIFICATION_ACTION,
{ callbackOS, callbackApp }: NotificationAction,
) => {
/* eslint-disable */
switch (type) {
case NOTIFICATION_ACTION.OS:
return callbackOS()
case NOTIFICATION_ACTION.APP:
return callbackApp()
}
/* eslint-enable */
}
export const addNotification = (notification: Notifications) => {
if (!enableNotifications()) return
checkPermission()
const { message, type } = notification
const toastOptions = {
style: {
background: '#0D1B26',
color: '#fff',
border: '1px solid #192736',
textAlign: 'left',
},
actionButtonStyle: {
background: '#192736',
border: '1px solid #192736',
color: '#FFFFFF',
},
class: 'my-custom-toast',
action: {
label: 'X',
onClick: () => console.log('Undo'),
},
}
const toastMap: Record<NOTIFICATION_TYPE, (msg: string) => void> = {
[NOTIFICATION_TYPE.ERROR]: (msg) => toast.error(msg, toastOptions),
[NOTIFICATION_TYPE.SUCCESS]: (msg) => toast.success(msg, toastOptions),
[NOTIFICATION_TYPE.INFO]: (msg) => toast.info(msg, toastOptions),
[NOTIFICATION_TYPE.WARNING]: (msg) => toast.warning(msg, toastOptions),
[NOTIFICATION_TYPE.DEFAULT]: (msg) => toast(msg, toastOptions),
}
mapNotificationCallback(globalNotificationsType(), {
callbackOS: () => {
toast(message, {
action: {
label: 'Close',
onClick: () => console.log('Undo'),
},
})
},
callbackApp: () => {
handleSound('EyeTrackApp_Audio_notif.mp3')
toastMap[type ?? NOTIFICATION_TYPE.DEFAULT](message)
},
})
}