Initial commit
This commit is contained in:
67
stores/ui-store.ts
Normal file
67
stores/ui-store.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools, persist } from 'zustand/middleware';
|
||||
|
||||
interface Notification {
|
||||
id: string;
|
||||
title: string;
|
||||
message: string;
|
||||
type: 'success' | 'error' | 'warning' | 'info';
|
||||
}
|
||||
|
||||
interface UIState {
|
||||
// Sidebar
|
||||
sidebarOpen: boolean;
|
||||
toggleSidebar: () => void;
|
||||
setSidebarOpen: (open: boolean) => void;
|
||||
|
||||
// Theme
|
||||
theme: 'light' | 'dark' | 'system';
|
||||
setTheme: (theme: 'light' | 'dark' | 'system') => void;
|
||||
|
||||
// Modals
|
||||
openModal: string | null;
|
||||
setOpenModal: (modal: string | null) => void;
|
||||
|
||||
// Notifications
|
||||
notifications: Notification[];
|
||||
addNotification: (notification: Omit<Notification, 'id'>) => void;
|
||||
removeNotification: (id: string) => void;
|
||||
}
|
||||
|
||||
export const useUIStore = create<UIState>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set) => ({
|
||||
sidebarOpen: true,
|
||||
toggleSidebar: () => set((state) => ({ sidebarOpen: !state.sidebarOpen })),
|
||||
setSidebarOpen: (open) => set({ sidebarOpen: open }),
|
||||
|
||||
theme: 'system',
|
||||
setTheme: (theme) => set({ theme }),
|
||||
|
||||
openModal: null,
|
||||
setOpenModal: (modal) => set({ openModal: modal }),
|
||||
|
||||
notifications: [],
|
||||
addNotification: (notification) =>
|
||||
set((state) => ({
|
||||
notifications: [
|
||||
...state.notifications,
|
||||
{ ...notification, id: crypto.randomUUID() },
|
||||
],
|
||||
})),
|
||||
removeNotification: (id) =>
|
||||
set((state) => ({
|
||||
notifications: state.notifications.filter((n) => n.id !== id),
|
||||
})),
|
||||
}),
|
||||
{
|
||||
name: 'colaflow-ui-storage',
|
||||
partialize: (state) => ({
|
||||
sidebarOpen: state.sidebarOpen,
|
||||
theme: state.theme
|
||||
}),
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user