스케줄 페이지에 인터랙티브 달력 추가

This commit is contained in:
caadiq 2025-12-31 22:08:01 +09:00
parent 80a8327c24
commit 66e54ed640

View file

@ -1,25 +1,59 @@
import { useState } from 'react';
import { motion } from 'framer-motion'; 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'; import { schedules } from '../../data/dummy';
function Schedule() { function Schedule() {
// const [currentDate, setCurrentDate] = useState(new Date());
const groupedSchedules = schedules.reduce((acc, schedule) => { const [selectedDate, setSelectedDate] = useState(null);
const date = schedule.date;
if (!acc[date]) { //
acc[date] = []; const getDaysInMonth = (year, month) => new Date(year, month + 1, 0).getDate();
} const getFirstDayOfMonth = (year, month) => new Date(year, month, 1).getDay();
acc[date].push(schedule);
return acc; 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 formatDate = (dateStr) => {
const date = new Date(dateStr); const date = new Date(dateStr);
const days = ['일', '월', '화', '수', '목', '금', '토']; const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
return { return {
month: date.getMonth() + 1, month: date.getMonth() + 1,
day: date.getDate(), day: date.getDate(),
weekday: days[date.getDay()], weekday: dayNames[date.getDay()],
}; };
}; };
@ -45,55 +79,152 @@ function Schedule() {
</motion.p> </motion.p>
</div> </div>
{/* 스케줄 리스트 */} <div className="flex gap-8">
<div className="max-w-4xl mx-auto space-y-4"> {/* 달력 */}
{Object.entries(groupedSchedules).map(([date, daySchedules], groupIndex) => { <motion.div
const formatted = formatDate(date); initial={{ opacity: 0, x: -20 }}
return daySchedules.map((schedule, index) => ( animate={{ opacity: 1, x: 0 }}
<motion.div className="w-80 flex-shrink-0"
key={schedule.id} >
initial={{ opacity: 0, y: 20 }} <div className="bg-white rounded-2xl shadow-sm p-6">
animate={{ opacity: 1, y: 0 }} {/* 달력 헤더 */}
transition={{ delay: (groupIndex * daySchedules.length + index) * 0.1 }} <div className="flex items-center justify-between mb-6">
className="flex items-stretch bg-white rounded-2xl shadow-sm hover:shadow-md transition-shadow overflow-hidden" <button
> onClick={prevMonth}
{/* 날짜 영역 */} className="p-2 hover:bg-gray-100 rounded-full transition-colors"
<div className="w-24 bg-primary flex flex-col items-center justify-center text-white py-6"> >
<span className="text-sm font-medium opacity-80">{formatted.month}</span> <ChevronLeft size={20} />
<span className="text-3xl font-bold">{formatted.day}</span> </button>
<span className="text-sm font-medium opacity-80">{formatted.weekday}</span> <h3 className="text-lg font-bold">
</div> {year} {monthNames[month]}
</h3>
<button
onClick={nextMonth}
className="p-2 hover:bg-gray-100 rounded-full transition-colors"
>
<ChevronRight size={20} />
</button>
</div>
{/* 스케줄 내용 */} {/* 요일 헤더 */}
<div className="flex-1 p-6"> <div className="grid grid-cols-7 mb-2">
<h3 className="font-bold text-lg mb-3">{schedule.title}</h3> {days.map((day, i) => (
<div
<div className="flex flex-wrap gap-4 text-sm text-gray-500"> key={day}
<div className="flex items-center gap-1"> className={`text-center text-sm font-medium py-2 ${
<Clock size={14} className="text-primary" /> i === 0 ? 'text-red-500' : i === 6 ? 'text-blue-500' : 'text-gray-500'
<span>{schedule.time}</span> }`}
</div> >
<div className="flex items-center gap-1"> {day}
<MapPin size={14} className="text-primary" />
<span>{schedule.platform}</span>
</div>
<div className="flex items-center gap-1">
<Users size={14} className="text-primary" />
<span>{schedule.members.join(', ')}</span>
</div>
</div> </div>
</div> ))}
</motion.div> </div>
));
})}
</div>
{/* 빈 스케줄 메시지 */} {/* 날짜 그리드 */}
{Object.keys(groupedSchedules).length === 0 && ( <div className="grid grid-cols-7 gap-1">
<div className="text-center py-20"> {/* 빈 칸 */}
<p className="text-gray-500">예정된 스케줄이 없습니다.</p> {Array.from({ length: firstDay }).map((_, i) => (
<div key={`empty-${i}`} className="aspect-square" />
))}
{/* 날짜 */}
{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 (
<button
key={day}
onClick={() => hasEvent && selectDate(day)}
className={`aspect-square flex flex-col items-center justify-center rounded-lg text-sm transition-all
${isSelected ? 'bg-primary text-white' : ''}
${isToday && !isSelected ? 'ring-2 ring-primary' : ''}
${hasEvent && !isSelected ? 'hover:bg-primary/10 cursor-pointer' : ''}
${!hasEvent ? 'cursor-default' : ''}
${dayOfWeek === 0 && !isSelected ? 'text-red-500' : ''}
${dayOfWeek === 6 && !isSelected ? 'text-blue-500' : ''}
`}
>
<span>{day}</span>
{hasEvent && (
<span className={`w-1.5 h-1.5 rounded-full mt-0.5 ${isSelected ? 'bg-white' : 'bg-primary'}`} />
)}
</button>
);
})}
</div>
{/* 범례 */}
<div className="mt-4 pt-4 border-t border-gray-100 flex items-center justify-center gap-4 text-xs text-gray-500">
<div className="flex items-center gap-1">
<span className="w-2 h-2 rounded-full bg-primary" />
<span>일정 있음</span>
</div>
{selectedDate && (
<button
onClick={() => setSelectedDate(null)}
className="text-primary hover:underline"
>
전체 보기
</button>
)}
</div>
</div>
</motion.div>
{/* 스케줄 리스트 */}
<div className="flex-1 space-y-4">
{filteredSchedules.length > 0 ? (
filteredSchedules.map((schedule, index) => {
const formatted = formatDate(schedule.date);
return (
<motion.div
key={schedule.id}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: index * 0.1 }}
className="flex items-stretch bg-white rounded-2xl shadow-sm hover:shadow-md transition-shadow overflow-hidden"
>
{/* 날짜 영역 */}
<div className="w-24 bg-primary flex flex-col items-center justify-center text-white py-6">
<span className="text-sm font-medium opacity-80">{formatted.month}</span>
<span className="text-3xl font-bold">{formatted.day}</span>
<span className="text-sm font-medium opacity-80">{formatted.weekday}</span>
</div>
{/* 스케줄 내용 */}
<div className="flex-1 p-6">
<h3 className="font-bold text-lg mb-3">{schedule.title}</h3>
<div className="flex flex-wrap gap-4 text-sm text-gray-500">
<div className="flex items-center gap-1">
<Clock size={14} className="text-primary" />
<span>{schedule.time}</span>
</div>
<div className="flex items-center gap-1">
<MapPin size={14} className="text-primary" />
<span>{schedule.platform}</span>
</div>
<div className="flex items-center gap-1">
<Users size={14} className="text-primary" />
<span>{schedule.members.join(', ')}</span>
</div>
</div>
</div>
</motion.div>
);
})
) : (
<div className="text-center py-20 text-gray-500">
{selectedDate ? '선택한 날짜에 일정이 없습니다.' : '예정된 스케줄이 없습니다.'}
</div>
)}
</div> </div>
)} </div>
</div> </div>
</div> </div>
); );