From 3b49844d0bd6d4342ee8e33464822f2dc8539132 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 07:47:08 +0000 Subject: [PATCH 1/2] fix: preserve AM/PM when dragging reservation; add drag & drop car reordering 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 | 46 ++++++++++++++++++- .../src/components/CarManagement.module.css | 10 ++++ frontend/src/components/ScheduleView.jsx | 2 + 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/CarManagement.jsx b/frontend/src/components/CarManagement.jsx index 977883a..5539e93 100644 --- a/frontend/src/components/CarManagement.jsx +++ b/frontend/src/components/CarManagement.jsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback } from 'react'; +import { useState, useEffect, useCallback, useRef } from 'react'; import { api } from '../api.js'; import { isInspectionExpirySoon } from '../utils/carUtils.js'; import styles from './CarManagement.module.css'; @@ -20,6 +20,8 @@ export default function CarManagement({ reloadKey = 0 }) { const [editEtc, setEditEtc] = useState(false); const [editTire, setEditTire] = useState('ノーマル'); const [submitting, setSubmitting] = useState(false); + const [dragOverIdx, setDragOverIdx] = useState(null); + const dragSrcIdx = useRef(null); const loadCars = useCallback(async () => { try { @@ -130,6 +132,38 @@ export default function CarManagement({ reloadKey = 0 }) { } }; + const handleDragStart = (index) => { + dragSrcIdx.current = index; + }; + + const handleDragOver = (e, index) => { + e.preventDefault(); + setDragOverIdx(index); + }; + + const handleDragEnd = () => { + setDragOverIdx(null); + dragSrcIdx.current = null; + }; + + const handleDrop = async (e, dropIndex) => { + e.preventDefault(); + const srcIndex = dragSrcIdx.current; + setDragOverIdx(null); + dragSrcIdx.current = null; + if (srcIndex === null || srcIndex === dropIndex) return; + 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(); + } + }; + return (