Skip to content

Commit fcedae4

Browse files
committed
feat: 캘린더 메인 - 일정클릭시 해당날짜의 일정리스트 노출
1 parent 45d6a69 commit fcedae4

File tree

1 file changed

+44
-46
lines changed

1 file changed

+44
-46
lines changed

src/components/common/Calendar.tsx

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import interactionPlugin from '@fullcalendar/interaction';
55
import { useRef, useState, useEffect } from 'react';
66

77
type Event = {
8-
title: string;
9-
start: Date | string;
10-
}
8+
title: string;
9+
start: Date | string;
10+
};
1111
interface EventCardsProps {
12-
events: Event[];
13-
date: Date | string | null;
12+
events: Event[];
13+
date: Date | string | null;
1414
}
1515

1616
const events = [
@@ -27,18 +27,16 @@ export function Calendar() {
2727
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
2828

2929
const handleDateClick = (clickInfo: EventClickArg) => {
30-
if(clickInfo.event.start) {
31-
const clickStartDate = new Date(clickInfo.event.start);
32-
setSelectedDate(clickStartDate);
33-
34-
const clickedStartDate = new Date(clickInfo.event.start).toDateString();
35-
setSelectedEvents(events.filter(event =>
36-
new Date(event.start).toDateString() === clickedStartDate
37-
));
30+
if (clickInfo.event.start) {
31+
const clickStartDate = new Date(clickInfo.event.start);
32+
setSelectedDate(clickStartDate);
33+
34+
const clickedStartDate = new Date(clickInfo.event.start).toDateString();
35+
setSelectedEvents(events.filter((event) => new Date(event.start).toDateString() === clickedStartDate));
3836
} else {
39-
console.log("not available");
37+
console.log('not available');
4038
}
41-
}
39+
};
4240

4341
const handlePrev = () => {
4442
const calendarApi = calendarRef?.current?.getApi();
@@ -136,11 +134,11 @@ export function Calendar() {
136134
right: 'nextButton',
137135
}}
138136
customButtons={{
139-
prevButton: { click: handlePrev },
140-
nextButton: { click: handleNext },
137+
prevButton: { click: handlePrev },
138+
nextButton: { click: handleNext },
141139
}}
142140
/>
143-
{selectedDate && <EventCards events={selectedEvents} date={selectedDate} />}
141+
{selectedDate && <EventCards events={selectedEvents} date={selectedDate} />}
144142
</div>
145143
);
146144
}
@@ -163,32 +161,32 @@ function renderEventContent(eventInfo: EventInfo) {
163161
);
164162
}
165163

166-
167164
function EventCards({ events, date }: EventCardsProps) {
168-
if (!date) {
169-
return <div>No date provided</div>; // date가 null인 경우 처리
170-
}
171-
172-
const formattedDate = new Date(date).toLocaleDateString('ko-KR', {
173-
year: 'numeric',
174-
month: '2-digit',
175-
day: '2-digit'
176-
}).replace(/\. /g,".").slice(0, -1);
177-
console.log(formattedDate)
178-
179-
return (
180-
<div>
181-
<h2>{formattedDate}</h2>
182-
<div className="flex overflow-x-auto">
183-
{events.map((event, index) => (
184-
<div key={index} className="min-w-[200px] m-2 p-2 bg-blue-200 text-white">
185-
<h3>{event.title}</h3>
186-
<p>{new Date(event.start).toLocaleTimeString()}</p>
187-
</div>
188-
))}
189-
</div>
190-
191-
</div>
192-
193-
);
194-
}
165+
if (!date) {
166+
return <div>No date provided</div>; // date가 null인 경우 처리
167+
}
168+
169+
const formattedDate = new Date(date)
170+
.toLocaleDateString('ko-KR', {
171+
year: 'numeric',
172+
month: '2-digit',
173+
day: '2-digit',
174+
})
175+
.replace(/\. /g, '.')
176+
.slice(0, -1);
177+
console.log(formattedDate);
178+
179+
return (
180+
<div>
181+
<h2>{formattedDate}</h2>
182+
<div className="flex overflow-x-auto">
183+
{events.map((event, index) => (
184+
<div key={index} className="m-2 min-w-[200px] bg-blue-200 p-2 text-white">
185+
<h3>{event.title}</h3>
186+
<p>{new Date(event.start).toLocaleTimeString()}</p>
187+
</div>
188+
))}
189+
</div>
190+
</div>
191+
);
192+
}

0 commit comments

Comments
 (0)