From 7502be1c5e445e9f75e231e136af93184210f006 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Wed, 3 Jun 2020 03:22:09 -0700 Subject: [PATCH] StationPicker sends json message --- src/js/components/root.js | 23 +++++++++++++++++++---- urbit/app/bartinfo.hoon | 10 ++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) 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