From 4437eb079423dab1a0d49d26e540fc1712d101e7 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Fri, 5 Jun 2020 04:38:25 -0700 Subject: [PATCH] Add link to open official BART schedule --- src/js/components/root.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/js/components/root.js b/src/js/components/root.js index 12faa1a..8bce7fc 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -34,6 +34,8 @@ class ScheduleWidget extends Component { constructor(props) { super(props); this.state = { station: "" }; + + } static getDerivedStateFromProps(props, state) { @@ -44,8 +46,18 @@ class ScheduleWidget extends Component { return null; } 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 + const station = this.state.station; + const t = new Date(); + const date = `${t.getMonth()}/${t.getDay()}/${t.getYear()}` + + const hours = t.getHours(); + const h = hours === 0 ? 12 : hours % 12; + const m = padNumber(t.getMinutes()); + const meridian = hours >= 12 ? "PM": "AM" + const timeStr = `${h}:${m} ${meridian}`; + const url = `https://www.bart.gov/schedules/bystationresults?station=${station}&date=${date}&time=${timeStr}`; + window.open(url, '_blank'); evt.preventDefault(); }