From c329543e663c7e3cf2fce7841ca1e2062aa7eaa3 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Wed, 3 Jun 2020 03:30:21 -0700 Subject: [PATCH] Fix json, handle routes response --- src/js/components/root.js | 15 ++++++--------- src/js/subscription.js | 4 ++++ urbit/app/bartinfo.hoon | 9 ++++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/js/components/root.js b/src/js/components/root.js index b626ab4..50505a5 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -69,13 +69,13 @@ class RoutePlanner extends Component { constructor(props) { super(props); this.state = { - fromStation: null, - toStation: null, + fromStation: "", + toStation: "", }; } static getDerivedStateFromProps(props, state) { - if (state.fromStation === null && props.stations && props.stations[0]) { + if (state.fromStation === "" && props.stations && props.stations[0]) { const abbr = props.stations[0].abbr; return { fromStation: abbr, toStation: abbr}; } @@ -109,18 +109,15 @@ class RoutePlanner extends Component { } renderStationForm() { - let initialState = null; - if (this.props.stations && this.props.stations[0]) { - initialState = this.props.stations[0].abbr; - } + const receivedStations = this.props.stations; return (
From: - { this.renderStationOptions() }
To: - { this.renderStationOptions() } diff --git a/src/js/subscription.js b/src/js/subscription.js index 8dcd03f..f8c9cf5 100644 --- a/src/js/subscription.js +++ b/src/js/subscription.js @@ -20,6 +20,10 @@ export class Subscription { this.handleError.bind(this)); */ + api.bind("/routes", "PUT", api.authTokens.ship, "bartinfo", + this.handleEvent.bind(this), + this.handleError.bind(this)); + api.bind("/elevators", "PUT", api.authTokens.ship, "bartinfo", this.handleEvent.bind(this), this.handleError.bind(this)); diff --git a/urbit/app/bartinfo.hoon b/urbit/app/bartinfo.hoon index cc1952e..da3320b 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -83,6 +83,8 @@ =/ req bart-api-elevator-status:cc [%pass /elevators %arvo %i %request req out] [~[elevator-status-request] this] + ?: ?=([%routes *] path) + [[~] this] ?: ?=([%http-response *] path) `this ?. =(/ path) @@ -192,11 +194,12 @@ (with-json-handler response handler) :: ++ poke-handle-json - |= jon=json + |= jon=json ^- (list card) ~& jon - [~] -:: + =/ update=json *json + [%give %fact ~[/routes] %json !>(update)]~ +:: ++ poke-handle-http-request |= =inbound-request:eyre ^- simple-payload:http