Files
duty-schedule-fe/src/stores/notifications.ts

33 lines
926 B
TypeScript

import { defineStore, acceptHMRUpdate } from 'pinia'
import { v4 as uuidv4 } from 'uuid'
export const useNotifications = defineStore('notifications', {
state: () => {
return {
/**@type {Map<string, {type: string, text: string}>} */
notifications: new Map<string, {type: string, text: string}>()
}
},
actions: {
remove(id : string) : void {
this.notifications.delete(id)
},
add(type : string, text: string, timeout: number = 1000) : void {
const id = uuidv4()
this.notifications.set(
id,
{
type:type,
text:text,
}
)
if (timeout > -1) setTimeout(() => this.remove(id), timeout)
}
}
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useNotifications, import.meta.hot))
}