diff --git a/frontend/src/components/AddLogModal.tsx b/frontend/src/components/AddLogModal.tsx index d3d6a84..00cf4a9 100644 --- a/frontend/src/components/AddLogModal.tsx +++ b/frontend/src/components/AddLogModal.tsx @@ -1,5 +1,5 @@ -import { useState, useEffect } from 'react'; -import { format, parseISO } from 'date-fns'; +import { useState, useEffect, useRef } from 'react'; +import { format, parseISO, addDays, subDays } from 'date-fns'; import type { TimeLog } from '../hooks/useLogs'; interface Props { @@ -16,12 +16,16 @@ function formatTimeForInput(hours: number, mins: number): string { return `${hours}:${String(mins).padStart(2, '0')}`; } +// Store last used date outside component to persist between modal opens +let lastUsedDate: string | null = null; + export function AddLogModal({ isOpen, onClose, onSave, editingLog }: Props) { const [date, setDate] = useState(format(new Date(), 'yyyy-MM-dd')); const [time, setTime] = useState('8'); const [description, setDescription] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); + const initializedRef = useRef(false); useEffect(() => { if (isOpen) { @@ -30,14 +34,25 @@ export function AddLogModal({ isOpen, onClose, onSave, editingLog }: Props) { setTime(formatTimeForInput(editingLog.hours, editingLog.mins)); setDescription(editingLog.description); } else { - setDate(format(new Date(), 'yyyy-MM-dd')); + // Use last used date or today + setDate(lastUsedDate || format(new Date(), 'yyyy-MM-dd')); setTime('8'); setDescription(''); } setError(''); + initializedRef.current = true; + } else { + initializedRef.current = false; } }, [isOpen, editingLog]); + // Save date when it changes (but not on initial load) + useEffect(() => { + if (initializedRef.current && !editingLog) { + lastUsedDate = date; + } + }, [date, editingLog]); + if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { @@ -59,6 +74,18 @@ export function AddLogModal({ isOpen, onClose, onSave, editingLog }: Props) { setTime(value); }; + const handlePrevDay = () => { + const currentDate = parseISO(date); + setDate(format(subDays(currentDate, 1), 'yyyy-MM-dd')); + }; + + const handleNextDay = () => { + const currentDate = parseISO(date); + setDate(format(addDays(currentDate, 1), 'yyyy-MM-dd')); + }; + + const displayDate = format(parseISO(date), 'dd/MM/yyyy'); + return (
@@ -71,13 +98,40 @@ export function AddLogModal({ isOpen, onClose, onSave, editingLog }: Props) { - setDate(e.target.value)} - className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" - required - /> +
+ +
+ setDate(e.target.value)} + className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 opacity-0 absolute inset-0 cursor-pointer" + required + /> +
+ {displayDate} +
+
+ +
diff --git a/frontend/src/components/LogList.tsx b/frontend/src/components/LogList.tsx index c8449c2..d435281 100644 --- a/frontend/src/components/LogList.tsx +++ b/frontend/src/components/LogList.tsx @@ -1,6 +1,5 @@ import { useState, useRef, useEffect } from 'react'; import { format, parseISO } from 'date-fns'; -import { ru } from 'date-fns/locale'; import type { TimeLog } from '../hooks/useLogs'; interface Props { @@ -143,7 +142,7 @@ export function LogList({ logs, onDelete, onEdit, onUpdateTime, isLoading }: Pro
- {format(parseISO(dateKey), 'd MMMM yyyy', { locale: ru })} + {format(parseISO(dateKey), 'dd/MM/yyyy')} Всего: {formatTime(totalHours, totalMins)}