forked from noxious/client
23 lines
691 B
TypeScript
23 lines
691 B
TypeScript
import { defineStore, type StoreDefinition } from 'pinia'
|
|
import type { Notification } from '@/types'
|
|
|
|
export const useNotificationStore: StoreDefinition = defineStore('notifications', {
|
|
state: () => ({
|
|
notifications: [] as Notification[]
|
|
}),
|
|
getters: {
|
|
getNotifications: (state: any) => state.notifications
|
|
},
|
|
actions: {
|
|
addNotification(notification: Notification) {
|
|
if (!notification.id) {
|
|
notification.id = Math.random().toString(16)
|
|
}
|
|
this.notifications.push(notification)
|
|
},
|
|
removeNotification(id: string) {
|
|
this.notifications = this.notifications.filter((notification: Notification) => notification.id !== id)
|
|
}
|
|
}
|
|
})
|