diff --git a/src/lib/ldb/public-ldb.svelte b/src/lib/ldb/public-ldb.svelte index cfd4e6e..8d56f12 100644 --- a/src/lib/ldb/public-ldb.svelte +++ b/src/lib/ldb/public-ldb.svelte @@ -1,71 +1,115 @@ - - + export let station = ""; + import { onMount } from 'svelte' -
{requestedStation.toUpperCase()}
+ let requestedStation; + $: requestedStation = station; -- {#each services as service} - {service.origin?.location?.locationName || 'Unknown'} - {/each} -
+ let jsonData = null; + let services = []; + let dataAge = ""; + + $: { + if (jsonData === null && requestedStation) { + fetchData(); + } + + if (jsonData && jsonData.GetStationBoardResult && jsonData.GetStationBoardResult.generatedAt) { + dataAge = [...jsonData.GetStationBoardResult.generatedAt]; + } + + if (jsonData && jsonData.GetStationBoardResult && jsonData.GetStationBoardResult.trainServices && jsonData.GetStationBoardResult.trainServices.service) { + services = [...jsonData.GetStationBoardResult.trainServices.service]; + } else { + services = []; + } + } + + 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(); + } + }); + + +{#if dataAge} + +Data From: {dataAge}
+{/if}From | +To | +Plat. | +Sch Arr. | +Exp Arr. | +Sch Dep. | +Exp Dep. | +|||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From | -To | -Plat. | -Sch Arr. | -Exp Arr. | -Sch Dep. | -Exp Dep. | +{service.origin?.location?.locationName || ''} | +{service.destination?.location?.locationName || ''} | +{service.platform || '-'} | +{service.sta || '-'} | +{service.eta || '-'} | +{service.std || '-'} | +{service.etd || '-'} |
{service.origin?.location?.locationName || ''} | -{service.destination?.location?.locationName || ''} | -{service.platform || '-'} | -