fix: apply designer agent improvements to src/store/navigationStore.ts
This commit is contained in:
parent
283a71dc8e
commit
4e960ba152
|
|
@ -0,0 +1,53 @@
|
|||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export interface NavItem {
|
||||
id: string
|
||||
label: string
|
||||
href: string
|
||||
target: '_self' | '_blank'
|
||||
order: number
|
||||
parentId: string | null
|
||||
isVisible: boolean
|
||||
}
|
||||
|
||||
interface NavigationStore {
|
||||
items: NavItem[]
|
||||
addItem: (item: Omit<NavItem, 'id'>) => void
|
||||
updateItem: (id: string, partial: Partial<NavItem>) => void
|
||||
removeItem: (id: string) => void
|
||||
reorderItems: (items: NavItem[]) => void
|
||||
}
|
||||
|
||||
const defaultNavItems: NavItem[] = [
|
||||
{ id: uuidv4(), label: 'Accueil', href: '/', target: '_self', order: 0, parentId: null, isVisible: true },
|
||||
{ id: uuidv4(), label: 'L\'Association', href: '/about', target: '_self', order: 1, parentId: null, isVisible: true },
|
||||
{ id: uuidv4(), label: 'Actualités', href: '/blog', target: '_self', order: 2, parentId: null, isVisible: true },
|
||||
{ id: uuidv4(), label: 'Mémoire', href: '/memorial', target: '_self', order: 3, parentId: null, isVisible: true },
|
||||
{ id: uuidv4(), label: 'Contact', href: '/contact', target: '_self', order: 4, parentId: null, isVisible: true },
|
||||
]
|
||||
|
||||
export const useNavigationStore = create<NavigationStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
items: defaultNavItems,
|
||||
addItem: (item) =>
|
||||
set((state) => ({
|
||||
items: [...state.items, { ...item, id: uuidv4() }],
|
||||
})),
|
||||
updateItem: (id, partial) =>
|
||||
set((state) => ({
|
||||
items: state.items.map((item) =>
|
||||
item.id === id ? { ...item, ...partial } : item
|
||||
),
|
||||
})),
|
||||
removeItem: (id) =>
|
||||
set((state) => ({
|
||||
items: state.items.filter((item) => item.id !== id),
|
||||
})),
|
||||
reorderItems: (items) => set({ items }),
|
||||
}),
|
||||
{ name: 'cms-navigation' }
|
||||
)
|
||||
)
|
||||
Loading…
Reference in New Issue