diff --git a/src/app/(afterLogin)/schedule/_components/sideSection.tsx b/src/app/(afterLogin)/schedule/_components/sideSection.tsx index 810d4be..ece6a50 100644 --- a/src/app/(afterLogin)/schedule/_components/sideSection.tsx +++ b/src/app/(afterLogin)/schedule/_components/sideSection.tsx @@ -4,45 +4,50 @@ import CalendarCheck from "@/assets/CalendarCheck.svg"; import { useSchedule } from "@/hooks/useSchedule"; import { Schedule } from "@/type/schedule"; import LoadingSpinner from "@/app/_components/loadingSpinner"; +import { useMemo } from "react"; -export default function SideSection() { - function formatDateToApiString(date: Date) { - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, "0"); - const day = String(date.getDate()).padStart(2, "0"); - const hours = String(date.getHours()).padStart(2, "0"); - const minutes = String(date.getMinutes()).padStart(2, "0"); - const seconds = String(date.getSeconds()).padStart(2, "0"); - return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`; - } - - const startDate = formatDateToApiString(new Date()); - const endDate = formatDateToApiString( - new Date(new Date().setDate(new Date().getDate() + 7)) - ); +function formatDateToApiString(date: Date) { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const day = String(date.getDate()).padStart(2, "0"); + const hours = String(date.getHours()).padStart(2, "0"); + const minutes = String(date.getMinutes()).padStart(2, "0"); + const seconds = String(date.getSeconds()).padStart(2, "0"); + return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`; +} - function getDDay(dateTime: string) { - const today = new Date(); - const targetDate = new Date(dateTime); +function getDDay(dateTime: string) { + const today = new Date(); + const targetDate = new Date(dateTime); - const todayOnly = new Date( - today.getFullYear(), - today.getMonth(), - today.getDate() - ); - const targetOnly = new Date( - targetDate.getFullYear(), - targetDate.getMonth(), - targetDate.getDate() - ); + const todayOnly = new Date( + today.getFullYear(), + today.getMonth(), + today.getDate() + ); + const targetOnly = new Date( + targetDate.getFullYear(), + targetDate.getMonth(), + targetDate.getDate() + ); - const diffTime = targetOnly.getTime() - todayOnly.getTime(); - const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + const diffTime = targetOnly.getTime() - todayOnly.getTime(); + const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - if (diffDays > 0) return `D-${diffDays}`; - else if (diffDays === 0) return `D-Day`; - else return `D+${Math.abs(diffDays)}`; - } + if (diffDays > 0) return `D-${diffDays}`; + else if (diffDays === 0) return `D-Day`; + else return `D+${Math.abs(diffDays)}`; +} +export default function SideSection() { + const { startDate, endDate } = useMemo(() => { + const now = new Date(); + const futureDate = new Date(now); + futureDate.setDate(now.getDate() + 7); + return { + startDate: formatDateToApiString(now), + endDate: formatDateToApiString(futureDate), + }; + }, []); const { data: scheduleData, isLoading: scheduleLoading } = useSchedule( startDate, @@ -53,16 +58,19 @@ export default function SideSection() { return (