Improve the frontend 3
This commit is contained in:
@@ -6,6 +6,9 @@ export type Language = 'es' | 'en' | 'eu';
|
||||
export type ViewMode = 'list' | 'grid' | 'card';
|
||||
export type SidebarState = 'expanded' | 'collapsed' | 'hidden';
|
||||
|
||||
// Toast interface kept for backward compatibility but toast functionality
|
||||
// has been moved to src/utils/toast.ts using react-hot-toast
|
||||
// This interface is deprecated and will be removed in a future version
|
||||
export interface Toast {
|
||||
id: string;
|
||||
type: 'success' | 'error' | 'warning' | 'info';
|
||||
@@ -45,10 +48,7 @@ export interface UIState {
|
||||
// Loading States
|
||||
globalLoading: boolean;
|
||||
loadingStates: Record<string, boolean>;
|
||||
|
||||
// Toasts & Notifications
|
||||
toasts: Toast[];
|
||||
|
||||
|
||||
// Modals & Dialogs
|
||||
modals: Modal[];
|
||||
|
||||
@@ -77,11 +77,7 @@ export interface UIState {
|
||||
setGlobalLoading: (loading: boolean) => void;
|
||||
setLoading: (key: string, loading: boolean) => void;
|
||||
isLoading: (key: string) => boolean;
|
||||
|
||||
showToast: (toast: Omit<Toast, 'id'>) => string;
|
||||
hideToast: (id: string) => void;
|
||||
clearToasts: () => void;
|
||||
|
||||
|
||||
showModal: (modal: Omit<Modal, 'id'>) => string;
|
||||
hideModal: (id: string) => void;
|
||||
clearModals: () => void;
|
||||
@@ -119,8 +115,7 @@ export const useUIStore = create<UIState>()(
|
||||
|
||||
globalLoading: false,
|
||||
loadingStates: {},
|
||||
|
||||
toasts: [],
|
||||
|
||||
modals: [],
|
||||
|
||||
preferences: defaultPreferences,
|
||||
@@ -211,39 +206,6 @@ export const useUIStore = create<UIState>()(
|
||||
return get().loadingStates[key] ?? false;
|
||||
},
|
||||
|
||||
// Toast actions
|
||||
showToast: (toast: Omit<Toast, 'id'>): string => {
|
||||
const id = `toast-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
||||
const newToast: Toast = {
|
||||
...toast,
|
||||
id,
|
||||
duration: toast.duration ?? (toast.type === 'error' ? 0 : 5000), // Error toasts don't auto-dismiss
|
||||
};
|
||||
|
||||
set((state) => ({
|
||||
toasts: [...state.toasts, newToast],
|
||||
}));
|
||||
|
||||
// Auto-dismiss toast if duration is set
|
||||
if (newToast.duration && newToast.duration > 0) {
|
||||
setTimeout(() => {
|
||||
get().hideToast(id);
|
||||
}, newToast.duration);
|
||||
}
|
||||
|
||||
return id;
|
||||
},
|
||||
|
||||
hideToast: (id: string) => {
|
||||
set((state) => ({
|
||||
toasts: state.toasts.filter(toast => toast.id !== id),
|
||||
}));
|
||||
},
|
||||
|
||||
clearToasts: () => {
|
||||
set({ toasts: [] });
|
||||
},
|
||||
|
||||
// Modal actions
|
||||
showModal: (modal: Omit<Modal, 'id'>): string => {
|
||||
const id = `modal-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
||||
@@ -336,7 +298,6 @@ export const useLoading = (key?: string) => {
|
||||
return useUIStore((state) => state.globalLoading);
|
||||
};
|
||||
|
||||
export const useToasts = () => useUIStore((state) => state.toasts);
|
||||
export const useModals = () => useUIStore((state) => state.modals);
|
||||
|
||||
export const useBreadcrumbs = () => useUIStore((state) => ({
|
||||
@@ -358,9 +319,6 @@ export const useUIActions = () => useUIStore((state) => ({
|
||||
setViewMode: state.setViewMode,
|
||||
setGlobalLoading: state.setGlobalLoading,
|
||||
setLoading: state.setLoading,
|
||||
showToast: state.showToast,
|
||||
hideToast: state.hideToast,
|
||||
clearToasts: state.clearToasts,
|
||||
showModal: state.showModal,
|
||||
hideModal: state.hideModal,
|
||||
clearModals: state.clearModals,
|
||||
|
||||
Reference in New Issue
Block a user