Fix json, handle routes response

This commit is contained in:
ronreg-ribdev 2020-06-03 03:30:21 -07:00
parent 7502be1c5e
commit c329543e66
3 changed files with 16 additions and 12 deletions

View File

@ -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 (<form name="bartSearch" onSubmit={this.stationSearch.bind(this)}>
From:
<select disabled={!initialState} name="fromStation" value={this.state.fromStation || initialState} onChange={this.changeStation.bind(this)}>
<select disabled={!receivedStations} name="fromStation" value={this.state.fromStation} onChange={this.changeStation.bind(this)}>
{ this.renderStationOptions() }
</select>
<br/>
To:
<select disabled={!initialState} name="toStation" value={this.state.toStation || initialState} onChange={this.changeStation.bind(this)}>
<select disabled={!receivedStations} name="toStation" value={this.state.toStation} onChange={this.changeStation.bind(this)}>
{ this.renderStationOptions() }
</select>
<input type="submit" value="Search"/>

View File

@ -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));

View File

@ -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