From bb0852ed97fe74ba226701e2d1214befdcf99951 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Fri, 5 Jun 2020 04:09:57 -0700 Subject: [PATCH] Basic search functionalty works! --- src/js/components/root.js | 34 +++++++++++++++++++++++++++++++++- urbit/app/bartinfo.hoon | 12 ++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/js/components/root.js b/src/js/components/root.js index 5005df9..12faa1a 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -45,6 +45,7 @@ class ScheduleWidget extends Component { } getSchedule(evt) { console.log("Get schedule"); + // Needs to make a request at https://www.bart.gov/schedules/bystationresults?station=12TH&date=06/03/2020&time=6%3A30%20PM evt.preventDefault(); } @@ -251,15 +252,46 @@ class RouteSearch extends Component { } } +class IndividualRouteResult extends Component { + render() { + const trip = this.props.trip; + return (
+ Depart: {trip.depart} Arrive: {trip.arrive} ({trip.time}) +
+ Cost: {trip.fare} +
+ Legs: + { _.map(trip.legs, (leg) => `${leg.line} line`) } +
); + } +} + class RouteResults extends Component { render() { + const routes = this.props.routes; console.log(this.props.routes); - if (!this.props.routes) { + if (!routes) { return (
); } + const request = routes.request; + const trip = request.trip; + const trips = _.map(trip, (t) => { + return { + fare: t['@fare'], + depart: t['@origTimeMin'], + arrive: t['@destTimeMin'], + time: t['@tripTime'], + legs: _.map(t.leg, (leg) => { + return {line: leg['@trainHeadStation'] }; + }) + }; + }); + return (
Trains: +
+ { _.map(trips, (trip, idx) => ) }
); } } diff --git a/urbit/app/bartinfo.hoon b/urbit/app/bartinfo.hoon index 630af3c..a708fb1 100644 --- a/urbit/app/bartinfo.hoon +++ b/urbit/app/bartinfo.hoon @@ -188,13 +188,17 @@ (with-json-handler response handler) :: ++ bart-api-routeplan +:: Documentation: http://api.bart.gov/docs/sched/depart.aspx |= [from=tape to=tape hour=@ min=@ ispm=?] ^- request:http - :: http://api.bart.gov/api/sched.aspx?cmd=depart&orig=ASHB&dest=CIVC&date=now - :: TODO cmd can be 'depart' or 'arrive', also 'fare' =/ meridian ?:(ispm "pm" "am") - =/ time "{}:{}{meridian}" - =/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y") + =/ minstr ?: =(min 0) "00" + ?: (lte min 9) "0{}" + "{}" + =/ time "{}:{minstr}{meridian}" + =/ before 1 + =/ after 3 + =/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&a={}&b={}&dest={to}&time={time}&key={bart-api-key}&json=y") ~& "Making BART API request to {}" =/ headers [['Accept' 'application/json']]~ [%'GET' url headers *(unit octs)]