11'use client'
22
33import { 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'
195import clsx from 'clsx'
20-
6+ import { useExerciseCalendarData } from '@/hooks/useExerciseCalendar' // 훅 직접 호출
217import StampIcon from '@/assets/stamp.svg'
228import Typography from '@/components/ui/typography'
23-
249import styles from './monthView.module.css'
2510
2611type 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
3623const 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
0 commit comments