diff --git a/frontend/src/pages/mobile/Schedule.jsx b/frontend/src/pages/mobile/Schedule.jsx index 0c53d8a..9ce2afe 100644 --- a/frontend/src/pages/mobile/Schedule.jsx +++ b/frontend/src/pages/mobile/Schedule.jsx @@ -13,7 +13,7 @@ function MobileSchedule() { const [isSearchMode, setIsSearchMode] = useState(false); const [searchTerm, setSearchTerm] = useState(''); const [showCalendar, setShowCalendar] = useState(false); - const [calendarViewDate, setCalendarViewDate] = useState(new Date()); // 달력 뷰 날짜 + const [calendarViewDate, setCalendarViewDate] = useState(() => new Date(selectedDate)); // 달력 뷰 날짜 const [calendarShowYearMonth, setCalendarShowYearMonth] = useState(false); // 달력 년월 선택 모드 // 달력 월 변경 함수 @@ -84,7 +84,17 @@ function MobileSchedule() { const changeMonth = (delta) => { const newDate = new Date(selectedDate); newDate.setMonth(newDate.getMonth() + delta); + + // 이번 달이면 오늘 날짜, 다른 달이면 1일 선택 + const today = new Date(); + if (newDate.getFullYear() === today.getFullYear() && newDate.getMonth() === today.getMonth()) { + newDate.setDate(today.getDate()); + } else { + newDate.setDate(1); + } + setSelectedDate(newDate); + setCalendarViewDate(newDate); }; // 캘린더가 열릴 때 배경 스크롤 방지 @@ -306,13 +316,20 @@ function MobileSchedule() { const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); const dateStr = `${year}-${month}-${day}`; - const hasSchedule = schedules.some(s => s.date.split('T')[0] === dateStr); + + // 해당 날짜의 일정 목록 (최대 3개) + const daySchedules = schedules + .filter(s => s.date?.split('T')[0] === dateStr) + .slice(0, 3); return ( setSelectedDate(date)} - className={`flex flex-col items-center min-w-[44px] py-2 px-1 rounded-xl transition-all ${ + onClick={() => { + setSelectedDate(date); + setCalendarViewDate(date); + }} + className={`flex flex-col items-center min-w-[44px] h-[64px] py-2 px-1 rounded-xl transition-all ${ isSelected(date) ? 'bg-primary text-white' : 'hover:bg-gray-100' @@ -338,9 +355,20 @@ function MobileSchedule() { }`}> {date.getDate()} - {hasSchedule && !isSelected(date) && ( - - )} + {/* 일정 점 (최대 3개) */} + + {!isSelected(date) && daySchedules.map((schedule, i) => { + const cat = categories.find(c => c.id === schedule.category_id); + const color = cat?.color || '#6b7280'; + return ( + + ); + })} + ); })} @@ -369,6 +397,8 @@ function MobileSchedule() { onShowYearMonthChange={setCalendarShowYearMonth} onSelectDate={(date) => { setSelectedDate(date); + setCalendarViewDate(date); + setCalendarShowYearMonth(false); setShowCalendar(false); }} /> @@ -571,7 +601,7 @@ function TimelineScheduleCard({ schedule, categoryColor, categories, delay = 0 } memberList.map((name, i) => ( {name.trim()} @@ -617,7 +647,7 @@ function CalendarPicker({ const scheduleDates = useMemo(() => { const dateMap = {}; schedules.forEach(schedule => { - const date = schedule.date; + const date = schedule.date.split('T')[0]; // YYYY-MM-DD 형식으로 통일 if (!dateMap[date]) { dateMap[date] = []; } @@ -627,11 +657,13 @@ function CalendarPicker({ return dateMap; }, [schedules, categories]); - const getScheduleColors = (date) => { - const dateStr = date.toISOString().split('T')[0]; - const colors = scheduleDates[dateStr] || []; - // 최대 3개까지만 표시 - return [...new Set(colors)].slice(0, 3); + // 날짜별 일정 목록 가져오기 (점 표시용, 최대 3개) + const getDaySchedules = (date) => { + const y = date.getFullYear(); + const m = String(date.getMonth() + 1).padStart(2, '0'); + const d = String(date.getDate()).padStart(2, '0'); + const dateStr = `${y}-${m}-${d}`; + return schedules.filter(s => s.date?.split('T')[0] === dateStr).slice(0, 3); }; const year = viewDate.getFullYear(); @@ -691,6 +723,13 @@ function CalendarPicker({ date.getFullYear() === today.getFullYear(); }; + // 선택된 날짜인지 확인 + const isSelected = (date) => { + return date.getDate() === selectedDate.getDate() && + date.getMonth() === selectedDate.getMonth() && + date.getFullYear() === selectedDate.getFullYear(); + }; + // 년월 선택 모드 - 외부에서 제어 가능 const [internalShowYearMonth, setInternalShowYearMonth] = useState(false); const showYearMonth = externalShowYearMonth !== undefined ? externalShowYearMonth : internalShowYearMonth; @@ -767,37 +806,45 @@ function CalendarPicker({ const dayOfWeek = index % 7; const isSunday = dayOfWeek === 0; const isSaturday = dayOfWeek === 6; - const scheduleColors = item.isCurrentMonth ? getScheduleColors(item.date) : []; + const daySchedules = item.isCurrentMonth ? getDaySchedules(item.date) : []; return ( onSelectDate(item.date)} - className="flex flex-col items-center py-1" + className="flex flex-col items-center py-2" > - {item.day} - {/* 일정 점 */} - - {scheduleColors.map((color, i) => ( - - ))} - + {/* 일정 점 - 선택된 날짜에는 표시하지 않음, 최대 3개 */} + {!isSelected(item.date) && daySchedules.length > 0 && ( + + {daySchedules.map((schedule, i) => { + const cat = categories.find(c => c.id === schedule.category_id); + const color = cat?.color || '#6b7280'; + return ( + + ); + })} + + )} ); })} @@ -882,10 +929,10 @@ function CalendarPicker({ ) : ( {/* 달력 헤더 - hideHeader일 때 숨김 */}