Skip to content

Commit

Permalink
feat: 캘린더/리스트 클릭 이벤트 추가 - 클릭한 날짜 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeseB committed Mar 27, 2024
1 parent 4fa393b commit 6825a8f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 32 deletions.
4 changes: 4 additions & 0 deletions src/components/calendar/CalendarBody/CalendarBody.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ $item-column: 7;
.date-item {
position: relative;

&.clickable {
cursor: pointer;
}

&:not(:nth-child(7n)) {
border-right: 0.1rem solid $black50;
}
Expand Down
15 changes: 13 additions & 2 deletions src/components/calendar/CalendarBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type CalendarBodyProps = {
currentYear: number;
currentMonth: number;
schedules?: ReservationsByDate;
onClick: (date: string) => void;
};

const CalendarBody = ({ today, currentYear, currentMonth, schedules }: CalendarBodyProps) => {
const CalendarBody = ({ today, currentYear, currentMonth, schedules, onClick }: CalendarBodyProps) => {
const { startOfCalendar, endOfPrevMonth, endOfThisMonth, endOfCalendar } = getCalendarDates(
currentYear,
currentMonth,
Expand Down Expand Up @@ -58,9 +59,19 @@ const CalendarBody = ({ today, currentYear, currentMonth, schedules }: CalendarB
))}
{thisMonthDates.map((date, index) => {
const formattedDate = getJoinedDateString(currentYear, currentMonth, date);
const hasReservation = schedules?.[formattedDate] !== undefined;
const handleClick = () => {
if (!hasReservation) return;
onClick(formattedDate);
};

return (
<div className={cx('date-item', 'hover')} key={`date-${index}`}>
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div
className={cx('date-item', 'hover', { clickable: hasReservation })}
key={`date-${index}`}
onClick={handleClick}
>
<CalendarItem date={date} isToday={isToday(date)} reservations={schedules?.[formattedDate]} />
</div>
);
Expand Down
4 changes: 0 additions & 4 deletions src/components/calendar/CalendarItem/CalendarItem.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ $item-size: 15.4rem;
color: $gray40;
}

&.clickable {
cursor: pointer;
}

&:hover:not(.disabled) {
color: $black80;

Expand Down
34 changes: 15 additions & 19 deletions src/components/calendar/CalendarItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ type CalendarItemProps = {
reservations?: MonthlyReservationCount;
};

const CalendarItem = ({ date, isToday, isDisabled, reservations }: CalendarItemProps) => {
const hasReservation = reservations !== undefined;

return (
<div className={cx('calendar-item', { disabled: isDisabled }, { clickable: hasReservation })}>
<div className={cx('calendar-number-area')}>
<span className={cx('calendar-number', { today: isToday })}>{date}</span>
</div>
<ul className={cx('calendar-badge-area')}>
{SCHEDULE_ORDER.map((status) =>
reservations?.[status] ? (
<li key={`badge-${status}`}>
<ScheduleBadge type={status} count={reservations[status]} />
</li>
) : undefined,
)}
</ul>
const CalendarItem = ({ date, isToday, isDisabled, reservations }: CalendarItemProps) => (
<div className={cx('calendar-item', { disabled: isDisabled })}>
<div className={cx('calendar-number-area')}>
<span className={cx('calendar-number', { today: isToday })}>{date}</span>
</div>
);
};
<ul className={cx('calendar-badge-area')}>
{SCHEDULE_ORDER.map((status) =>
reservations?.[status] ? (
<li key={`badge-${status}`}>
<ScheduleBadge type={status} count={reservations[status]} />
</li>
) : undefined,
)}
</ul>
</div>
);

export default CalendarItem;
18 changes: 12 additions & 6 deletions src/components/calendar/ListBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ const cx = classNames.bind(styles);

type ListBodyProps = {
schedules?: MonthlySchedule[];
onClick: (date: string) => void;
};

const ListBody = ({ schedules }: ListBodyProps) => {
const ListBody = ({ schedules, onClick }: ListBodyProps) => {
return (
<ul>
{schedules?.map(({ date, reservations }) => (
<li className={cx('card-container')} key={`schedule-${date}`}>
<ListCard date={date} reservations={reservations} />
</li>
))}
{schedules?.map(({ date, reservations }) => {
const handleClick = () => onClick(date);

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
<li className={cx('card-container')} key={`schedule-${date}`} onClick={handleClick}>
<ListCard date={date} reservations={reservations} />
</li>
);
})}
</ul>
);
};
Expand Down
Empty file.
11 changes: 11 additions & 0 deletions src/components/calendar/ModalContents/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import classNames from 'classnames/bind';

import styles from './ModalContents.module.scss';

const cx = classNames.bind(styles);

const ModalContents = () => {
return <div className={cx('')}>ModalContents</div>;
};

export default ModalContents;
9 changes: 8 additions & 1 deletion src/components/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const Calendar = ({ gameId }: CalendarProps) => {
const [currentYear, setCurrentYear] = useState(today.year);
const [currentMonth, setCurrentMonth] = useState(today.month);
const [monthlySchedule, setMonthlySchedule] = useState<MonthlySchedule[]>([]);
const [activeDate, setActiveDate] = useState('');

const currentDeviceType = useDeviceType();

Expand All @@ -64,6 +65,10 @@ const Calendar = ({ gameId }: CalendarProps) => {
setCurrentMonth(newMonth);
};

const handleScheduleClick = (date: string) => {
setActiveDate(date);
};

useEffect(() => {
if (currentDeviceType !== 'PC') setIsCalendar(false);
}, [currentDeviceType]);
Expand All @@ -75,6 +80,7 @@ const Calendar = ({ gameId }: CalendarProps) => {
}, [currentYear, currentMonth]);

console.log(gameId);
console.log(activeDate);

return (
<div className={cx('calendar-container')}>
Expand All @@ -91,9 +97,10 @@ const Calendar = ({ gameId }: CalendarProps) => {
currentYear={currentYear}
currentMonth={currentMonth}
schedules={scheduleListToObjectByDate(monthlySchedule)}
onClick={handleScheduleClick}
/>
) : (
<ListBody schedules={monthlySchedule} />
<ListBody schedules={monthlySchedule} onClick={handleScheduleClick} />
)}
</div>
);
Expand Down

0 comments on commit 6825a8f

Please sign in to comment.