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) {
|
|
|
|
console.log('dismissed');
|
|
|
|
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();
|
2022-11-30 18:26:06 +00:00
|
|
|
alertsStore.addAlert({ message, severity, timeout: 5 });
|
2022-04-15 16:08:41 +00:00
|
|
|
}
|