blob: 997494dbf5c75b4a82aa38f653eae200a14a19a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// React/Component imports
import { useEffect, useState } from "react";
import DateSelector from './DateSelector.js';
// CSS imports
import '../css/Route.css';
/**
* The component that hold the forms for routing.
* @param {Object} props
*/
function TimeSelector(props) {
const [current, setCurrent] = useState("");
const toValue = date => new Date(date).toISOString().slice(0, 10);
const [startDate, setStartDate] = useState(props.dates.start);
const [endDate, setEndDate] = useState(props.dates.end);
const changeTimeframe = () => {
props.setDates({
start: startDate,
end: endDate
});
}
useEffect(() => setCurrent(""), [startDate, endDate]);
// The div with the html elements for routing.
return (
<div className="Route">
<div className="Coord-selectors-flex">
<DateSelector side={"left"} name={"Start Date"} className="Coord-select-left" clickedFunc={setCurrent}
changedFunc={setStartDate} disabled={current==='start' || props.isChanging} value={toValue(startDate)}></DateSelector>
<div>
<button className="Btn Route-btn" onClick={() => changeTimeframe()}
disabled={current!=="" || props.isChanging}>Adjust Timeframe</button>
</div>
<DateSelector side={"right"} name={"End Date"} className="Coord-select-right" clickedFunc={setCurrent}
changedFunc={setEndDate} disabled={current==='end' || props.isChanging} value={toValue(endDate)}></DateSelector>
</div>
</div>
);
}
export default TimeSelector;
|