diff --git a/src/js/components/root.js b/src/js/components/root.js index cf40f48..16c928a 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -7,16 +7,40 @@ import { HeaderBar } from "./lib/header-bar.js" export class Root extends Component { constructor(props) { super(props); - - this.state = { fromValue: "ashby", toValue: "24th" }; + this.state = store.state; + store.setStateHandler((newState) => { + this.setState(newState); + }); } action() { console.log("Clickin'"); } - render() { + renderStationOptions() { + const stations = this.state.stations || []; + return _.map(stations, (station) => { + const abbr = station.abbr; + const name = station.name; + return ; + }); + } + renderStationForm() { + return (
+ From: + +
+ To: + +
); + } + + render() { return (
@@ -35,19 +59,9 @@ export class Root extends Component {
Search scheduled trains: + { this.renderStationForm() }
From: - -
- To: -
diff --git a/src/js/reducers/config.js b/src/js/reducers/config.js deleted file mode 100644 index 04bb524..0000000 --- a/src/js/reducers/config.js +++ /dev/null @@ -1,11 +0,0 @@ -import _ from 'lodash'; - - -export class ConfigReducer { - reduce(json, state) { - let data = _.get(json, 'bartinfo', false); - if (data) { - state.inbox = data.inbox; - } - } -} diff --git a/src/js/reducers/initial.js b/src/js/reducers/initial.js deleted file mode 100644 index 2ba151c..0000000 --- a/src/js/reducers/initial.js +++ /dev/null @@ -1,11 +0,0 @@ -import _ from 'lodash'; - - -export class InitialReducer { - reduce(json, state) { - let data = _.get(json, 'initial', false); - if (data) { - state.inbox = data.inbox; - } - } -} diff --git a/src/js/reducers/update.js b/src/js/reducers/update.js index a167c59..a5d62e7 100644 --- a/src/js/reducers/update.js +++ b/src/js/reducers/update.js @@ -5,13 +5,10 @@ export class UpdateReducer { reduce(json, state) { let data = _.get(json, 'update', false); if (data) { - this.reduceInbox(_.get(data, 'inbox', false), state); - } - } - - reduceInbox(inbox, state) { - if (inbox) { - state.inbox = inbox; + const stations = _.get(data, 'stations', false); + if (stations) { + state.stations = stations; + } } } } diff --git a/src/js/store.js b/src/js/store.js index 7b8b8de..71e8b0b 100644 --- a/src/js/store.js +++ b/src/js/store.js @@ -1,33 +1,25 @@ -import { InitialReducer } from '/reducers/initial'; -import { ConfigReducer } from '/reducers/config'; import { UpdateReducer } from '/reducers/update'; class Store { constructor() { - this.state = { - inbox: {} - }; + this.state = {} - this.initialReducer = new InitialReducer(); - this.configReducer = new ConfigReducer(); this.updateReducer = new UpdateReducer(); this.setState = () => { }; } setStateHandler(setState) { + console.log("Calling setStateHandler"); this.setState = setState; } handleEvent(data) { + console.log("Handling event"); + console.log(data); let json = data.data; - console.log("Storing event"); - console.log(json); - this.initialReducer.reduce(json, this.state); - this.configReducer.reduce(json, this.state); this.updateReducer.reduce(json, this.state); - this.setState(this.state); } } diff --git a/src/js/subscription.js b/src/js/subscription.js index 646c6ef..863c5db 100644 --- a/src/js/subscription.js +++ b/src/js/subscription.js @@ -14,9 +14,16 @@ export class Subscription { } initializebartinfo() { + /* api.bind('/primary', 'PUT', api.authTokens.ship, 'bartinfo', this.handleEvent.bind(this), this.handleError.bind(this)); + */ + + api.bind('/bartstations', 'PUT', api.authTokens.ship, 'bartinfo', + this.handleEvent.bind(this), + this.handleError.bind(this)); + } handleEvent(diff) { diff --git a/urbit/app/bartinfo.hoon b/urbit/app/bartinfo.hoon index 7f73534..4dac133 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -73,7 +73,7 @@ |= =path ^- (quip card _this) ~& "on-watch path: {}" - ?: ?=([%primary *] path) + ?: ?=([%bartstations *] path) =/ bart-station-request =/ out *outbound-config:iris =/ req bart-api-request-stations:cc @@ -96,7 +96,9 @@ ?+ wire ~ [%bartstationrequest *] =/ value=json (parse-request-stations-response:cc client-response.sign-arvo) - [%give %fact ~[/primary] %json !>(value)]~ + ?> ?=(%o -.value) + =/ update=json (pairs:enjs:format [update+o+p.value ~]) + [%give %fact ~[/bartstations] %json !>(update)]~ == [http-moves this] ?. ?=(%bound +<.sign-arvo)