feat: toasts
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import type { Alert } from '@/types';
|
||||
|
||||
export const useAlertStore = defineStore('alerts', () => {
|
||||
const alerts = ref<Alert[]>([]);
|
||||
|
||||
function addAlert(message: string, type: 'info' | 'success' | 'warning' | 'error', seconds: number) {
|
||||
alerts.value.push({ message, type, created: new Date(), seconds });
|
||||
}
|
||||
|
||||
function alertSuccess(message: string, seconds = 2) {
|
||||
addAlert(message, 'success', seconds);
|
||||
}
|
||||
|
||||
function alertInfo(message: string, seconds = 3) {
|
||||
addAlert(message, 'info', seconds);
|
||||
}
|
||||
|
||||
function alertWarning(message: string, seconds = 4) {
|
||||
addAlert(message, 'warning', seconds);
|
||||
}
|
||||
|
||||
function alertError(message: string, seconds = 5) {
|
||||
addAlert(message, 'error', seconds);
|
||||
}
|
||||
|
||||
return { alerts, alertSuccess, alertInfo, alertWarning, alertError };
|
||||
})
|
||||
Reference in New Issue
Block a user