Skip to content

Commit

Permalink
fix: getDayStyle()을 useCallback 밖으로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcjy committed Sep 19, 2024
1 parent 0be210b commit 1b3ce76
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,6 @@ export const Calendar = ({ bibleData }: { bibleData: BibleData }) => {

const createCalendar = useCallback(
(date: Date) => {
const getDayStyle = (date: Date, today: Date) => {
date.setHours(0, 0, 0, 0)
today.setHours(0, 0, 0, 0)

const isPast = date < today
const isToday = !(date.getTime() - today.getTime())
const isSunday = date.getDay() === 0
const isSaturday = date.getDay() === 6

const styles = ['hover:shadow-md transition-shadow']

if (isPast) styles.push('opacity-50')
if (isToday) styles.push('bg-blue-100 border-blue-500')
if (isSunday) styles.push('text-red-500')
if (isSaturday) styles.push('text-blue-600')

return styles.join(' ')
}

const year = date.getFullYear()
const month = date.getMonth()
const monthlyBible = bibleData[year]?.[month] ?? {}
Expand Down Expand Up @@ -75,3 +56,22 @@ export const Calendar = ({ bibleData }: { bibleData: BibleData }) => {
</div>
)
}

const getDayStyle = (date: Date, today: Date) => {
date.setHours(0, 0, 0, 0)
today.setHours(0, 0, 0, 0)

const isPast = date < today
const isToday = !(date.getTime() - today.getTime())
const isSunday = date.getDay() === 0
const isSaturday = date.getDay() === 6

const styles = ['hover:shadow-md transition-shadow']

if (isPast) styles.push('opacity-50')
if (isToday) styles.push('bg-blue-100 border-blue-500')
if (isSunday) styles.push('text-red-500')
if (isSaturday) styles.push('text-blue-600')

return styles.join(' ')
}

0 comments on commit 1b3ce76

Please sign in to comment.