diff --git a/frontend/src/pages/pc/admin/AdminSchedule.jsx b/frontend/src/pages/pc/admin/AdminSchedule.jsx index 9eda0d5..d29e14e 100644 --- a/frontend/src/pages/pc/admin/AdminSchedule.jsx +++ b/frontend/src/pages/pc/admin/AdminSchedule.jsx @@ -80,9 +80,9 @@ function AdminSchedule() { } }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]); - // selectedDate가 undefined이면 오늘 날짜로 초기화 (null은 전체보기이므로 유지) + // selectedDate가 없으면 오늘 날짜로 초기화 useEffect(() => { - if (selectedDate === undefined) { + if (!selectedDate) { setSelectedDate(getTodayKST()); } }, []); @@ -166,22 +166,28 @@ function AdminSchedule() { return colors[color] || 'bg-gray-100 text-gray-700'; }; - // 해당 날짜에 일정이 있는지 확인 + // 일정 날짜별 맵 (O(1) 조회용) - 성능 최적화 + const scheduleDateMap = useMemo(() => { + const map = new Map(); + schedules.forEach(s => { + const dateStr = formatDate(s.date); + if (!map.has(dateStr)) { + map.set(dateStr, s); + } + }); + return map; + }, [schedules]); + + // 해당 날짜에 일정이 있는지 확인 (O(1)) const hasSchedule = (day) => { const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; - return schedules.some(s => { - const scheduleDate = formatDate(s.date); - return scheduleDate === dateStr; - }); + return scheduleDateMap.has(dateStr); }; - // 해당 날짜의 첫 번째 일정 카테고리 색상 + // 해당 날짜의 첫 번째 일정 카테고리 색상 (O(1)) const getScheduleColor = (day) => { const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; - const schedule = schedules.find(s => { - const scheduleDate = formatDate(s.date); - return scheduleDate === dateStr; - }); + const schedule = scheduleDateMap.get(dateStr); if (!schedule) return null; const cat = categories.find(c => c.id === schedule.category_id); return cat?.color || '#4A7C59';