diff --git a/src/js/components/root.js b/src/js/components/root.js index e5803c2..6c5a4b4 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -109,19 +109,23 @@ class TimeScheduleWidget extends Component { } } -class RoutePlanner extends Component { +class RouteSearch extends Component { constructor(props) { super(props); + const now = new Date(); this.state = { fromStation: "", toStation: "", + depart: 'now', + min: now.getMinutes(), + hour: now.getHours(), }; } static getDerivedStateFromProps(props, state) { if (state.fromStation === "" && props.stations && props.stations[0]) { const abbr = props.stations[0].abbr; - return { fromStation: abbr, toStation: abbr}; + return { ...state, fromStation: abbr, toStation: abbr}; } return null; } @@ -143,7 +147,53 @@ class RoutePlanner extends Component { } } - renderStationForm() { + setDepartNow(evt) { + evt.preventDefault(); + this.setState({depart: "now"}); + } + + setDepartAt(evt) { + evt.preventDefault(); + const now = new Date(); + this.setState({ + depart: "givenTime", + hour: now.getHours(), + min: now.getMinutes(), + }); + } + + renderTimePicker() { + const state = this.state; + const departNow = this.state.depart === 'now'; + return (