main
|
Last change
on this file since a8f4a2d was b62cefc, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago |
|
Added frontend and imporoved AI Suggestions service
|
-
Property mode
set to
100644
|
|
File size:
701 bytes
|
| Line | |
|---|
| 1 | import { create } from 'zustand'
|
|---|
| 2 |
|
|---|
| 3 | interface Toast {
|
|---|
| 4 | id: number
|
|---|
| 5 | message: string
|
|---|
| 6 | type: 'success' | 'error' | 'warning' | 'info'
|
|---|
| 7 | }
|
|---|
| 8 |
|
|---|
| 9 | interface UIStore {
|
|---|
| 10 | toasts: Toast[]
|
|---|
| 11 | addToast: (message: string, type?: Toast['type']) => void
|
|---|
| 12 | removeToast: (id: number) => void
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | export const useUIStore = create<UIStore>((set) => ({
|
|---|
| 16 | toasts: [],
|
|---|
| 17 |
|
|---|
| 18 | addToast: (message, type = 'success') => {
|
|---|
| 19 | const id = Date.now()
|
|---|
| 20 | set(state => ({ toasts: [...state.toasts, { id, message, type }] }))
|
|---|
| 21 | setTimeout(
|
|---|
| 22 | () => set(state => ({ toasts: state.toasts.filter(t => t.id !== id) })),
|
|---|
| 23 | 3500
|
|---|
| 24 | )
|
|---|
| 25 | },
|
|---|
| 26 |
|
|---|
| 27 | removeToast: (id) =>
|
|---|
| 28 | set(state => ({ toasts: state.toasts.filter(t => t.id !== id) })),
|
|---|
| 29 | }))
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.