From 81b78be0107f85efd43db403c0cb2cc0b65a31e1 Mon Sep 17 00:00:00 2001 From: caadiq Date: Wed, 21 Jan 2026 18:01:09 +0900 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20useCalendar=20=EB=B0=8F=20Sche?= =?UTF-8?q?dule=20=EB=82=A0=EC=A7=9C=20=EC=B2=98=EB=A6=AC=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - useCalendar: initialDate가 문자열일 경우 Date 객체로 변환 - useCalendar: days 배열 추가 (캘린더 날짜 목록) - useCalendar: canGoPrev 별칭 추가 - Schedule: currentDate가 Date 객체가 아닐 경우 안전하게 변환 Co-Authored-By: Claude Opus 4.5 --- frontend-temp/src/hooks/useCalendar.js | 44 ++++++++++++++++++- frontend-temp/src/pages/schedule/Schedule.jsx | 5 ++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/frontend-temp/src/hooks/useCalendar.js b/frontend-temp/src/hooks/useCalendar.js index 8a2e190..59e434c 100644 --- a/frontend-temp/src/hooks/useCalendar.js +++ b/frontend-temp/src/hooks/useCalendar.js @@ -5,10 +5,17 @@ import { getTodayKST } from '@/utils'; /** * 캘린더 훅 * 날짜 선택, 월 이동 등 캘린더 로직 제공 - * @param {Date} initialDate - 초기 날짜 + * @param {Date|string} initialDate - 초기 날짜 */ export function useCalendar(initialDate = new Date()) { - const [currentDate, setCurrentDate] = useState(initialDate); + // initialDate가 Date 객체가 아니면 변환 + const ensureDate = (date) => { + if (date instanceof Date) return date; + if (typeof date === 'string') return new Date(date); + return new Date(); + }; + + const [currentDate, setCurrentDate] = useState(() => ensureDate(initialDate)); const [selectedDate, setSelectedDate] = useState(getTodayKST()); const year = currentDate.getFullYear(); @@ -20,6 +27,37 @@ export function useCalendar(initialDate = new Date()) { const daysInMonth = new Date(year, month + 1, 0).getDate(); const prevMonthDays = new Date(year, month, 0).getDate(); + // 캘린더에 표시할 날짜 배열 생성 + const days = []; + + // 이전 달 날짜 + for (let i = firstDay - 1; i >= 0; i--) { + days.push({ + day: prevMonthDays - i, + isCurrentMonth: false, + date: new Date(year, month - 1, prevMonthDays - i), + }); + } + + // 현재 달 날짜 + for (let i = 1; i <= daysInMonth; i++) { + days.push({ + day: i, + isCurrentMonth: true, + date: new Date(year, month, i), + }); + } + + // 다음 달 날짜 (6주 채우기) + const remaining = 42 - days.length; // 6주 * 7일 = 42 + for (let i = 1; i <= remaining; i++) { + days.push({ + day: i, + isCurrentMonth: false, + date: new Date(year, month + 1, i), + }); + } + return { year, month, @@ -28,6 +66,7 @@ export function useCalendar(initialDate = new Date()) { daysInMonth, prevMonthDays, weekdays: WEEKDAYS, + days, }; }, [year, month]); @@ -93,6 +132,7 @@ export function useCalendar(initialDate = new Date()) { ...calendarData, currentDate, selectedDate, + canGoPrev: canGoPrevMonth, canGoPrevMonth, goToPrevMonth, goToNextMonth, diff --git a/frontend-temp/src/pages/schedule/Schedule.jsx b/frontend-temp/src/pages/schedule/Schedule.jsx index 874377d..4fb6827 100644 --- a/frontend-temp/src/pages/schedule/Schedule.jsx +++ b/frontend-temp/src/pages/schedule/Schedule.jsx @@ -143,11 +143,12 @@ function Schedule() { const isMobile = useIsMobile(); // Zustand store - const { currentDate, setCurrentDate, selectedDate, setSelectedDate } = useScheduleStore(); + const { currentDate: storedCurrentDate, setCurrentDate, selectedDate, setSelectedDate } = useScheduleStore(); - // 초기값 설정 + // 초기값 설정 - currentDate가 Date 객체가 아닐 수 있으므로 안전하게 변환 const today = getTodayKST(); const actualSelectedDate = selectedDate || today; + const currentDate = storedCurrentDate instanceof Date ? storedCurrentDate : new Date(storedCurrentDate || today); // 데이터 로드 const year = currentDate.getFullYear();