Add train service boxes... not yet expanding!
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
min-height: 48px;
|
min-height: 48px;
|
||||||
min-width: 48px;
|
min-width: 98px;
|
||||||
appearance: none;
|
appearance: none;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
|
|||||||
55
src/lib/components/ui/NoResults.svelte
Normal file
55
src/lib/components/ui/NoResults.svelte
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import noResult from '$lib/assets/img/no-data.svg';
|
||||||
|
import Button from '$lib/components/ui/Button.svelte';
|
||||||
|
let { title = "No results", message = "Try checking your search term"} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="no-results-state">
|
||||||
|
<img src={noResult} class="image" height="200" width="200" alt="" role="presentation">
|
||||||
|
<h3>{title}</h3>
|
||||||
|
<p>{message}</p>
|
||||||
|
<div class="btn-container">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onclick={() => history.length > 1 ? history.back() : window.location.href = '/'}
|
||||||
|
color="accent"
|
||||||
|
>
|
||||||
|
Go back
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.no-results-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 400px;
|
||||||
|
padding: 5rem;
|
||||||
|
text-align: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-family: 'URW-Gothic', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image {
|
||||||
|
margin-bottom: 1.95rem;
|
||||||
|
max-width: 90%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-container {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
let code = $derived(toc.toUpperCase());
|
let code = $derived(toc.toUpperCase());
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- SPACE MONO for the font? -->
|
||||||
<div class="toc-container {code}">
|
<div class="toc-container {code}">
|
||||||
{code}
|
{code}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
90
src/lib/components/ui/TrainService.svelte
Normal file
90
src/lib/components/ui/TrainService.svelte
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { ApiTrainsTrainByHeadcode } from '@owlboard/owlboard-ts';
|
||||||
|
import { slide } from 'svelte/transition';
|
||||||
|
import { formatUkTime } from '$lib/utils/time';
|
||||||
|
import TocStyle from '$lib/components/ui/TocStyle.svelte';
|
||||||
|
|
||||||
|
let { service }: { service: ApiTrainsTrainByHeadcode.TrainByHeadcodeResponse} = $props();
|
||||||
|
let isExpanded = $state(false);
|
||||||
|
|
||||||
|
const toggleExpand = () => isExpanded = !isExpanded;
|
||||||
|
|
||||||
|
let OriginDepartureSummary = $derived(formatUkTime(service.od));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="train-service">
|
||||||
|
<button class="summary" onclick={toggleExpand} type="button" aria-expanded={isExpanded}>
|
||||||
|
<div class="operator-summary">
|
||||||
|
<TocStyle toc={service.o} />
|
||||||
|
</div>
|
||||||
|
<div class="main-text-summary">
|
||||||
|
<div class="time-summary">
|
||||||
|
{OriginDepartureSummary}
|
||||||
|
</div>
|
||||||
|
<div class="location-summary">
|
||||||
|
{service.ot}
|
||||||
|
</div>
|
||||||
|
<div class="location-summary to-summary">
|
||||||
|
to
|
||||||
|
</div>
|
||||||
|
<div class="location-summary">
|
||||||
|
{service.dt}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.train-service {
|
||||||
|
background-color: var(--color-accent);
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: var(--shadow-std);
|
||||||
|
overflow: hidden;
|
||||||
|
font-family: 'URW Gothic', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.75rem;
|
||||||
|
min-height: 48px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operator-summary {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-text-summary {
|
||||||
|
display: flex;
|
||||||
|
flex-grow: 1;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-summary {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-brand);
|
||||||
|
}
|
||||||
|
|
||||||
|
.location-summary {
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
letter-spacing: 0.02em;
|
||||||
|
color: var(--color-title);
|
||||||
|
}
|
||||||
|
|
||||||
|
.to-summary {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-style: oblique;
|
||||||
|
text-transform: lowercase;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
padding: 10px 0 10px 0;
|
padding: 10px 0 0 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
width: 90%;
|
width: 90%;
|
||||||
min-height: 98px;
|
min-height: 98px;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
padding: 10px 0 10px 0;
|
padding: 10px 0 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stations-flex {
|
.stations-flex {
|
||||||
|
|||||||
17
src/lib/utils/time.ts
Normal file
17
src/lib/utils/time.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Converts ISO/JSON time to UK-formatted HH:MM string.
|
||||||
|
* Ensures Europe/London timezone irrespective of browser timezone.
|
||||||
|
*/
|
||||||
|
export function formatUkTime(dateStr: string | Date | undefined): string {
|
||||||
|
if (!dateStr) return '--:--';
|
||||||
|
const date = typeof dateStr === 'string' ? new Date(dateStr): dateStr;
|
||||||
|
|
||||||
|
if (isNaN(date.getTime())) return '--:--';
|
||||||
|
|
||||||
|
return date.toLocaleTimeString('en-GB', {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
timeZone: 'Europe/London',
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import HeadcodeSearchCard from '$lib/components/ui/cards/HeadcodeSearchCard.svelte';
|
||||||
import PisStartEndCard from '$lib/components/ui/cards/pis/PisStartEndCard.svelte';
|
import PisStartEndCard from '$lib/components/ui/cards/pis/PisStartEndCard.svelte';
|
||||||
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
||||||
import Button from '$lib/components/ui/Button.svelte';
|
import Button from '$lib/components/ui/Button.svelte';
|
||||||
@@ -60,6 +61,7 @@
|
|||||||
|
|
||||||
{#if !resultsLoaded}
|
{#if !resultsLoaded}
|
||||||
<div class="card-container">
|
<div class="card-container">
|
||||||
|
<HeadcodeSearchCard />
|
||||||
<PisStartEndCard onsearch={handleStartEndSearch} />
|
<PisStartEndCard onsearch={handleStartEndSearch} />
|
||||||
<PisCode onsearch={handleCodeSearch} />
|
<PisCode onsearch={handleCodeSearch} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,12 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let { data } = $props();
|
import NoResults from '$lib/components/ui/NoResults.svelte';
|
||||||
|
import TrainService from '$lib/components/ui/TrainService.svelte';
|
||||||
|
let { data } = $props();
|
||||||
</script>
|
</script>
|
||||||
<pre>{JSON.stringify(data.results, null, 1)}</pre>
|
|
||||||
|
{#if data.results.length === 0}
|
||||||
|
<NoResults
|
||||||
|
message={"No trains found on this date with this headcode."}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<div class="result-boxes">
|
||||||
|
{#each data.results as service (service.r)}
|
||||||
|
<TrainService {service} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
pre {
|
.result-boxes {
|
||||||
background: #1e1e1e;
|
width: 95%;
|
||||||
color: #00ff00;
|
margin: auto;
|
||||||
padding: 1rem;
|
padding-top: 1rem;
|
||||||
overflow: auto;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user