StationPicker sends json message

This commit is contained in:
ronreg-ribdev 2020-06-03 03:22:09 -07:00
parent 0a64d70ae3
commit 7502be1c5e
2 changed files with 29 additions and 4 deletions

View File

@ -74,8 +74,19 @@ class RoutePlanner extends Component {
}; };
} }
stationSearch() { static getDerivedStateFromProps(props, state) {
console.log("Searching"); 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) { changeStation(evt) {
@ -98,14 +109,18 @@ class RoutePlanner extends Component {
} }
renderStationForm() { renderStationForm() {
let initialState = null;
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 name="fromStation" value={this.state.fromStation || ""} onChange={this.changeStation.bind(this)}> <select disabled={!initialState} name="fromStation" value={this.state.fromStation || initialState} onChange={this.changeStation.bind(this)}>
{ this.renderStationOptions() } { this.renderStationOptions() }
</select> </select>
<br/> <br/>
To: To:
<select name="toStation" value={this.state.toStation || ""} onChange={this.changeStation.bind(this)}> <select disabled={!initialState} name="toStation" value={this.state.toStation || initialState} onChange={this.changeStation.bind(this)}>
{ this.renderStationOptions() } { this.renderStationOptions() }
</select> </select>
<input type="submit" value="Search"/> <input type="submit" value="Search"/>

View File

@ -60,6 +60,10 @@
%+ give-simple-payload:app eyre-id %+ give-simple-payload:app eyre-id
%+ require-authorization:app inbound-request %+ require-authorization:app inbound-request
poke-handle-http-request:cc 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] ~]) (pairs:enjs [[%elevators %a p.bsa] ~])
(with-json-handler response handler) (with-json-handler response handler)
:: ::
++ poke-handle-json
|= jon=json
^- (list card)
~& jon
[~]
::
++ poke-handle-http-request ++ poke-handle-http-request
|= =inbound-request:eyre |= =inbound-request:eyre
^- simple-payload:http ^- simple-payload:http