Add drag-and-drop section reordering

This commit is contained in:
2026-04-20 01:14:11 +02:00
parent 70315a3fd1
commit bcda0e7315
3 changed files with 47 additions and 3 deletions
+13
View File
@@ -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,