diff --git a/task_yell/src/app/home/page.tsx b/task_yell/src/app/home/page.tsx index 870caf2..199d9f9 100644 --- a/task_yell/src/app/home/page.tsx +++ b/task_yell/src/app/home/page.tsx @@ -117,9 +117,8 @@ function EventCreator({ }) { const [title, setTitle] = useState(initialTitle); const [description, setDescription] = useState(""); - const [selectedDate] = useState(targetDate); - const [startTime] = useState("10:00"); - const [endTime] = useState("11:00"); + const [startTime, setStartTime] = useState(targetDate); + const [endTime, setEndTime] = useState(targetDate); const [location, setLocation] = useState(""); const [invitees, setInvitees] = useState(""); const [category, setCategory] = useState("other"); @@ -132,8 +131,8 @@ function EventCreator({ const newEvent: Event = { id: Date.now(), title, - start: new Date(`${format(selectedDate, "yyyy-MM-dd")}T${startTime}`), - end: new Date(`${format(selectedDate, "yyyy-MM-dd")}T${endTime}`), + start: startTime, + end: endTime, description, category, priority, @@ -150,7 +149,7 @@ function EventCreator({ const renderDaySchedule = () => { // 選択された日のイベントをフィルタリング const dayEvents = events.filter((event) => - isSameDay(event.start, selectedDate), + isSameDay(event.start, startTime), ); const hours = Array.from({ length: 24 }, (_, i) => i); @@ -161,7 +160,7 @@ function EventCreator({ return (

- {format(selectedDate, "yyyy年MM月dd日 (E)", { locale: ja })} + {format(startTime, "yyyy年MM月dd日 (E)", { locale: ja })} のスケジュール

{isTask ? ( - + setStartTime(date)} + /> ) : (
- - + setStartTime(date)} + /> + setEndTime(date)} + />
)} diff --git a/task_yell/src/components/date-time-input.tsx b/task_yell/src/components/date-time-input.tsx index cf64a56..9ec1ba0 100644 --- a/task_yell/src/components/date-time-input.tsx +++ b/task_yell/src/components/date-time-input.tsx @@ -16,20 +16,17 @@ import { CalendarIcon } from "@radix-ui/react-icons"; import { format } from "date-fns"; import { ja } from "date-fns/locale"; -import { useState } from "react"; +import { useMemo } from "react"; export function DateTimeInput({ className, - props, + date, + onChanged, }: { className?: string; - props: { - date: Date; - }; + date: Date; + onChanged: (date: Date) => void; }) { - const [date, setDate] = useState(props.date); - const [time, setTime] = useState(props.date.toLocaleTimeString()); - const timeOptions = Array.from({ length: 96 }, (_, i) => { const hours = Math.floor(i / 4) .toString() @@ -37,7 +34,9 @@ export function DateTimeInput({ const minutes = ((i % 4) * 15).toString().padStart(2, "0"); return `${hours}:${minutes}`; }); - const handleTimeChange = (time: string) => setTime(time); + const time = useMemo(() => { + return `${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`; + }, [date]); return (
@@ -56,14 +55,28 @@ export function DateTimeInput({ setDate(day ?? undefined)} + onSelect={(day) => { + // Dateの日付部分だけ変更 + if (!day) return; + const newDate = new Date(date); + newDate.setFullYear(day.getFullYear()); + newDate.setMonth(day.getMonth()); + newDate.setDate(day.getDate()); + onChanged(newDate); + }} initialFocus />