[FEAT] Toastr and saving UX improvements

This commit is contained in:
2026-01-02 20:35:50 +01:00
parent cabc1f747f
commit 009f8810e0
7 changed files with 234 additions and 8 deletions

View File

@@ -0,0 +1,39 @@
import { ref } from 'vue';
export type ToastType = 'success' | 'error' | 'info' | 'warning';
export interface Toast {
id: string;
message: string;
type: ToastType;
duration?: number;
}
const toasts = ref<Toast[]>([]);
export function useToast() {
const addToast = (message: string, type: ToastType = 'info', duration: number = 3000) => {
const id = Date.now().toString(36) + Math.random().toString(36).substr(2);
const toast: Toast = { id, message, type, duration };
toasts.value.push(toast);
if (duration > 0) {
setTimeout(() => {
removeToast(id);
}, duration);
}
};
const removeToast = (id: string) => {
const index = toasts.value.findIndex(t => t.id === id);
if (index !== -1) {
toasts.value.splice(index, 1);
}
};
return {
toasts,
addToast,
removeToast,
};
}