From 09f964451d7d92e9891430ec4595c1276d486aab Mon Sep 17 00:00:00 2001 From: zwlucas Date: Fri, 5 Jun 2026 17:52:54 -0300 Subject: feat: upload Signed-off-by: zwlucas --- src/stores/useToastStore.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/stores/useToastStore.ts (limited to 'src/stores/useToastStore.ts') diff --git a/src/stores/useToastStore.ts b/src/stores/useToastStore.ts new file mode 100644 index 0000000..ab45325 --- /dev/null +++ b/src/stores/useToastStore.ts @@ -0,0 +1,31 @@ +import { create } from 'zustand' + +export type ToastType = 'success' | 'error' | 'info' | 'warning' + +export interface Toast { + id: string + message: string + type: ToastType +} + +interface ToastState { + toasts: Toast[] + addToast: (message: string, type?: ToastType, duration?: number) => void + removeToast: (id: string) => void +} + +let counter = 0 + +export const useToastStore = create((set, get) => ({ + toasts: [], + addToast: (message, type = 'info', duration = 3500) => { + const id = `toast-${++counter}` + set((s) => ({ toasts: [...s.toasts, { id, message, type }] })) + setTimeout(() => { + get().removeToast(id) + }, duration) + }, + removeToast: (id) => { + set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })) + }, +})) -- cgit v1.2.3