Add drag-and-drop section reordering
This commit is contained in:
@@ -158,6 +158,18 @@ export function useCarts() {
|
||||
}))
|
||||
}
|
||||
|
||||
function reorderSections(fromId: string, toId: string) {
|
||||
mutateActiveCart(cart => {
|
||||
const sections = [...cart.sections]
|
||||
const fromIdx = sections.findIndex(s => s.id === fromId)
|
||||
const toIdx = sections.findIndex(s => s.id === toId)
|
||||
if (fromIdx === -1 || toIdx === -1 || fromIdx === toIdx) return cart
|
||||
const [moved] = sections.splice(fromIdx, 1)
|
||||
sections.splice(toIdx, 0, moved)
|
||||
return { ...cart, sections }
|
||||
})
|
||||
}
|
||||
|
||||
// ── Item management ───────────────────────────────────────────────────────
|
||||
|
||||
function addItem(sectionId: string, item: Product | Drone) {
|
||||
@@ -220,6 +232,7 @@ export function useCarts() {
|
||||
addSection,
|
||||
removeSection,
|
||||
renameSection,
|
||||
reorderSections,
|
||||
addItem,
|
||||
updateItem,
|
||||
removeItem,
|
||||
|
||||
Reference in New Issue
Block a user