diff --git a/frontend/src/pages/pc/Schedule.jsx b/frontend/src/pages/pc/Schedule.jsx index c0080b4..ac940de 100644 --- a/frontend/src/pages/pc/Schedule.jsx +++ b/frontend/src/pages/pc/Schedule.jsx @@ -1,25 +1,59 @@ +import { useState } from 'react'; import { motion } from 'framer-motion'; -import { Clock, MapPin, Users } from 'lucide-react'; +import { Clock, MapPin, Users, ChevronLeft, ChevronRight } from 'lucide-react'; import { schedules } from '../../data/dummy'; function Schedule() { - // 스케줄을 날짜별로 그룹핑 - const groupedSchedules = schedules.reduce((acc, schedule) => { - const date = schedule.date; - if (!acc[date]) { - acc[date] = []; - } - acc[date].push(schedule); - return acc; - }, {}); + const [currentDate, setCurrentDate] = useState(new Date()); + const [selectedDate, setSelectedDate] = useState(null); + + // 달력 관련 함수 + const getDaysInMonth = (year, month) => new Date(year, month + 1, 0).getDate(); + const getFirstDayOfMonth = (year, month) => new Date(year, month, 1).getDay(); + + const year = currentDate.getFullYear(); + const month = currentDate.getMonth(); + const daysInMonth = getDaysInMonth(year, month); + const firstDay = getFirstDayOfMonth(year, month); + + const days = ['일', '월', '화', '수', '목', '금', '토']; + const monthNames = ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월']; + + // 스케줄이 있는 날짜 목록 + const scheduleDates = schedules.map(s => s.date); + + const hasSchedule = (day) => { + const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; + return scheduleDates.includes(dateStr); + }; + + const prevMonth = () => { + setCurrentDate(new Date(year, month - 1, 1)); + setSelectedDate(null); + }; + + const nextMonth = () => { + setCurrentDate(new Date(year, month + 1, 1)); + setSelectedDate(null); + }; + + const selectDate = (day) => { + const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; + setSelectedDate(selectedDate === dateStr ? null : dateStr); + }; + + // 필터링된 스케줄 + const filteredSchedules = selectedDate + ? schedules.filter(s => s.date === selectedDate) + : schedules; const formatDate = (dateStr) => { const date = new Date(dateStr); - const days = ['일', '월', '화', '수', '목', '금', '토']; + const dayNames = ['일', '월', '화', '수', '목', '금', '토']; return { month: date.getMonth() + 1, day: date.getDate(), - weekday: days[date.getDay()], + weekday: dayNames[date.getDay()], }; }; @@ -45,55 +79,152 @@ function Schedule() { - {/* 스케줄 리스트 */} -
- {Object.entries(groupedSchedules).map(([date, daySchedules], groupIndex) => { - const formatted = formatDate(date); - return daySchedules.map((schedule, index) => ( - - {/* 날짜 영역 */} -
- {formatted.month}월 - {formatted.day} - {formatted.weekday} -
+
+ {/* 달력 */} + +
+ {/* 달력 헤더 */} +
+ +

+ {year}년 {monthNames[month]} +

+ +
- {/* 스케줄 내용 */} -
-

{schedule.title}

- -
-
- - {schedule.time} -
-
- - {schedule.platform} -
-
- - {schedule.members.join(', ')} -
+ {/* 요일 헤더 */} +
+ {days.map((day, i) => ( +
+ {day}
-
- - )); - })} -
+ ))} +
- {/* 빈 스케줄 메시지 */} - {Object.keys(groupedSchedules).length === 0 && ( -
-

예정된 스케줄이 없습니다.

+ {/* 날짜 그리드 */} +
+ {/* 빈 칸 */} + {Array.from({ length: firstDay }).map((_, i) => ( +
+ ))} + + {/* 날짜 */} + {Array.from({ length: daysInMonth }).map((_, i) => { + const day = i + 1; + const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`; + const isSelected = selectedDate === dateStr; + const hasEvent = hasSchedule(day); + const dayOfWeek = (firstDay + i) % 7; + const isToday = new Date().toDateString() === new Date(year, month, day).toDateString(); + + return ( + + ); + })} +
+ + {/* 범례 */} +
+
+ + 일정 있음 +
+ {selectedDate && ( + + )} +
+
+ + + {/* 스케줄 리스트 */} +
+ {filteredSchedules.length > 0 ? ( + filteredSchedules.map((schedule, index) => { + const formatted = formatDate(schedule.date); + return ( + + {/* 날짜 영역 */} +
+ {formatted.month}월 + {formatted.day} + {formatted.weekday} +
+ + {/* 스케줄 내용 */} +
+

{schedule.title}

+ +
+
+ + {schedule.time} +
+
+ + {schedule.platform} +
+
+ + {schedule.members.join(', ')} +
+
+
+
+ ); + }) + ) : ( +
+ {selectedDate ? '선택한 날짜에 일정이 없습니다.' : '예정된 스케줄이 없습니다.'} +
+ )}
- )} +
);