@@ -2,12 +2,7 @@ import * as React from 'react';
22import { RangeValue , PickerMode } from '../interface' ;
33import { GenerateConfig } from '../generate' ;
44import { getValue , updateValues } from '../utils/miscUtil' ;
5- import {
6- getClosingViewDate ,
7- isSameYear ,
8- isSameMonth ,
9- isSameDecade ,
10- } from '../utils/dateUtil' ;
5+ import { getClosingViewDate , isSameYear , isSameMonth , isSameDecade } from '../utils/dateUtil' ;
116
127function getStartEndDistance < DateType > (
138 startDate : DateType ,
@@ -17,9 +12,7 @@ function getStartEndDistance<DateType>(
1712) : 'same' | 'closing' | 'far' {
1813 const startNext = getClosingViewDate ( startDate , picker , generateConfig , 1 ) ;
1914
20- function getDistance (
21- compareFunc : ( start : DateType | null , end : DateType | null ) => boolean ,
22- ) {
15+ function getDistance ( compareFunc : ( start : DateType | null , end : DateType | null ) => boolean ) {
2316 if ( compareFunc ( startDate , endDate ) ) {
2417 return 'same' ;
2518 }
@@ -31,17 +24,11 @@ function getStartEndDistance<DateType>(
3124
3225 switch ( picker ) {
3326 case 'year' :
34- return getDistance ( ( start , end ) =>
35- isSameDecade ( generateConfig , start , end ) ,
36- ) ;
27+ return getDistance ( ( start , end ) => isSameDecade ( generateConfig , start , end ) ) ;
3728 case 'month' :
38- return getDistance ( ( start , end ) =>
39- isSameYear ( generateConfig , start , end ) ,
40- ) ;
29+ return getDistance ( ( start , end ) => isSameYear ( generateConfig , start , end ) ) ;
4130 default :
42- return getDistance ( ( start , end ) =>
43- isSameMonth ( generateConfig , start , end ) ,
44- ) ;
31+ return getDistance ( ( start , end ) => isSameMonth ( generateConfig , start , end ) ) ;
4532 }
4633}
4734
@@ -59,12 +46,7 @@ function getRangeViewDate<DateType>(
5946 }
6047
6148 if ( startDate && endDate ) {
62- const distance = getStartEndDistance (
63- startDate ,
64- endDate ,
65- picker ,
66- generateConfig ,
67- ) ;
49+ const distance = getStartEndDistance ( startDate , endDate , picker , generateConfig ) ;
6850 switch ( distance ) {
6951 case 'same' :
7052 return startDate ;
@@ -88,16 +70,11 @@ export default function useRangeViewDates<DateType>({
8870 picker : PickerMode ;
8971 defaultDates : RangeValue < DateType > | undefined ;
9072 generateConfig : GenerateConfig < DateType > ;
91- } ) : [
92- ( activePickerIndex : 0 | 1 ) => DateType ,
93- ( viewDate : DateType | null , index : 0 | 1 ) => void ,
94- ] {
73+ } ) : [ ( activePickerIndex : 0 | 1 ) => DateType , ( viewDate : DateType | null , index : 0 | 1 ) => void ] {
9574 const [ defaultViewDates , setDefaultViewDates ] = React . useState <
9675 [ DateType | null , DateType | null ]
9776 > ( ( ) => [ getValue ( defaultDates , 0 ) , getValue ( defaultDates , 1 ) ] ) ;
98- const [ viewDates , setInternalViewDates ] = React . useState <
99- RangeValue < DateType >
100- > ( null ) ;
77+ const [ viewDates , setInternalViewDates ] = React . useState < RangeValue < DateType > > ( null ) ;
10178
10279 const startDate = getValue ( values , 0 ) ;
10380 const endDate = getValue ( values , 1 ) ;
@@ -128,7 +105,7 @@ export default function useRangeViewDates<DateType>({
128105
129106 // Reset another one when not have value
130107 const anotherIndex = ( index + 1 ) % 2 ;
131- if ( getValue ( values , anotherIndex ) ) {
108+ if ( ! getValue ( values , anotherIndex ) ) {
132109 newViewDates = updateValues ( newViewDates , viewDate , anotherIndex ) ;
133110 }
134111
0 commit comments