diff --git a/src/lib/ldb/public-ldb.svelte b/src/lib/ldb/public-ldb.svelte index b6e9677..6f0a7cf 100644 --- a/src/lib/ldb/public-ldb.svelte +++ b/src/lib/ldb/public-ldb.svelte @@ -13,6 +13,7 @@ let ferryServices = []; let dataAge = null; let isLoading = true; + let dataExists = false; $: { if (jsonData === null && requestedStation) { @@ -40,11 +41,12 @@ if (jsonData?.GetStationBoardResult?.locationName) { title = jsonData.GetStationBoardResult.locationName } else { - title = "Loading Board" + title = requestedStation.toUpperCase() } } async function fetchData() { + dataExists = true; isLoading = true; // Set loading state try { console.log(`Requested Station: ${requestedStation}`); @@ -52,6 +54,8 @@ jsonData = await data.json(); } catch (error) { console.error("Error fetching data:", error); + dataExists = false; + title = "Not Found"; } finally { isLoading = false; // Clear loading state } @@ -106,118 +110,122 @@ {#if isLoading} {:else} -

Updated: {dataAge.toLocaleTimeString()}

- {#if services.length} - - - - - - - - - - - {#each services as service} + {#if dataAge} +

Updated: {dataAge.toLocaleTimeString()}

+ {#if services.length} +
FromToPlat.Sch Arr.Exp Arr.Sch Dep.Exp Dep.
- - - - - - - + + + + + + + + {#each services as service} + + + + + + + + + - - {/each} -
{service.origin?.location?.locationName || ''}{service.destination?.location?.locationName || ''}{service.platform || '-'}{parseTime(service.sta).data}{parseTime(service.eta).data}{parseTime(service.std).data}{parseTime(service.etd).data}FromToPlat.Sch Arr.Exp Arr.Sch Dep.Exp Dep.
{service.origin?.location?.locationName || ''}{service.destination?.location?.locationName || ''}{service.platform || '-'}{parseTime(service.sta).data}{parseTime(service.eta).data}{parseTime(service.std).data}{parseTime(service.etd).data}
-

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

+

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

+ {#if service.delayReason} +

{service.delayReason}

{/if} -

- {#if service.delayReason} -

{service.delayReason}

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

{service.cancelReason}

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

{service.cancelReason}

+ {/if} + + {/each} + + {:else} +

No Scheduled Train Services

+ {/if} + {#if busServices.length} +
+ Bus services
+ Bus Services + + + + + + + + + + {#each busServices as service} + + + + + + + + + + + {/each} +
FromToSch Arr.Exp Arr.Sch Dep.Exp Dep.
{service.origin?.location?.locationName || ''}{service.destination?.location?.locationName || ''}{parseTime(service.sta).data}{parseTime(service.eta).data}{parseTime(service.std).data}{parseTime(service.etd).data}
+

+ A {service.operator || 'Unknown'} service +

+ {#if service.delayReason} +

{service.delayReason}

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

{service.cancelReason}

+ {/if} +
+ {/if} + {#if ferryServices.length} +
+ Bus services
+ Ferry Services + + + + + + + + + + {#each ferryServices as service} + + + + + + + + + + + {/each} +
FromToSch Arr.Exp Arr.Sch Dep.Exp Dep.
{service.origin?.location?.locationName || ''}{service.destination?.location?.locationName || ''}{parseTime(service.sta).data}{parseTime(service.eta).data}{parseTime(service.std).data}{parseTime(service.etd).data}
+ {#if service.delayReason} +

{service.delayReason}

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

{service.cancelReason}

+ {/if} +
+ {/if} {:else} -

No Scheduled Train Services

- {/if} - {#if busServices.length} -
- Bus services
- Bus Services - - - - - - - - - - {#each busServices as service} - - - - - - - - - - - {/each} -
FromToSch Arr.Exp Arr.Sch Dep.Exp Dep.
{service.origin?.location?.locationName || ''}{service.destination?.location?.locationName || ''}{parseTime(service.sta).data}{parseTime(service.eta).data}{parseTime(service.std).data}{parseTime(service.etd).data}
-

- A {service.operator || 'Unknown'} service -

- {#if service.delayReason} -

{service.delayReason}

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

{service.cancelReason}

- {/if} -
- {/if} - {#if ferryServices.length} -
- Bus services
- Ferry Services - - - - - - - - - - {#each ferryServices as service} - - - - - - - - - - - {/each} -
FromToSch Arr.Exp Arr.Sch Dep.Exp Dep.
{service.origin?.location?.locationName || ''}{service.destination?.location?.locationName || ''}{parseTime(service.sta).data}{parseTime(service.eta).data}{parseTime(service.std).data}{parseTime(service.etd).data}
- {#if service.delayReason} -

{service.delayReason}

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

{service.cancelReason}

- {/if} -
+

Unable to find this station

{/if} {/if} \ No newline at end of file diff --git a/src/routes/ldb/+page.svelte b/src/routes/ldb/+page.svelte index 36d9c9c..1bca81b 100644 --- a/src/routes/ldb/+page.svelte +++ b/src/routes/ldb/+page.svelte @@ -1,6 +1,6 @@