Begin work on public board component
This commit is contained in:
@@ -1,29 +1,39 @@
|
||||
<script>
|
||||
export let station = "";
|
||||
import {onMount} from 'svelte'
|
||||
|
||||
let requestedStation = "";
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
let requestedStation;
|
||||
$: requestedStation = station;
|
||||
|
||||
let jsonData = {};
|
||||
/**
|
||||
* @type {any[]}
|
||||
*/
|
||||
|
||||
let jsonData = null;
|
||||
let services = [];
|
||||
|
||||
$: {
|
||||
if (jsonData && jsonData.GetStationBoardResult && jsonData.GetStationBoardResult.trainServices && jsonData.GetStationBoardResult.trainServices.service) {
|
||||
services = [...jsonData.GetStationBoardResult.trainServices.service];
|
||||
} else {
|
||||
services = ["No train services available"];
|
||||
}
|
||||
if (jsonData === null && requestedStation) {
|
||||
fetchData();
|
||||
}
|
||||
|
||||
if (jsonData && jsonData.GetStationBoardResult && jsonData.GetStationBoardResult.trainServices && jsonData.GetStationBoardResult.trainServices.service) {
|
||||
services = [...jsonData.GetStationBoardResult.trainServices.service];
|
||||
} else {
|
||||
services = ["No train services available"];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
const data = await fetch(`https://owlboard.info/api/v1/ldb/${station}`);
|
||||
jsonData = await data.json();
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
async function fetchData() {
|
||||
console.log(`Requested Station: ${requestedStation}`);
|
||||
const data = await fetch(`https://owlboard.info/api/v1/ldb/${requestedStation}`);
|
||||
jsonData = await data.json();
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (requestedStation && jsonData === null) {
|
||||
fetchData();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<p>{requestedStation.toUpperCase()}</p>
|
||||
|
||||
@@ -47,7 +57,7 @@
|
||||
<tr>
|
||||
<td>{service.origin?.location?.locationName || ''}</td>
|
||||
<td>{service.destination?.location?.locationName || ''}</td>
|
||||
<td>{service.platform || ''}</td>
|
||||
<td>{service.platform || '-'}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</table>
|
||||
@@ -56,5 +66,6 @@
|
||||
table {
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user