Begin work on public board component

This commit is contained in:
Fred Boniface 2023-06-17 01:53:08 +01:00
parent ed3dd38769
commit bf8dea7bcd
3 changed files with 38 additions and 23 deletions

View File

@ -1,29 +1,39 @@
<script>
export let station = "";
import {onMount} from 'svelte'
import { onMount } from 'svelte'
let requestedStation = "";
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();
})
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>
</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>

View File

@ -9,10 +9,12 @@
return new URLSearchParams(window.location.search).get('station');
}
let station = ""
let station;
let staff;
onMount(async () => {
station = await getHeadcode() || "";
staff = false;
})
</script>
@ -20,6 +22,8 @@
<Header {title} />
<!-- If 'uuid' exists in store then load StaffLdb else load PublicLdb -->
{#if !staff}
<PublicLdb {station} />
{/if}
<Nav />

View File

@ -5,7 +5,7 @@ export default {
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: '/',
fallback: 'undefined',
precompress: true,
strict: true
})