Skip to content

Commit 9ec7e4b

Browse files
committed
fix: notifications type feature
1 parent 03cf68f commit 9ec7e4b

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

GUI/ETVR/src/components/Notifications/CustomToast/index.tsx

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
/* eslint-disable indent */
12
import { Transition, Toast, Alert } from 'solid-headless'
23
import { AiOutlineCheckCircle } from 'solid-icons/ai'
34
import { FiAlertTriangle, FiAlertOctagon } from 'solid-icons/fi'
45
import { IoAlertCircleSharp } from 'solid-icons/io'
56
import { createSignal, Component } from 'solid-js'
67
import CloseIcon from '@components/CloseIcon'
78
import { ENotificationType } from '@static/types/enums'
8-
import { notifications } from '@store/ui/selectors'
9+
import { notifications, notificationsType } from '@store/ui/selectors'
910

1011
interface ToastProps {
1112
id: string
1213
message: string
1314
}
1415

15-
const NotificationIcon = (notificationAction: ENotificationType) => {
16-
switch (notificationAction) {
17-
case ENotificationType.SUCCESS:
18-
return <AiOutlineCheckCircle size={25} color="#68D391" />
19-
case ENotificationType.ERROR:
20-
return <FiAlertOctagon size={25} color="#F56565" />
21-
case ENotificationType.WARNING:
22-
return <FiAlertTriangle size={25} color="#F6E05E" />
23-
case ENotificationType.INFO:
24-
return <IoAlertCircleSharp size={25} color="#90CDF4" />
16+
const NotificationIcon = () => {
17+
switch (notificationsType()) {
18+
case ENotificationType.SUCCESS:
19+
return <AiOutlineCheckCircle size={25} color="#68D391" />
20+
case ENotificationType.ERROR:
21+
return <FiAlertOctagon size={25} color="#F56565" />
22+
case ENotificationType.WARNING:
23+
return <FiAlertTriangle size={25} color="#F6E05E" />
24+
case ENotificationType.INFO:
25+
return <IoAlertCircleSharp size={25} color="#90CDF4" />
2526
}
2627
}
2728

@@ -47,7 +48,7 @@ const CustomToast: Component<ToastProps> = (props) => {
4748
}}>
4849
<Toast class="flex justify-between items-center">
4950
<Alert class="bg-slate-600 flex grow flex-row items-center justify-center text-xl text-bold text-gray-50 p-4">
50-
{/* {NotificationIcon()} */}
51+
{NotificationIcon()}
5152
<span class="flex-1 text-sm font-semibold pl-1 pr-1 text-gray-50">
5253
{props.message}
5354
</span>

GUI/ETVR/src/static/types/enums/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export enum loaderType {
2626

2727
/**
2828
* @description Enum for the different types of notifications
29-
* @enum {string}
29+
* @enum {string} ENotificationType
3030
* @property {string} ERROR - An Error notification
3131
* @property {string} SUCCESS - A Success notification
3232
* @property {string} INFO - An Info notification

GUI/ETVR/src/store/ui/components/actions.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { sendNotification } from '@tauri-apps/api/notification'
55
import { ENotificationAction, ENotificationType } from '@static/types/enums'
66
import { INotifictionMessage, INotificationAction } from '@static/types/interfaces'
77
import { notifications } from '@store/ui/selectors'
8+
import { setNotificationsType } from '@store/ui/ui'
89

910
/**
1011
* Send notification to the WebView Window using the browser API
@@ -24,15 +25,16 @@ export const addNotification = (
2425
notification: INotifictionMessage,
2526
actionType: ENotificationAction,
2627
) => {
27-
const { title, message } = notification
28-
const notificationAction = NotificationsType(actionType, {
28+
const { title, message, type } = notification
29+
const notificationAction = NotificationsType(actionType, {
2930
callbackOS: () => {
3031
sendNotification({
3132
title,
3233
body: message,
3334
})
3435
},
3536
callbackApp: () => {
37+
setNotificationsType(type as ENotificationType)
3638
notifications()?.create(message)
3739
},
3840
})

GUI/ETVR/src/store/ui/selectors.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export const menuOpenStatus = createMemo(() => uiState().menuOpen)
88
export const connectedUserName = createMemo(() => uiState().connectedUser)
99
export const showCameraView = createMemo(() => uiState().showCameraView)
1010
export const notifications = createMemo(() => uiState().notifications)
11+
export const notificationsType = createMemo(() => uiState().notificationsType)
1112
export const displayMode = createMemo(() => uiState().displayMode)

GUI/ETVR/src/store/ui/ui.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ToasterStore } from 'solid-headless'
22
import { createMemo, JSXElement } from 'solid-js'
33
import { createStore, produce } from 'solid-js/store'
4-
import { loaderType, POPOVER_ID } from '@src/static/types/enums'
4+
import { ENotificationType, loaderType, POPOVER_ID } from '@src/static/types/enums'
55

66
interface IMenuOpen {
77
x: number
@@ -28,6 +28,7 @@ export interface IUiStore {
2828
showCameraView?: boolean
2929
connectedUser: string
3030
notifications?: ToasterStore<string>
31+
notificationsType?: ENotificationType
3132
displayMode: POPOVER_ID
3233
}
3334

@@ -99,4 +100,12 @@ export const setShowCameraView = (showCameraView: boolean) => {
99100
)
100101
}
101102

103+
export const setNotificationsType = (type: ENotificationType) => {
104+
setState(
105+
produce((s) => {
106+
s.notificationsType = type
107+
}),
108+
)
109+
}
110+
102111
export const uiState = createMemo(() => state)

0 commit comments

Comments
 (0)