Merge pull request #9 from pdf114514/copilot/update-schedule-and-timeline-order

Start schedule view from today; sort timeline by newest first
This commit is contained in:
h
2026-04-15 14:22:48 +09:00
committed by GitHub
2 changed files with 6 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { useState, useEffect, useRef, useCallback } from 'react'; 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 { ja } from 'date-fns/locale';
import { api } from '../api.js'; import { api } from '../api.js';
import { isInspectionExpirySoon, formatDateRange, formatReservationTooltip } from '../utils/carUtils.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 [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
// The first date shown in the grid // The first date shown in the grid (start from today)
const [viewStart, setViewStart] = useState(() => const [viewStart, setViewStart] = useState(() => new Date());
startOfWeek(new Date(), { weekStartsOn: 1 })
);
// Drag-to-create state // Drag-to-create state
const [creating, setCreating] = useState(null); const [creating, setCreating] = useState(null);
@@ -92,7 +90,7 @@ export default function ScheduleView({ reloadKey = 0 }) {
// --- Navigation --- // --- Navigation ---
const prevWeek = () => setViewStart((d) => addDays(d, -7)); const prevWeek = () => setViewStart((d) => addDays(d, -7));
const nextWeek = () => 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 --- // --- Grid position helpers ---
// Given a mouse clientX within the grid scroll area, get the half-day slot index (0-based) // Given a mouse clientX within the grid scroll area, get the half-day slot index (0-based)

View File

@@ -136,9 +136,9 @@ export default function TimelineView({ reloadKey = 0 }) {
const carColorMap = {}; const carColorMap = {};
cars.forEach((car, i) => { carColorMap[car.id] = getColor(i); }); 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) => { 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; return a.car_id - b.car_id;
}); });