@@ -2,12 +2,7 @@ import * as React from 'react';
2
2
import { RangeValue , PickerMode } from '../interface' ;
3
3
import { GenerateConfig } from '../generate' ;
4
4
import { 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' ;
11
6
12
7
function getStartEndDistance < DateType > (
13
8
startDate : DateType ,
@@ -17,9 +12,7 @@ function getStartEndDistance<DateType>(
17
12
) : 'same' | 'closing' | 'far' {
18
13
const startNext = getClosingViewDate ( startDate , picker , generateConfig , 1 ) ;
19
14
20
- function getDistance (
21
- compareFunc : ( start : DateType | null , end : DateType | null ) => boolean ,
22
- ) {
15
+ function getDistance ( compareFunc : ( start : DateType | null , end : DateType | null ) => boolean ) {
23
16
if ( compareFunc ( startDate , endDate ) ) {
24
17
return 'same' ;
25
18
}
@@ -31,17 +24,11 @@ function getStartEndDistance<DateType>(
31
24
32
25
switch ( picker ) {
33
26
case 'year' :
34
- return getDistance ( ( start , end ) =>
35
- isSameDecade ( generateConfig , start , end ) ,
36
- ) ;
27
+ return getDistance ( ( start , end ) => isSameDecade ( generateConfig , start , end ) ) ;
37
28
case 'month' :
38
- return getDistance ( ( start , end ) =>
39
- isSameYear ( generateConfig , start , end ) ,
40
- ) ;
29
+ return getDistance ( ( start , end ) => isSameYear ( generateConfig , start , end ) ) ;
41
30
default :
42
- return getDistance ( ( start , end ) =>
43
- isSameMonth ( generateConfig , start , end ) ,
44
- ) ;
31
+ return getDistance ( ( start , end ) => isSameMonth ( generateConfig , start , end ) ) ;
45
32
}
46
33
}
47
34
@@ -59,12 +46,7 @@ function getRangeViewDate<DateType>(
59
46
}
60
47
61
48
if ( startDate && endDate ) {
62
- const distance = getStartEndDistance (
63
- startDate ,
64
- endDate ,
65
- picker ,
66
- generateConfig ,
67
- ) ;
49
+ const distance = getStartEndDistance ( startDate , endDate , picker , generateConfig ) ;
68
50
switch ( distance ) {
69
51
case 'same' :
70
52
return startDate ;
@@ -88,16 +70,11 @@ export default function useRangeViewDates<DateType>({
88
70
picker : PickerMode ;
89
71
defaultDates : RangeValue < DateType > | undefined ;
90
72
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 ] {
95
74
const [ defaultViewDates , setDefaultViewDates ] = React . useState <
96
75
[ DateType | null , DateType | null ]
97
76
> ( ( ) => [ 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 ) ;
101
78
102
79
const startDate = getValue ( values , 0 ) ;
103
80
const endDate = getValue ( values , 1 ) ;
@@ -128,7 +105,7 @@ export default function useRangeViewDates<DateType>({
128
105
129
106
// Reset another one when not have value
130
107
const anotherIndex = ( index + 1 ) % 2 ;
131
- if ( getValue ( values , anotherIndex ) ) {
108
+ if ( ! getValue ( values , anotherIndex ) ) {
132
109
newViewDates = updateValues ( newViewDates , viewDate , anotherIndex ) ;
133
110
}
134
111
0 commit comments