Compare commits

..

3 Commits

13 changed files with 219 additions and 24 deletions

8
package-lock.json generated
View File

@@ -8,7 +8,7 @@
"name": "web-pwa",
"version": "0.0.1",
"dependencies": {
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348",
"@owlboard/owlboard-ts": "^3.0.0-dev.20260428T2753",
"@tabler/icons-svelte": "^3.40.0"
},
"devDependencies": {
@@ -786,9 +786,9 @@
"license": "MIT"
},
"node_modules/@owlboard/owlboard-ts": {
"version": "3.0.0-dev.20260427T2348",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260427T2348/owlboard-ts-3.0.0-dev.20260427t2348.tgz",
"integrity": "sha512-ZZ6h8zSnL/FyEZ6ZSekhK781/5TYMj6y6atRVwKiPH6TfXxauMdEimYCOKQIcoskseH7wItEZRFGAOUDAY3q7w==",
"version": "3.0.0-dev.20260428T2753",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260428T2753/owlboard-ts-3.0.0-dev.20260428t2753.tgz",
"integrity": "sha512-8kZ6oP8MFz+1FHyYZS7lAYSk0Kamq80KAsIcef32/lZTT0GhIjyjZcabWZ0uipAYYsKvGqdm1wtxDrtgKPN/DQ==",
"license": "GPL-3.0",
"dependencies": {
"@owlboard/api-schema-types": "^3.0.3-alpha1",

View File

@@ -41,7 +41,7 @@
"vitest-browser-svelte": "^2.0.2"
},
"dependencies": {
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348",
"@owlboard/owlboard-ts": "^3.0.0-dev.20260428T2753",
"@tabler/icons-svelte": "^3.40.0"
}
}

View File

@@ -39,7 +39,7 @@
align-items: center;
justify-content: center;
min-height: 48px;
min-width: 48px;
min-width: 98px;
appearance: none;
background: transparent;
border: none;

View 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>

View File

@@ -8,6 +8,8 @@
let code = $derived(toc.toUpperCase());
</script>
<!-- SPACE MONO for the font? -->
<div class="toc-container {code}">
{code}
</div>

View 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>

View File

@@ -37,7 +37,7 @@
text-align: center;
width: 90%;
margin: auto;
padding: 10px 0 10px 0;
padding: 10px 0 0 0;
display: flex;
flex-direction: column;
gap: 0.75rem;

View File

@@ -44,7 +44,7 @@
width: 90%;
min-height: 98px;
margin: auto;
padding: 10px 0 10px 0;
padding: 10px 0 0 0;
}
.stations-flex {

17
src/lib/utils/time.ts Normal file
View 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',
});
}

View File

@@ -7,9 +7,11 @@
</script>
<div class="error-wrapper">
{#if page.status == 20}
{#if page.status == 404}
<!-- Warning no data image -->
<img class="err-img" src={noResult} alt="" role="presentation" width="200" height="200" />
{:else}
<!-- STOP Error image -->
<img class="err-img" src={stopErr} alt="" role="presentation" width="150" height="210" />
{/if}
<h2 class="label">{page.status}</h2>

View File

@@ -1,4 +1,5 @@
<script lang="ts">
import HeadcodeSearchCard from '$lib/components/ui/cards/HeadcodeSearchCard.svelte';
import PisStartEndCard from '$lib/components/ui/cards/pis/PisStartEndCard.svelte';
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
import Button from '$lib/components/ui/Button.svelte';
@@ -60,6 +61,7 @@
{#if !resultsLoaded}
<div class="card-container">
<HeadcodeSearchCard />
<PisStartEndCard onsearch={handleStartEndSearch} />
<PisCode onsearch={handleCodeSearch} />
</div>

View File

@@ -1,12 +1,30 @@
<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>
<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>
pre {
background: #1e1e1e;
color: #00ff00;
padding: 1rem;
overflow: auto;
.result-boxes {
width: 95%;
margin: auto;
padding-top: 1rem;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1rem;
}
</style>

View File

@@ -19,11 +19,13 @@ export const load: PageLoad = async ({ url }) => {
});
}
// Declared outside of the try so that it can be used in both the try and catch blocks
let results: ApiTrainsTrainByHeadcode.TrainByHeadcodeResponse[]
try {
const response = await OwlClient.trains.getByHeadcode(headcode, date, toc);
// Shouldn't be needed to cast the type...
const results = (response.data || []);
results = (response.data);
return {
title: headcode.toUpperCase(),
results: results,
@@ -35,11 +37,18 @@ export const load: PageLoad = async ({ url }) => {
owlCode: 'VALIDATION_ERROR',
});
} else if (e instanceof ApiError) {
console.log(e);
throw error(20, {
message: e.message,
owlCode: 'API_ERROR',
});
// Check if NO_RESULTS error, and return empty array if that is the case
if (e.code === "NOT_FOUND") {
return {
title: headcode.toUpperCase(),
results: []
}
} else {
throw error(e.status, {
message: e.message,
owlCode: 'API_ERROR',
});
}
} else if (e instanceof Error) {
throw error(500, {
message: e.message,
@@ -52,4 +61,4 @@ export const load: PageLoad = async ({ url }) => {
})
}
}
}
}