Skip to content

Commit 8f3a086

Browse files
committed
(#246) monthViewWithData 컴포넌트 삭제
1 parent dc0dff2 commit 8f3a086

4 files changed

Lines changed: 45 additions & 113 deletions

File tree

src/components/commons/exerciseCalendar/exerciseCalendar.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LeftArrow from '@/assets/icon_left_arrow.svg'
1010
import RightArrow from '@/assets/icon_right_arrow.svg'
1111
import Typography from '@/components/ui/typography'
1212

13-
import MonthViewWithData from './monthViewWithData'
13+
import MonthView from './monthView'
1414
import styles from './exerciseCalendar.module.css'
1515

1616
type Props = {
@@ -142,9 +142,10 @@ const ExerciseCalendar = forwardRef<HTMLDivElement, Props>(
142142
),
143143
}}
144144
>
145-
<MonthViewWithData
145+
<MonthView
146+
key={prevMonth.toISOString()}
147+
month={prevMonth}
146148
today={today}
147-
monthToShow={prevMonth}
148149
isActive={false}
149150
onDateSelect={onDateSelect}
150151
selectedDate={selectedDate}
@@ -153,9 +154,10 @@ const ExerciseCalendar = forwardRef<HTMLDivElement, Props>(
153154
showStamps={showStamps}
154155
memberId={memberId ?? undefined}
155156
/>
156-
<MonthViewWithData
157+
<MonthView
158+
key={currentMonth.toISOString()}
159+
month={currentMonth}
157160
today={today}
158-
monthToShow={currentMonth}
159161
isActive={true}
160162
onDateSelect={onDateSelect}
161163
selectedDate={selectedDate}
@@ -164,9 +166,10 @@ const ExerciseCalendar = forwardRef<HTMLDivElement, Props>(
164166
showStamps={showStamps}
165167
memberId={memberId ?? undefined}
166168
/>
167-
<MonthViewWithData
169+
<MonthView
170+
key={nextMonth.toISOString()}
171+
month={nextMonth}
168172
today={today}
169-
monthToShow={nextMonth}
170173
isActive={false}
171174
onDateSelect={onDateSelect}
172175
selectedDate={selectedDate}
Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
'use client'
22

33
import { memo, useMemo, useRef } from 'react'
4-
5-
import {
6-
eachWeekOfInterval,
7-
eachDayOfInterval,
8-
format,
9-
isSameMonth,
10-
isSameDay,
11-
isAfter,
12-
startOfWeek,
13-
endOfWeek,
14-
startOfMonth,
15-
endOfMonth,
16-
addDays,
17-
parseISO,
18-
} from 'date-fns'
4+
import { eachWeekOfInterval, eachDayOfInterval, format, isSameMonth, isSameDay, isAfter, startOfWeek, endOfWeek, startOfMonth, endOfMonth, addDays, parseISO } from 'date-fns'
195
import clsx from 'clsx'
20-
6+
import { useExerciseCalendarData } from '@/hooks/useExerciseCalendar' // 훅 직접 호출
217
import StampIcon from '@/assets/stamp.svg'
228
import Typography from '@/components/ui/typography'
23-
249
import styles from './monthView.module.css'
2510

2611
type Props = {
2712
month: Date
2813
today: Date
29-
counts: Record<string, number>
30-
onDateClick: (date: Date) => void
14+
onDateSelect?: (date: Date) => void
3115
selectedDate: string
3216
isReadOnly: boolean
17+
isOthers: boolean
3318
showStamps: boolean
19+
isActive: boolean
20+
memberId?: string
3421
}
3522

3623
const MonthView = memo(function MonthView({
3724
month,
3825
today,
39-
counts,
40-
onDateClick,
26+
onDateSelect,
4127
selectedDate,
4228
isReadOnly,
29+
isOthers,
4330
showStamps,
31+
isActive,
32+
memberId,
4433
}: Props) {
34+
const { counts } = useExerciseCalendarData({
35+
monthToShow: month,
36+
today,
37+
isOthers,
38+
memberId,
39+
isActive,
40+
showStamps,
41+
})
42+
4543
const prevCounts = useRef(counts)
44+
4645
const shouldAnimate = useMemo(() => {
4746
const prevData = Object.keys(prevCounts.current).length === 0
4847
const currentData = Object.keys(counts).length > 0
@@ -55,16 +54,10 @@ const MonthView = memo(function MonthView({
5554
const gridStart = startOfWeek(monthStart, { weekStartsOn: 0 })
5655
const gridEnd = endOfWeek(monthEnd, { weekStartsOn: 0 })
5756

58-
const weekStarts = eachWeekOfInterval(
59-
{ start: gridStart, end: gridEnd },
60-
{ weekStartsOn: 0 },
61-
)
57+
const weekStarts = eachWeekOfInterval({ start: gridStart, end: gridEnd }, { weekStartsOn: 0 })
6258

6359
return weekStarts.map((weekStart) =>
64-
eachDayOfInterval({
65-
start: weekStart,
66-
end: addDays(weekStart, 6),
67-
}),
60+
eachDayOfInterval({ start: weekStart, end: addDays(weekStart, 6) })
6861
)
6962
}, [month])
7063

@@ -77,12 +70,7 @@ const MonthView = memo(function MonthView({
7770
const isCurrent = isSameMonth(day, month)
7871
const isFuture = isAfter(day, today)
7972
const isSelected = isSameDay(day, parseISO(selectedDate))
80-
const count = counts[dateStr] ?? 0
81-
82-
const stampIconClassName = clsx(styles['stamp-icon'], {
83-
[styles['animate-fade-in']]: shouldAnimate,
84-
[styles['show-immediately']]: !shouldAnimate,
85-
})
73+
const count = showStamps ? (counts[dateStr] ?? 0) : 0
8674

8775
return (
8876
<div
@@ -92,17 +80,24 @@ const MonthView = memo(function MonthView({
9280
!isCurrent && styles['empty'],
9381
isFuture && styles['disabled'],
9482
isSelected && styles['selected'],
95-
!showStamps && styles['is-picker'],
83+
!showStamps && styles['is-picker']
9684
)}
9785
onClick={() => {
98-
if (!isCurrent || isFuture || isReadOnly) return
99-
onDateClick(day)
86+
if (!isCurrent || isFuture || isReadOnly || !onDateSelect) return
87+
onDateSelect(day)
10088
}}
10189
>
10290
<Typography as="span" variant="content-medium">
10391
{format(day, 'd')}
10492
</Typography>
105-
{count > 0 && <StampIcon className={stampIconClassName} />}
93+
{count > 0 && (
94+
<StampIcon
95+
className={clsx(styles['stamp-icon'], {
96+
[styles['animate-fade-in']]: shouldAnimate,
97+
[styles['show-immediately']]: !shouldAnimate,
98+
})}
99+
/>
100+
)}
106101
</div>
107102
)
108103
})}
@@ -112,4 +107,4 @@ const MonthView = memo(function MonthView({
112107
)
113108
})
114109

115-
export default MonthView
110+
export default MonthView

src/components/commons/exerciseCalendar/monthViewWithData.module.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/components/commons/exerciseCalendar/monthViewWithData.tsx

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)