From 7a04012b6016ead721e996da9de4e34d59583586 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 07:48:47 +0000 Subject: [PATCH] refactor: extract shared applyReorder helper in CarManagement Agent-Logs-Url: https://github.com/pdf114514/CarReservation/sessions/c5f8f1a2-8a8b-4951-8442-76ce37d906ae Co-authored-by: pdf114514 <57948770+pdf114514@users.noreply.github.com> --- frontend/src/components/CarManagement.jsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) 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 (