Skip to content

Commit 97558b6

Browse files
authored
Merge pull request #201 from prgrms-aibe-devcourse/dev
fix: 중복 로직 해결
2 parents b3d037d + f6514e1 commit 97558b6

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/components/dashboard/DashboardPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,15 +716,15 @@ const DashboardPage: React.FC = () => {
716716
))}
717717
</div>
718718
<div className="grid grid-cols-7 gap-1">
719-
{calendarDays.map((day) => {
719+
{calendarDays.map((day, index) => {
720720
const dayEvents = getEventsForDate(day);
721721
const isCurrentMonth = isSameMonth(day, calendarDate);
722722
const isDayToday = isToday(day);
723723
const isSelected = isSameDay(day, selectedDate);
724724

725725
return (
726726
<motion.button
727-
key={day.toString()}
727+
key={`${day.getTime()}-${index}`}
728728
className={`
729729
text-xs p-1 rounded transition-colors relative
730730
${isCurrentMonth ? "text-gray-800" : "text-gray-300"}

src/hooks/useCalendar.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export const useCalendar = (options: UseCalendarOptions = {}): UseCalendarReturn
329329
const targetDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
330330
const targetDateString = targetDate.toISOString().split('T')[0]; // YYYY-MM-DD 형식
331331

332-
return events.filter(event => {
332+
const filteredEvents = events.filter(event => {
333333

334334
const eventStartDate = event.date instanceof Date ? new Date(event.date) : new Date(event.date);
335335
const eventStart = new Date(eventStartDate.getFullYear(), eventStartDate.getMonth(), eventStartDate.getDate());
@@ -408,6 +408,25 @@ export const useCalendar = (options: UseCalendarOptions = {}): UseCalendarReturn
408408

409409
return patternMatch;
410410
});
411+
412+
// 중복 제거: 같은 제목, 시간, 카테고리를 가진 이벤트들을 하나로 합치기
413+
const uniqueEvents = filteredEvents.reduce((acc: Event[], current: Event) => {
414+
const duplicate = acc.find(event =>
415+
event.title === current.title &&
416+
event.startTime === current.startTime &&
417+
event.endTime === current.endTime &&
418+
event.category === current.category &&
419+
event.isAllDay === current.isAllDay
420+
);
421+
422+
if (!duplicate) {
423+
acc.push(current);
424+
}
425+
426+
return acc;
427+
}, []);
428+
429+
return uniqueEvents;
411430
}, [events]);
412431

413432
// 자동 로드 - groupId, currentDate, currentView 변경 시 실행

0 commit comments

Comments
 (0)