Tidy up train service component, add loading state, convert tiploc to name... etc.
This commit is contained in:
10
src/lib/components/ui/TiplocConverter.svelte
Normal file
10
src/lib/components/ui/TiplocConverter.svelte
Normal file
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { LOCATIONS } from '$lib/locations-object.svelte';
|
||||
|
||||
let { code } = $props<{ code: string | null | undefined }>();
|
||||
|
||||
const location = $derived(LOCATIONS.getName(code));
|
||||
const displayName = $derived(location?.n ?? code ?? '');
|
||||
</script>
|
||||
|
||||
{displayName}
|
||||
@@ -5,12 +5,12 @@
|
||||
import { quintOut } from 'svelte/easing';
|
||||
import { formatUkTime } from '$lib/utils/time';
|
||||
import TocStyle from '$lib/components/ui/TocStyle.svelte';
|
||||
|
||||
import TiplocConverter from '$lib/components/ui/TiplocConverter.svelte';
|
||||
let { service }: { service: ApiTrainsTrainByHeadcode.TrainByHeadcodeResponse } = $props();
|
||||
let isExpanded = $state(false);
|
||||
let loadingDetails = $state(false);
|
||||
let loadingDetailsError = $state(false);
|
||||
let loadingDetailsErrorMsg = $state("");
|
||||
let loadingDetailsErrorMsg = $state('');
|
||||
let details = $state(null);
|
||||
|
||||
const toggleExpand = async (rid: string) => {
|
||||
@@ -19,11 +19,6 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (details) {
|
||||
isExpanded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
loadingDetails = true;
|
||||
try {
|
||||
const result = await OwlClient.trains.getByRid(service.r);
|
||||
@@ -49,11 +44,14 @@
|
||||
loadingDetails = false;
|
||||
}
|
||||
|
||||
const estClass = (act, est) => (!act && est) ? 'est' : 'act';
|
||||
const estClass = (act, est) => (!act && est ? 'est' : 'act');
|
||||
</script>
|
||||
|
||||
<div class="train-service">
|
||||
<button class="summary" onclick={toggleExpand} type="button" aria-expanded={isExpanded}>
|
||||
{#if loadingDetails}
|
||||
<div class="loading-state"><div class="loading-spinner"></div></div>
|
||||
{/if}
|
||||
<div class="operator-summary">
|
||||
<TocStyle toc={service.o} />
|
||||
</div>
|
||||
@@ -61,11 +59,11 @@
|
||||
<div class="time-summary">
|
||||
{OriginDepartureSummary}
|
||||
</div>
|
||||
<div class="location-summary">
|
||||
<div class="location-summary" class:can-all={service.ct}>
|
||||
{service.ot}
|
||||
</div>
|
||||
<div class="location-summary to-summary">to</div>
|
||||
<div class="location-summary">
|
||||
<div class="location-summary to-summary" class:can-all={service.ct}>to</div>
|
||||
<div class="location-summary" class:can-all={service.ct}>
|
||||
{service.dt}
|
||||
</div>
|
||||
<!-- Add arrow icon to signify drop-down -->
|
||||
@@ -77,12 +75,16 @@
|
||||
<!-- Here goes the data formatting! -->
|
||||
<div class="detail-head">
|
||||
<!-- Cancellation Section -->
|
||||
{#if service.ct}
|
||||
<span class="cancel-reason"> Cancelled throughout </span>
|
||||
{/if}
|
||||
{#if details.header.cr}
|
||||
<span class="cancel-reason">
|
||||
{details.header.cr}
|
||||
{#if details.header.cl}
|
||||
{details.header.cn ? ' near ' : ' at '}
|
||||
{details.header.cl}
|
||||
<TiplocConverter code={details.header.cl} />
|
||||
<!-- CONSIDER WRAPPING IN A COMPONENT THAT CONVERTS TO THE LOCATION NAME RATHER THAN TIPLOC -->
|
||||
{/if}
|
||||
</span>
|
||||
{/if}
|
||||
@@ -120,18 +122,24 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each details.locations as loc}
|
||||
<tr class:pass-loc={loc.r === "PASS"} class:can-loc={loc.can}>
|
||||
<tr class:pass-loc={loc.r === 'PASS'} class:can-loc={loc.can}>
|
||||
<td class="tpl-cell">{loc.t}</td>
|
||||
<td class="plat-cell">{loc.p}</td>
|
||||
{#if loc.r == "PASS"}
|
||||
{#if loc.r == 'PASS'}
|
||||
<td class="time-cell" colspan="2">Pass</td>
|
||||
<td class="time-cell">{formatUkTime(loc.wtp)}</td>
|
||||
<td class="time-cell {estClass(loc.atp, loc.etp)}">{formatUkTime(loc.atp || loc.etp || "--")}</td>
|
||||
<td class="time-cell {estClass(loc.atp, loc.etp)}"
|
||||
>{formatUkTime(loc.atp || loc.etp || '--')}</td
|
||||
>
|
||||
{:else}
|
||||
<td class="time-cell">{formatUkTime(loc.pta || loc.wta || "--")}</td>
|
||||
<td class="time-cell {estClass(loc.ata, loc.eta)}">{formatUkTime(loc.ata || loc.eta || "--")}</td>
|
||||
<td class="time-cell">{formatUkTime(loc.ptd || loc.wtd || "--")}</td>
|
||||
<td class="time-cell {estClass(loc.atd, loc.etd)}">{formatUkTime(loc.atd || loc.etd || "--")}</td>
|
||||
<td class="time-cell">{formatUkTime(loc.pta || loc.wta || '--')}</td>
|
||||
<td class="time-cell {estClass(loc.ata, loc.eta)}"
|
||||
>{formatUkTime(loc.ata || loc.eta || '--')}</td
|
||||
>
|
||||
<td class="time-cell">{formatUkTime(loc.ptd || loc.wtd || '--')}</td>
|
||||
<td class="time-cell {estClass(loc.atd, loc.etd)}"
|
||||
>{formatUkTime(loc.atd || loc.etd || '--')}</td
|
||||
>
|
||||
{/if}
|
||||
</tr>
|
||||
{/each}
|
||||
@@ -155,10 +163,11 @@
|
||||
}
|
||||
|
||||
.summary:hover {
|
||||
filter:invert();
|
||||
filter: invert();
|
||||
}
|
||||
|
||||
.summary {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
@@ -171,6 +180,39 @@
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
backdrop-filter: blur(5px);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: 'URW Gothic', sans-serif;
|
||||
font-size: 1rem;
|
||||
color: var(--color-title);
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid rgba(0, 0, 0, 0.1);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: load-spin 0.8s linear infinite;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
@keyframes load-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.operator-summary {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -202,6 +244,10 @@
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.can-all {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.box-ext {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -219,20 +265,21 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cancel-reason, .delay-reason {
|
||||
.cancel-reason,
|
||||
.delay-reason {
|
||||
display: block;
|
||||
padding: 4px 8px;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.cancel-reason {
|
||||
color:rgb(255, 0, 0);
|
||||
color: rgb(255, 0, 0);
|
||||
font-weight: 500;
|
||||
animation: cancel-pulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.delay-reason {
|
||||
color:rgb(255, 119, 0);
|
||||
color: rgb(255, 119, 0);
|
||||
font-weight: 500;
|
||||
animation: cancel-pulse 2s ease-in-out infinite;
|
||||
}
|
||||
@@ -244,7 +291,7 @@
|
||||
}
|
||||
50% {
|
||||
opacity: 0.8;
|
||||
text-shadow: 0 0 5px rgba(255,0,0,0.2)
|
||||
text-shadow: 0 0 5px rgba(255, 0, 0, 0.2);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
@@ -265,7 +312,8 @@
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
th, td {
|
||||
th,
|
||||
td {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,20 @@ class LocationStore {
|
||||
return loc.t === query || loc.c === query;
|
||||
});
|
||||
}
|
||||
|
||||
getName(code: string | number | null | undefined): ApiLocationFilter.LocationFilterObject | null {
|
||||
try {
|
||||
if (!code) return null;
|
||||
|
||||
const query = String(code).toUpperCase().trim();
|
||||
|
||||
const match = this.data.find((loc) => loc.t === query || loc.c === query);
|
||||
return match ?? null;
|
||||
} catch (e) {
|
||||
console.error('Error finding location object: ', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const LOCATIONS = new LocationStore();
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
let { data } = $props();
|
||||
</script>
|
||||
|
||||
<h6 style="text-align:center;width=100%;margin:auto;padding-top:1rem;font-size:1rem;">
|
||||
DateSelector
|
||||
</h6>
|
||||
{#if data.results.length === 0}
|
||||
<NoResults message={'No trains found on this date with this headcode.'} />
|
||||
{:else}
|
||||
|
||||
Reference in New Issue
Block a user