frequi_origin/src/stores/alerts.ts

23 lines
630 B
TypeScript
Raw Normal View History

2022-04-15 16:08:41 +00:00
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);
},
2022-11-30 18:26:06 +00:00
removeAlert(alert: AlertType) {
console.log('dismissed');
this.activeMessages = this.activeMessages.filter((v) => v !== alert);
2022-04-15 16:08:41 +00:00
},
},
});
export function showAlert(message: string, severity = '') {
const alertsStore = useAlertsStore();
2022-11-30 18:26:06 +00:00
alertsStore.addAlert({ message, severity, timeout: 5 });
2022-04-15 16:08:41 +00:00
}