forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.ts
More file actions
45 lines (37 loc) · 938 Bytes
/
Copy pathnotifications.ts
File metadata and controls
45 lines (37 loc) · 938 Bytes
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
import { defineStore } from 'pinia'
export type NotificationType = 'error' | 'success' | 'info'
export interface Notification {
message: string
timeout: number
active: boolean
type: NotificationType
}
export interface NotificationRequest {
message: string
type: NotificationType
}
const DEFAULT_TIMEOUT = 3000
export const useNotificationsStore = defineStore('notifications', () => {
const notification = ref<Notification>({
active: false,
message: '',
type: 'success',
timeout: DEFAULT_TIMEOUT,
})
function addNotification(request: NotificationRequest) {
notification.value = {
active: true,
message: request.message,
type: request.type,
timeout: Math.floor(Math.random() * 100) + DEFAULT_TIMEOUT,
}
}
function disableNotification() {
notification.value.active = false
}
return {
notification,
addNotification,
disableNotification,
}
})