Compare commits
2 Commits
v3.0.0-dev
...
v3.0.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
| a7c244171c | |||
| 3467f97889 |
53
src/lib/components/ui/TocStyle.svelte
Normal file
53
src/lib/components/ui/TocStyle.svelte
Normal file
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
toc: string;
|
||||
}
|
||||
|
||||
let {
|
||||
toc
|
||||
}: Props = $props();
|
||||
|
||||
let code = $derived(toc.toUpperCase());
|
||||
</script>
|
||||
|
||||
<div class="toc-container {code}">
|
||||
{code}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.toc-container {
|
||||
border-radius: 10px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2px 8px;
|
||||
font-weight: 800;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.GW { /* Great Western Railway */
|
||||
background: #004225;
|
||||
color: #E2E2E2;
|
||||
}
|
||||
|
||||
.GR { /* LNER */
|
||||
background-color: #C00000;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.VT { /* Avanti West Coast */
|
||||
background-color: #004354;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.SW { /* South Western Railway */
|
||||
background-color: #2A3389;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.XC { /* CrossCountry */
|
||||
background-color: #660000;
|
||||
color: #E4D5B1;
|
||||
}
|
||||
</style>
|
||||
@@ -4,34 +4,51 @@
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import type { PisObjects } from '@owlboard/api-schema-types';
|
||||
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
|
||||
import TocStyle from '$lib/components/ui/TocStyle.svelte';
|
||||
|
||||
let results = $state<PisObjects[]>([]);
|
||||
let resultsLoaded = $state<boolean>(false);
|
||||
let errorState = $state<{status: number, message: message} | null>(null);
|
||||
let errorState = $state<{status: number, message: string} | null>(null);
|
||||
|
||||
async function handleStartEndSearch(start: string, end: string): Promise<void> {
|
||||
console.log(`PIS Search: ${start}-${end}`);
|
||||
errorState = null;
|
||||
|
||||
try {
|
||||
results = await OwlClient.pis.getByStartEndCrs(start, end);
|
||||
const response = await OwlClient.pis.getByStartEndCrs(start, end);
|
||||
results = await response.data || [];
|
||||
} catch (e) {
|
||||
if (e instanceof ValidationError) {
|
||||
errorState = { status: 400, message: e.message };
|
||||
} else if (e instanceof ApiError) {
|
||||
errorState = { status: 500, message: e.message };
|
||||
console.log(e)
|
||||
errorState = { status: 20, message: e.message };
|
||||
} else {
|
||||
errorState = { status: 0, message: `Unknown Error: ${e.message}` };
|
||||
}
|
||||
} finally {
|
||||
resultsLoaded = true;
|
||||
}
|
||||
|
||||
resultsLoaded = true;
|
||||
}
|
||||
|
||||
function handleCodeSearch(code: string) {
|
||||
async function handleCodeSearch(code: string) {
|
||||
console.log(`PIS Search: ${code}`);
|
||||
// Fetch API Results Here
|
||||
resultsLoaded = true;
|
||||
errorState = null;
|
||||
try {
|
||||
const response = await OwlClient.pis.getByCode(code);
|
||||
results = response.data || []
|
||||
} catch (e) {
|
||||
if (e instanceof ValidationError) {
|
||||
errorState = { status: 400, message: e.message };
|
||||
} else if (e instanceof ApiError) {
|
||||
console.log(e)
|
||||
errorState = { status: 20, message: e.message };
|
||||
} else {
|
||||
errorState = { status: 0, message: `Unknown Error: ${e.message}` };
|
||||
}
|
||||
} finally {
|
||||
resultsLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
function clearResults() {
|
||||
@@ -49,16 +66,33 @@
|
||||
{:else}
|
||||
<div class="result-container">
|
||||
{#if errorState}
|
||||
<span class="errCode">{errorState.status}</span>
|
||||
<span class="errCode">Error: {errorState.status}</span>
|
||||
<span class="errMsg">{errorState.message}</span>
|
||||
{:else}
|
||||
{#if !results.length}
|
||||
<p class="no-results">No results found</p>
|
||||
{:else}
|
||||
<p class="no-results">Results Loaded - Display logic not present</p>
|
||||
{/if}{/if}
|
||||
{#if results.length}
|
||||
<h2 class="result-title">{results.length} Result{#if results.length > 1}s{/if} found</h2>
|
||||
<table class="result-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:16%">TOC</th>
|
||||
<th style="width:14%">Code</th>
|
||||
<th style="width:70%">Locations</th>
|
||||
</tr></thead>
|
||||
{#each results as result}
|
||||
<tbody><tr>
|
||||
<td><TocStyle toc={result.toc} /></td>
|
||||
<td>{result.code}</td>
|
||||
<td class="locations-row">{result.crsStops.join(' ')}</td>
|
||||
</tr></tbody>
|
||||
{/each}
|
||||
</table>
|
||||
{:else}
|
||||
<p class="no-results">No matching results</p>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="reset-button-container">
|
||||
<Button onclick={clearResults}>Reset</Button>
|
||||
</div>
|
||||
</div> </div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
@@ -82,11 +116,43 @@
|
||||
justify-content: center;
|
||||
background: var(--color-accent);
|
||||
border-radius: 15px;
|
||||
padding: 0 0 20px 0;
|
||||
padding: 20px 0 20px 0;
|
||||
margin: auto;
|
||||
margin-top: 25px;
|
||||
margin-bottom: 25px;
|
||||
width: 90%;
|
||||
max-width: 1000px;
|
||||
max-width: 500px;
|
||||
box-shadow: var(--shadow-std);
|
||||
}
|
||||
|
||||
.result-title {
|
||||
color: var(--color-brand);
|
||||
}
|
||||
|
||||
.result-table {
|
||||
width: 90%;
|
||||
max-width: 350px;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
table-layout: fixed;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 20px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.locations-row {
|
||||
font-family:'Courier New', Courier, monospace;
|
||||
text-align: left;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.errCode {
|
||||
color: rgb(255, 54, 54);
|
||||
font-weight: 600;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.reset-button-container {
|
||||
padding: 20px 0 3px 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user