diff --git a/frontend/src/components/CarManagement.jsx b/frontend/src/components/CarManagement.jsx index 5539e93..9751ff7 100644 --- a/frontend/src/components/CarManagement.jsx +++ b/frontend/src/components/CarManagement.jsx @@ -118,11 +118,7 @@ export default function CarManagement({ reloadKey = 0 }) { } }; - const handleReorder = async (index, direction) => { - const newCars = [...cars]; - const swapIndex = index + direction; - if (swapIndex < 0 || swapIndex >= newCars.length) return; - [newCars[index], newCars[swapIndex]] = [newCars[swapIndex], newCars[index]]; + const applyReorder = async (newCars) => { setCars(newCars); try { await api.reorderCars(newCars.map((c) => c.id)); @@ -132,6 +128,14 @@ export default function CarManagement({ reloadKey = 0 }) { } }; + const handleReorder = async (index, direction) => { + const swapIndex = index + direction; + if (swapIndex < 0 || swapIndex >= cars.length) return; + const newCars = [...cars]; + [newCars[index], newCars[swapIndex]] = [newCars[swapIndex], newCars[index]]; + await applyReorder(newCars); + }; + const handleDragStart = (index) => { dragSrcIdx.current = index; }; @@ -155,13 +159,7 @@ export default function CarManagement({ reloadKey = 0 }) { const newCars = [...cars]; const [moved] = newCars.splice(srcIndex, 1); newCars.splice(dropIndex, 0, moved); - setCars(newCars); - try { - await api.reorderCars(newCars.map((c) => c.id)); - } catch (e) { - setError(e.message); - await loadCars(); - } + await applyReorder(newCars); }; return (