diff --git a/src/js/components/root.js b/src/js/components/root.js index 47792e1..b626ab4 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -74,8 +74,19 @@ class RoutePlanner extends Component { }; } - stationSearch() { - console.log("Searching"); + static getDerivedStateFromProps(props, state) { + if (state.fromStation === null && props.stations && props.stations[0]) { + const abbr = props.stations[0].abbr; + return { fromStation: abbr, toStation: abbr}; + } + return null; + } + + stationSearch(evt) { + evt.preventDefault(); + api.action("bartinfo", "json", { + from: this.state.fromStation, + to: this.state.toStation}); } changeStation(evt) { @@ -98,14 +109,18 @@ class RoutePlanner extends Component { } renderStationForm() { + let initialState = null; + if (this.props.stations && this.props.stations[0]) { + initialState = this.props.stations[0].abbr; + } return (