aboutsummaryrefslogtreecommitdiff
path: root/src/stores/useToastStore.ts
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-06-05 20:52:54 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-06-05 20:52:54 +0000
commit09f964451d7d92e9891430ec4595c1276d486aab (patch)
tree28da4483f5c28924a8c47fceb648b1baebe88224 /src/stores/useToastStore.ts
downloadyace-master.tar.gz
yace-master.zip
feat: uploadHEADmaster
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'src/stores/useToastStore.ts')
-rw-r--r--src/stores/useToastStore.ts31
1 files changed, 31 insertions, 0 deletions
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<ToastState>((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) }))
+ },
+}))