From 030488a451bf9ae9b3ebde3701425aa3a4a1e25c Mon Sep 17 00:00:00 2001 From: Leo dev Date: Wed, 19 Feb 2025 20:49:24 +0100 Subject: [PATCH] improved time select and calendar --- src/app/calendar/page.tsx | 13 +++++++++++++ src/app/calendar/timeSelect.tsx | 21 ++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/app/calendar/page.tsx b/src/app/calendar/page.tsx index b88a7a1..ac6f20f 100644 --- a/src/app/calendar/page.tsx +++ b/src/app/calendar/page.tsx @@ -83,8 +83,21 @@ function CalendarApp() { const [newPostDialogOpen, setNewPostDialogOpen] = useState(false); const [date, setDate] = useState(today); const [selected, setSelected] = useState(null); + const [scrollY, setScrollY] = useState(0); + + useEffect(() => { + const interval = setInterval(() => { + window.scrollTo(0, scrollY); + }, 10); + + setTimeout(() => { + clearInterval(interval); + }, 300); + }, [scrollY]); const handleDialog: MouseEventHandler = (event) => { + setScrollY(window.scrollY); + const target = event.target as HTMLElement; if (target.className === 'sx__time-grid-event-time') { diff --git a/src/app/calendar/timeSelect.tsx b/src/app/calendar/timeSelect.tsx index 7a1fb4c..4e38c0f 100644 --- a/src/app/calendar/timeSelect.tsx +++ b/src/app/calendar/timeSelect.tsx @@ -17,14 +17,16 @@ const TimeSelect: React.FC = ({ setDate, className, }) => { - const times = Array.from({ length: 24 }, (_, h) => - [0, 15, 30, 45].map( - (m) => - `${(h+1).toString().padStart(2, '0')}:${m - .toString() - .padStart(2, '0')}` - ) - ).flat(); + const times = ['00:00'].concat( + Array.from({ length: 23 }, (_, h) => + [0, 15, 30, 45].map( + (m) => + `${(h + 1).toString().padStart(2, '0')}:${m + .toString() + .padStart(2, '0')}` + ) + ).flat() + ); const currentHour = date.getHours().toString().padStart(2, '0'); const currentMinute = date.getMinutes(); @@ -39,8 +41,9 @@ const TimeSelect: React.FC = ({ const handleTimeChange = (newTime: string) => { const [hour, minute] = newTime.split(':').map(Number); + console.log(hour, minute); const newDate = new Date(date); - newDate.setHours(hour, minute, 0, 0); + newDate.setHours(hour === 24 ? 0 : hour, minute, 0, 0); setDate(newDate); };