@@ -46,22 +46,15 @@ function DateRangePicker() {
46
46
const from = useSelector ( ( state ) => state . from ) ;
47
47
const until = useSelector ( ( state ) => state . until ) ;
48
48
49
- const initialState = {
50
- // so the idea with this is that we don't want to send from and until back to the state
51
- // until the user clicks some button. This is why these are stored in state here.
52
- from,
53
- until,
54
- opened : false ,
55
- } ;
56
- const [ state , setState ] = useState ( initialState ) ;
49
+ const [ opened , setOpened ] = useState ( false ) ;
57
50
const [ presets , setPresets ] = useState ( defaultPresets ) ;
58
51
59
52
const updateFrom = ( from ) => {
60
- setState ( { from } ) ;
53
+ dispatch ( setDateRange ( from , until ) ) ;
61
54
} ;
62
55
63
56
const updateUntil = ( until ) => {
64
- setState ( { until } ) ;
57
+ dispatch ( setDateRange ( from , until ) ) ;
65
58
} ;
66
59
67
60
const updateDateRange = ( ) => {
@@ -85,27 +78,23 @@ function DateRangePicker() {
85
78
// return from + " to " +until;
86
79
} ;
87
80
88
- const showDropdown = ( ) => {
89
- setState ( {
90
- opened : ! state . opened ,
91
- } ) ;
81
+ const toggleDropdown = ( ) => {
82
+ setOpened ( ! opened ) ;
92
83
} ;
93
84
94
- const selectPreset = ( { from, until } ) => {
95
- dispatch ( setDateRange ( from , until ) ) ;
96
- hideDropdown ( ) ;
85
+ const hideDropdown = ( ) => {
86
+ setOpened ( false ) ;
97
87
} ;
98
88
99
- const hideDropdown = ( ) => {
100
- setState ( {
101
- opened : false ,
102
- } ) ;
89
+ const selectPreset = ( { from, until } ) => {
90
+ dispatch ( setDateRange ( from , until ) ) ;
91
+ setOpened ( false ) ;
103
92
} ;
104
93
105
94
return (
106
- < div className = { state . opened ? "drp-container opened" : "drp-container" } >
95
+ < div className = { opened ? "drp-container opened" : "drp-container" } >
107
96
< OutsideClickHandler onOutsideClick = { hideDropdown } >
108
- < button className = "btn drp-button" onClick = { showDropdown } >
97
+ < button className = "btn drp-button" onClick = { toggleDropdown } >
109
98
< FontAwesomeIcon icon = { faClock } />
110
99
< span > { humanReadableRange ( ) } </ span >
111
100
</ button >
0 commit comments