Skip to content

Commit

Permalink
fix: today에 다시 useState 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcjy committed Sep 19, 2024
1 parent 1b3ce76 commit b167492
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,29 @@ import { CalendarGrid } from './CalendarGrid'

export const Calendar = ({ bibleData }: { bibleData: BibleData }) => {
const [currentDate, setCurrentDate] = useState(new Date())
const today = useMemo(() => new Date(), [])
const [today, setToday] = useState(new Date())

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 @@ -56,22 +75,3 @@ 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 b167492

Please sign in to comment.