Fix json, handle routes response
This commit is contained in:
parent
7502be1c5e
commit
c329543e66
@ -69,13 +69,13 @@ class RoutePlanner extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
fromStation: null,
|
fromStation: "",
|
||||||
toStation: null,
|
toStation: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
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;
|
const abbr = props.stations[0].abbr;
|
||||||
return { fromStation: abbr, toStation: abbr};
|
return { fromStation: abbr, toStation: abbr};
|
||||||
}
|
}
|
||||||
@ -109,18 +109,15 @@ class RoutePlanner extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderStationForm() {
|
renderStationForm() {
|
||||||
let initialState = null;
|
const receivedStations = this.props.stations;
|
||||||
if (this.props.stations && this.props.stations[0]) {
|
|
||||||
initialState = this.props.stations[0].abbr;
|
|
||||||
}
|
|
||||||
return (<form name="bartSearch" onSubmit={this.stationSearch.bind(this)}>
|
return (<form name="bartSearch" onSubmit={this.stationSearch.bind(this)}>
|
||||||
From:
|
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() }
|
{ this.renderStationOptions() }
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
<br/>
|
||||||
To:
|
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() }
|
{ this.renderStationOptions() }
|
||||||
</select>
|
</select>
|
||||||
<input type="submit" value="Search"/>
|
<input type="submit" value="Search"/>
|
||||||
|
@ -20,6 +20,10 @@ export class Subscription {
|
|||||||
this.handleError.bind(this));
|
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",
|
api.bind("/elevators", "PUT", api.authTokens.ship, "bartinfo",
|
||||||
this.handleEvent.bind(this),
|
this.handleEvent.bind(this),
|
||||||
this.handleError.bind(this));
|
this.handleError.bind(this));
|
||||||
|
@ -83,6 +83,8 @@
|
|||||||
=/ req bart-api-elevator-status:cc
|
=/ req bart-api-elevator-status:cc
|
||||||
[%pass /elevators %arvo %i %request req out]
|
[%pass /elevators %arvo %i %request req out]
|
||||||
[~[elevator-status-request] this]
|
[~[elevator-status-request] this]
|
||||||
|
?: ?=([%routes *] path)
|
||||||
|
[[~] this]
|
||||||
?: ?=([%http-response *] path)
|
?: ?=([%http-response *] path)
|
||||||
`this
|
`this
|
||||||
?. =(/ path)
|
?. =(/ path)
|
||||||
@ -192,11 +194,12 @@
|
|||||||
(with-json-handler response handler)
|
(with-json-handler response handler)
|
||||||
::
|
::
|
||||||
++ poke-handle-json
|
++ poke-handle-json
|
||||||
|= jon=json
|
|= jon=json
|
||||||
^- (list card)
|
^- (list card)
|
||||||
~& jon
|
~& jon
|
||||||
[~]
|
=/ update=json *json
|
||||||
::
|
[%give %fact ~[/routes] %json !>(update)]~
|
||||||
|
::
|
||||||
++ poke-handle-http-request
|
++ poke-handle-http-request
|
||||||
|= =inbound-request:eyre
|
|= =inbound-request:eyre
|
||||||
^- simple-payload:http
|
^- simple-payload:http
|
||||||
|
Loading…
Reference in New Issue
Block a user