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} + + + + + + + + + + {#each services as service} - - - - - - - + + + + + + + - {#each services as service} - - - - - - {/each} + +

+ A {service.operator || 'Unknown'} service + {#if service['length']} + with {service['length'] || 'some'} coaches + {/if} +

+ {#if service.delayReason} +

{service.delayReason}

+ {/if} + {#if service.cancelReason} +

{service.cancelReason}

+ {/if} + {/each}
FromToPlat.Sch Arr.Exp Arr.Sch Dep.Exp Dep.
FromToPlat.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 || '-'}
- + \ No newline at end of file + table { + width: 100%; + margin: auto; + color: white; + } + .origdest { + color: yellow; + text-align: left; + } + .from { + width: 25%; + } + .to { + width: 25%; + } + .plat { + width: 10% + } + .time { + width: 10%; + } + .service-detail { + color: cyan; + text-align: left; + font-size: 12px; + padding: 0; + margin: 0; + } +