Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
oasis-cloud committed Nov 11, 2024
1 parent 20db501 commit 7668b38
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
47 changes: 25 additions & 22 deletions src/packages/calendarcard/calendarcard.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, useEffect, useState } from 'react'
import React, { ReactNode, useCallback, useEffect, useState } from 'react'
import classNames from 'classnames'
import { View } from '@tarojs/components'
import { ArrowLeft, ArrowRight, DoubleLeft, DoubleRight } from './icon.taro'
Expand Down Expand Up @@ -124,27 +124,30 @@ export const CalendarCard = React.forwardRef<
}
}

const getDays = (month: CalendarCardMonth) => {
const y = month.year
const m = month.month
const days = [
...getPrevMonthDays(y, m, firstDayOfWeek),
...getCurrentMonthDays(y, m),
] as CalendarCardDay[]
const size = days.length
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
// 补全 6 行 7 列视图
for (let i = 1; i <= 42 - size; i++) {
days.push({
type: 'next',
year: yearOfNextMonth,
month: monthOfNextMonth,
date: i,
})
}
return days
}
const getDays = useCallback(
(month: CalendarCardMonth) => {
const y = month.year
const m = month.month
const days = [
...getPrevMonthDays(y, m, firstDayOfWeek),
...getCurrentMonthDays(y, m),
] as CalendarCardDay[]
const size = days.length
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
// 补全 6 行 7 列视图
for (let i = 1; i <= 42 - size; i++) {
days.push({
type: 'next',
year: yearOfNextMonth,
month: monthOfNextMonth,
date: i,
})
}
return days
},
[firstDayOfWeek]
)

useEffect(() => {
const newDays = getDays(month)
Expand Down
48 changes: 26 additions & 22 deletions src/packages/calendarcard/calendarcard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, ReactNode } from 'react'
import React, { ReactNode, useEffect, useState, useCallback } from 'react'
import classNames from 'classnames'
import { ArrowLeft, ArrowRight, DoubleLeft, DoubleRight } from './icon'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
Expand Down Expand Up @@ -34,6 +34,7 @@ export interface CalendarCardProps extends BasicComponent {
onPageChange: (data: CalendarCardMonth) => void
onChange: (value: CalendarCardValue) => void
}

const defaultProps = {
...ComponentDefaults,
type: 'single',
Expand Down Expand Up @@ -122,27 +123,30 @@ export const CalendarCard = React.forwardRef<
}
}

const getDays = (month: CalendarCardMonth) => {
const y = month.year
const m = month.month
const days = [
...getPrevMonthDays(y, m, firstDayOfWeek),
...getCurrentMonthDays(y, m),
] as CalendarCardDay[]
const size = days.length
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
// 补全 6 行 7 列视图
for (let i = 1; i <= 42 - size; i++) {
days.push({
type: 'next',
year: yearOfNextMonth,
month: monthOfNextMonth,
date: i,
})
}
return days
}
const getDays = useCallback(
(month: CalendarCardMonth) => {
const y = month.year
const m = month.month
const days = [
...getPrevMonthDays(y, m, firstDayOfWeek),
...getCurrentMonthDays(y, m),
] as CalendarCardDay[]
const size = days.length
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
// 补全 6 行 7 列视图
for (let i = 1; i <= 42 - size; i++) {
days.push({
type: 'next',
year: yearOfNextMonth,
month: monthOfNextMonth,
date: i,
})
}
return days
},
[firstDayOfWeek]
)

useEffect(() => {
const newDays = getDays(month)
Expand Down

0 comments on commit 7668b38

Please sign in to comment.