frequi_origin/src/stores/alerts.ts
2022-12-03 14:55:39 +01:00

23 lines
630 B
TypeScript

import { defineStore } from 'pinia';
import { AlertType } from '@/types/alertTypes';
export const useAlertsStore = defineStore('alerts', {
state: () => {
return { activeMessages: [] as AlertType[] };
},
actions: {
addAlert(message: AlertType) {
this.activeMessages.push(message);
},
removeAlert(alert: AlertType) {
console.log('dismissed');
this.activeMessages = this.activeMessages.filter((v) => v !== alert);
},
},
});
export function showAlert(message: string, severity = '') {
const alertsStore = useAlertsStore();
alertsStore.addAlert({ message, severity, timeout: 5 });
}