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 (
From: - { this.renderStationOptions() }
To: - { this.renderStationOptions() } diff --git a/urbit/app/bartinfo.hoon b/urbit/app/bartinfo.hoon index c0a1d55..cc1952e 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -60,6 +60,10 @@ %+ give-simple-payload:app eyre-id %+ require-authorization:app inbound-request poke-handle-http-request:cc + %json + =+ !<(jon=json vase) + :_ this + (poke-handle-json:cc jon) :: == :: @@ -187,6 +191,12 @@ (pairs:enjs [[%elevators %a p.bsa] ~]) (with-json-handler response handler) :: +++ poke-handle-json + |= jon=json + ^- (list card) + ~& jon + [~] +:: ++ poke-handle-http-request |= =inbound-request:eyre ^- simple-payload:http