mizar/src/renderer/stores/notifications.ts

24 lines
689 B
TypeScript
Raw Normal View History

2023-03-19 18:40:03 +01:00
import { defineStore } from 'pinia';
2023-03-21 18:10:35 +01:00
import { uidGen } from '../libs/uidGen';
2023-03-19 18:40:03 +01:00
export interface Notification {
uid: string;
status: string;
message: string;
}
export const useNotificationsStore = defineStore('notifications', {
state: () => ({
notifications: [] as Notification[]
}),
actions: {
addNotification (payload: { status: string; message: string }) {
const notification: Notification = { uid: uidGen('N'), ...payload };
this.notifications.unshift(notification);
},
removeNotification (uid: string) {
this.notifications = (this.notifications as Notification[]).filter(item => item.uid !== uid);
}
}
});