From 701a55ce29a5ce015cce64f71195f00cfa55ce12 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Thu, 4 Jun 2020 01:30:34 -0700 Subject: [PATCH] Add time picker --- src/js/components/root.js | 67 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) 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 (
+
+ +
+

{ departNow ? Now : "Now" }

+
+
+ +
+

{ departNow ? "At..." : At...}

+
+
+
+
+
+
+
+ + : + +
+
); + } + + render() { const receivedStations = this.props.stations; return (
From: @@ -155,9 +205,17 @@ class RoutePlanner extends Component { +
+ Depart at: + { this.renderTimePicker() } +
); } +} + +class RoutePlanner extends Component { + render() { const curTime = this.props.curTime; @@ -177,8 +235,7 @@ class RoutePlanner extends Component {
Search scheduled trains: - { this.renderStationForm() } - +
or see the official bart scheduler for a given station, date and time: