From 208dddeeb3c90973c73a1c5506a51ba7918d5df9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 05:21:07 +0000 Subject: [PATCH] Fix schedule start date and timeline sort order Agent-Logs-Url: https://github.com/h/CarReservation/sessions/47d2417d-06f8-4edb-95cc-c0d838df7be0 Co-authored-by: h <57948770+h@users.noreply.github.com> --- frontend/src/components/ScheduleView.jsx | 10 ++++------ frontend/src/components/TimelineView.jsx | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/ScheduleView.jsx b/frontend/src/components/ScheduleView.jsx index f585e50..3ac6ecd 100644 --- a/frontend/src/components/ScheduleView.jsx +++ b/frontend/src/components/ScheduleView.jsx @@ -1,5 +1,5 @@ import { useState, useEffect, useRef, useCallback } from 'react'; -import { format, addDays, startOfWeek, parseISO, differenceInDays } from 'date-fns'; +import { format, addDays, parseISO, differenceInDays } from 'date-fns'; import { ja } from 'date-fns/locale'; import { api } from '../api.js'; import { isInspectionExpirySoon, formatDateRange, formatReservationTooltip } from '../utils/carUtils.js'; @@ -43,10 +43,8 @@ export default function ScheduleView({ reloadKey = 0 }) { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - // The first date shown in the grid - const [viewStart, setViewStart] = useState(() => - startOfWeek(new Date(), { weekStartsOn: 1 }) - ); + // The first date shown in the grid (start from today) + const [viewStart, setViewStart] = useState(() => new Date()); // Drag-to-create state const [creating, setCreating] = useState(null); @@ -92,7 +90,7 @@ export default function ScheduleView({ reloadKey = 0 }) { // --- Navigation --- const prevWeek = () => setViewStart((d) => addDays(d, -7)); const nextWeek = () => setViewStart((d) => addDays(d, 7)); - const goToday = () => setViewStart(startOfWeek(new Date(), { weekStartsOn: 1 })); + const goToday = () => setViewStart(new Date()); // --- Grid position helpers --- // Given a mouse clientX within the grid scroll area, get the half-day slot index (0-based) diff --git a/frontend/src/components/TimelineView.jsx b/frontend/src/components/TimelineView.jsx index 2c366e6..daedca4 100644 --- a/frontend/src/components/TimelineView.jsx +++ b/frontend/src/components/TimelineView.jsx @@ -136,9 +136,9 @@ export default function TimelineView({ reloadKey = 0 }) { const carColorMap = {}; cars.forEach((car, i) => { carColorMap[car.id] = getColor(i); }); - // Sort reservations by start_date then car + // Sort reservations by start_date descending (newest first) then car const sortedReservations = [...reservations].sort((a, b) => { - if (a.start_date !== b.start_date) return a.start_date < b.start_date ? -1 : 1; + if (a.start_date !== b.start_date) return a.start_date > b.start_date ? -1 : 1; return a.car_id - b.car_id; });