Begin implementation of train data page
This commit is contained in:
parent
cda71f1648
commit
8c9f2de590
@ -4,29 +4,45 @@
|
||||
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
const title = "Timetable Results"
|
||||
let title = "Timetable Results"
|
||||
let id = ""
|
||||
let data = [];
|
||||
|
||||
async function getHeadcode() {
|
||||
return new URLSearchParams(window.location.search).get('headcode');
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
const headcode = await getHeadcode();
|
||||
document.getElementById('headcode').textContent = headcode;
|
||||
const data = await fetch(`https://owlboard.info/api/v1/train/headcode/today/${headcode}`)
|
||||
document.getElementById('data_raw').textContent = await data.text();
|
||||
id = await getHeadcode() || "";
|
||||
data = await fetchData(id);
|
||||
})
|
||||
|
||||
</script>
|
||||
async function fetchData(id = "") {
|
||||
const date = 'now';
|
||||
const searchType = 'headcode'
|
||||
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`
|
||||
const res = await fetch(url);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
<svelte:head>
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>OwlBoard {title}</title>
|
||||
</svelte:head>
|
||||
</svelte:head>
|
||||
|
||||
<Header {title} />
|
||||
<Header {title} />
|
||||
|
||||
<p>Headcode: <span id="headcode"></span></p>
|
||||
<p>{id.toUpperCase()}</p> <!-- NOT REACTIVE YET -->
|
||||
|
||||
<p id="data_raw"></p>
|
||||
{#each data as service}
|
||||
<h2>{service.stops[0]['publicDeparture']} {service.stops[0]['tiploc']} to {service.stops[service['stops'].length -1]['tiploc']}</h2>
|
||||
<p>PIS: {service.pis}</p>
|
||||
{#each service.stops as stop}
|
||||
<p>{stop.tiploc}</p>
|
||||
{/each}
|
||||
{/each}
|
||||
|
||||
<Nav />
|
||||
<p id="data_raw"></p>
|
||||
|
||||
<Nav />
|
Loading…
Reference in New Issue
Block a user