2022-04-15 16:08:41 +00:00
|
|
|
import { defineStore } from 'pinia';
|
2022-12-05 05:54:06 +00:00
|
|
|
import { AlertSeverity, AlertType } from '@/types/alertTypes';
|
2022-04-15 16:08:41 +00:00
|
|
|
|
|
|
|
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) {
|
2022-12-07 06:04:31 +00:00
|
|
|
console.log('dismissed', alert);
|
2022-11-30 18:26:06 +00:00
|
|
|
this.activeMessages = this.activeMessages.filter((v) => v !== alert);
|
2022-04-15 16:08:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-12-05 05:54:06 +00:00
|
|
|
export function showAlert(message: string, severity: AlertSeverity = 'warning') {
|
2022-04-15 16:08:41 +00:00
|
|
|
const alertsStore = useAlertsStore();
|
2023-01-04 12:31:43 +00:00
|
|
|
alertsStore.addAlert({ message, severity, timeout: 5000 });
|
2022-04-15 16:08:41 +00:00
|
|
|
}
|