Skip to content

Commit 241ee01

Browse files
author
Michael William Le Nguyen
committed
Add shuttle tracking logic
1 parent 8c8a9f9 commit 241ee01

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/App.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
</div>
1111
<div>
1212
<h1>Shuttles <span class="material-icons">airport_shuttle</span></h1>
13+
<h2 v-if="info.size === 0">No shuttles are currently being tracked.</h2>
14+
<table>
15+
<tbody>
16+
<tr v-for="item in info.values()">
17+
<td style="text-align: left;"><h2>{{ item.title }}</h2></td>
18+
<td><h2>{{ item.prediction + ' ' + (item.prediction === '1' ? 'minute' : 'minutes') }}</h2></td>
19+
</tr>
20+
</tbody>
21+
</table>
1322
</div>
1423
</div>
1524
</div>
@@ -30,12 +39,33 @@ import './app.css'
3039
components: {}
3140
})
3241
export default class App extends Vue {
42+
private error: boolean = false
43+
private info: Map<string, { prediction: string, title: string }> = new Map()
3344
private time: string = ''
3445
3546
private mounted (): void {
3647
setInterval(() => {
3748
this.time = new Date().toLocaleString()
3849
}, 1000)
50+
51+
fetch('http://webservices.nextbus.com/service/publicJSONFeed?command=predictionsForMultiStops&a=mit' +
52+
'&stops=tech|tangwest&stops=saferidecampshut|tangwest').then((data) => {
53+
return data.json()
54+
}).then((data) => {
55+
const info = new Map()
56+
for (const route of data.predictions) {
57+
if (route.direction !== undefined) {
58+
info.set(route.routeTag, {
59+
prediction: route.direction.prediction[0].minutes,
60+
title: route.routeTitle
61+
})
62+
}
63+
}
64+
this.info = info
65+
}).catch((error) => {
66+
this.error = true
67+
console.log(error)
68+
})
3969
}
4070
}
4171
</script>
@@ -50,6 +80,10 @@ h2 {
5080
font-size: 2.5em;
5181
}
5282
83+
table {
84+
width: 100%;
85+
}
86+
5387
#app {
5488
font-family: 'Avenir', Helvetica, Arial, sans-serif;
5589
-webkit-font-smoothing: antialiased;

0 commit comments

Comments
 (0)