Compare commits
8 Commits
v3.0.0-dev
...
v3.0.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
| d9b60daa8b | |||
| 2f0a6b9646 | |||
| 1165c02e26 | |||
| 45dd5a1cf5 | |||
| e47bebe7d4 | |||
| b7007d2fb3 | |||
| 64bc5b979d | |||
| 3240560a0b |
1
.npmrc
1
.npmrc
@@ -1 +1,2 @@
|
||||
engine-strict=true
|
||||
@owlboard:registry=https://git.fjla.uk/api/packages/OwlBoard/npm/
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<meta name="title" content="OwlBoard | Your fasted route to live and reference data" />
|
||||
<meta name="title" content="OwlBoard | Your fastest route to live and reference data" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Live station departures, Live train tracking, PIS Codes & more"
|
||||
|
||||
@@ -4,44 +4,26 @@
|
||||
import { fade } from 'svelte/transition';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
interface LocationRecord {
|
||||
n: string; // name
|
||||
t: string; // tiploc
|
||||
c?: string; // crs
|
||||
s: string; // search string
|
||||
}
|
||||
import { LOCATIONS } from '$lib/locations-object.svelte.ts';
|
||||
|
||||
let { value = $bindable() } = $props();
|
||||
|
||||
let results = $state<LocationRecord[]>([]);
|
||||
let locations: LocationRecord[] = [];
|
||||
|
||||
let showResults = $state(false);
|
||||
let selectedIndex = $state(-1);
|
||||
|
||||
const MAX_RESULTS = 5;
|
||||
|
||||
async function loadLocations() {
|
||||
const res = await fetch('/api/tiplocs');
|
||||
locations = await res.json();
|
||||
}
|
||||
|
||||
onMount(loadLocations);
|
||||
|
||||
function tokenize(query: string) {
|
||||
return query.toLowerCase().trim().split(/\s+/).filter(Boolean);
|
||||
}
|
||||
|
||||
function search(query: string) {
|
||||
if (query.length < 3) {
|
||||
results = [];
|
||||
return;
|
||||
}
|
||||
let results = $derived.by(() => {
|
||||
if (value.length < 3) return [];
|
||||
|
||||
const tokens = tokenize(query);
|
||||
const lowerQuery = query.toLowerCase().trim();
|
||||
const tokens = tokenize(value);
|
||||
const lowerQuery = value.toLowerCase().trim();
|
||||
|
||||
results = locations
|
||||
return LOCATIONS.data
|
||||
.filter((r) => tokens.every((t) => r.s.includes(t)))
|
||||
.sort((a, b) => {
|
||||
// Check if query matches CRS
|
||||
@@ -56,10 +38,10 @@
|
||||
return a.n.localeCompare(b.n);
|
||||
})
|
||||
.slice(0, MAX_RESULTS);
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
search(value);
|
||||
if (results) selectedIndex = -1;
|
||||
});
|
||||
|
||||
// Hide results when click outside of container
|
||||
@@ -82,7 +64,7 @@
|
||||
selectedIndex = -1;
|
||||
value = '';
|
||||
console.log('Selected Location: ', JSON.stringify(loc));
|
||||
const queryString = loc.c || loc.t
|
||||
const queryString = loc.c || loc.t;
|
||||
goto(`/board?loc=${queryString.toLowerCase()}`);
|
||||
}
|
||||
|
||||
|
||||
52
src/lib/components/ui/cards/pis/PisCode.svelte
Normal file
52
src/lib/components/ui/cards/pis/PisCode.svelte
Normal file
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import BaseCard from '$lib/components/ui/cards/BaseCard.svelte';
|
||||
import Textbox from '$lib/components/ui/Textbox.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
|
||||
let codeValue = $state('');
|
||||
|
||||
function resetValues(): void {
|
||||
codeValue = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<BaseCard header={'Find by Code'}>
|
||||
<div class="card-content">
|
||||
<div class="textbox-container">
|
||||
<div class="textbox-item-wrapper">
|
||||
<Textbox placeholder={"Code"} uppercase={true} type={'number'} max={9999} bind:value={codeValue} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="button-wrapper">
|
||||
<Button>Search</Button>
|
||||
<Button onclick={resetValues}>Reset</Button>
|
||||
</div>
|
||||
</div>
|
||||
</BaseCard>
|
||||
|
||||
<style>
|
||||
.card-content {
|
||||
text-align: center;
|
||||
width: 90%;
|
||||
margin: auto;
|
||||
padding: 10px 0 10px 0;
|
||||
}
|
||||
|
||||
.textbox-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
gap: 4rem;
|
||||
}
|
||||
|
||||
.textbox-item-wrapper {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.button-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
margin-top: 15px;
|
||||
}
|
||||
</style>
|
||||
57
src/lib/components/ui/cards/pis/PisStartEndCard.svelte
Normal file
57
src/lib/components/ui/cards/pis/PisStartEndCard.svelte
Normal file
@@ -0,0 +1,57 @@
|
||||
<script lang="ts">
|
||||
import BaseCard from '$lib/components/ui/cards/BaseCard.svelte';
|
||||
import Textbox from '$lib/components/ui/Textbox.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
|
||||
let startValue = $state('');
|
||||
let endValue = $state('');
|
||||
|
||||
function resetValues(): void {
|
||||
startValue = '';
|
||||
endValue = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<BaseCard header={'Find by Start/End CRS'}>
|
||||
<div class="card-content">
|
||||
<div class="textbox-container">
|
||||
<div class="textbox-item-wrapper">
|
||||
<Textbox placeholder={"Start"} uppercase={true} maxLength={3} bind:value={startValue} />
|
||||
</div>
|
||||
<div class="textbox-item-wrapper">
|
||||
<Textbox placeholder={"End"} uppercase={true} maxLength={3} bind:value={endValue} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="button-wrapper">
|
||||
<Button>Search</Button>
|
||||
<Button onclick={resetValues}>Reset</Button>
|
||||
</div>
|
||||
</div>
|
||||
</BaseCard>
|
||||
|
||||
<style>
|
||||
.card-content {
|
||||
text-align: center;
|
||||
width: 90%;
|
||||
margin: auto;
|
||||
padding: 10px 0 10px 0;
|
||||
}
|
||||
|
||||
.textbox-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
gap: 4rem;
|
||||
}
|
||||
|
||||
.textbox-item-wrapper {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.button-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
margin-top: 15px;
|
||||
}
|
||||
</style>
|
||||
37
src/lib/locations-object.svelte.ts
Normal file
37
src/lib/locations-object.svelte.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
interface LocationRecord {
|
||||
n: string; // name
|
||||
t: string; // tiploc
|
||||
c?: string; // crs
|
||||
s: string; // search string
|
||||
}
|
||||
|
||||
class LocationStore {
|
||||
data = $state<LocationRecord[]>([]);
|
||||
loaded = $state(false);
|
||||
|
||||
async init(fetcher = fetch) {
|
||||
if (this.loaded) return;
|
||||
|
||||
try {
|
||||
const res = await fetcher('/api/tiplocs');
|
||||
this.data = await res.json();
|
||||
this.loaded = true;
|
||||
} catch (err) {
|
||||
console.error('Failed to load locations', err);
|
||||
}
|
||||
}
|
||||
|
||||
find(id: string | null): LocationRecord | undefined {
|
||||
if (!id) return undefined;
|
||||
|
||||
const query = id.toUpperCase().trim();
|
||||
|
||||
console.log(query);
|
||||
|
||||
return this.data.find((loc) => {
|
||||
return loc.t === query || loc.c === query;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const LOCATIONS = new LocationStore();
|
||||
@@ -59,12 +59,14 @@
|
||||
color: var(--color-title);
|
||||
max-width: 300px;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 30px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
padding: 5px 12px;
|
||||
padding: 5px 15px;
|
||||
margin-top: 0;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.6;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { slide, fade } from 'svelte/transition';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
import { LOCATIONS } from '$lib/locations-object.svelte.ts';
|
||||
|
||||
import '$lib/global.css';
|
||||
|
||||
@@ -10,6 +13,8 @@
|
||||
|
||||
import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte';
|
||||
|
||||
onMount(() => LOCATIONS.init(fetch));
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
// Navigation State
|
||||
@@ -18,9 +23,9 @@
|
||||
|
||||
const navItems = [
|
||||
{ label: 'Home', path: '/', icon: IconHome },
|
||||
{ label: 'PIS', path: '/pis', icon: IconDialpad },
|
||||
{ label: 'Options', path: '/preferences', icon: IconSettings },
|
||||
{ label: 'About', path: '/about', icon: IconHelp }
|
||||
{ label: 'PIS', path: '/pis/', icon: IconDialpad },
|
||||
{ label: 'Options', path: '/preferences/', icon: IconSettings },
|
||||
{ label: 'About', path: '/about/', icon: IconHelp }
|
||||
];
|
||||
|
||||
let navWidth = $state(0);
|
||||
@@ -78,7 +83,7 @@
|
||||
<nav bind:clientWidth={navWidth}>
|
||||
<!-- Dynamic Nav Elements Here! -->
|
||||
{#each visibleItems as item}
|
||||
{@const isActive = activePath === item.path}
|
||||
{@const isActive = activePath.replace(/\/$/, '') === item.path.replace(/\/$/, '')}
|
||||
<a
|
||||
href={item.path}
|
||||
class="nav-item"
|
||||
@@ -110,7 +115,7 @@
|
||||
></div>
|
||||
<div class="menu-popover" transition:slide={{ axis: 'y', duration: 250 }}>
|
||||
{#each hiddenItems as item}
|
||||
{@const isActive = activePath === item.path}
|
||||
{@const isActive = activePath.replace(/\/$/, '') === item.path.replace(/\/$/, '')}
|
||||
<a
|
||||
href={item.path}
|
||||
class="menu-popover-item"
|
||||
@@ -157,6 +162,7 @@
|
||||
.page-title {
|
||||
font-family: 'URW Gothic', sans-serif;
|
||||
font-weight: 600;
|
||||
font-size: clamp(0.9rem, 2.5vw + 0.8rem, 2rem);
|
||||
font-style: normal;
|
||||
margin-left: 5px;
|
||||
padding-bottom: 2px;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export const prerender = true;
|
||||
export const trailingSlash = 'always';
|
||||
export const csr = true;
|
||||
export const ssr = false;
|
||||
|
||||
13
src/routes/board/+page.svelte
Normal file
13
src/routes/board/+page.svelte
Normal file
@@ -0,0 +1,13 @@
|
||||
<section>Live board are not yet implemented on the server</section>
|
||||
|
||||
<style>
|
||||
section {
|
||||
font-family: 'URW Gothic', sans-serif;
|
||||
text-align: center;
|
||||
font-size: 2rem;
|
||||
width: 90%;
|
||||
margin: auto;
|
||||
padding-top: 25px;
|
||||
max-width: 500px;
|
||||
}
|
||||
</style>
|
||||
37
src/routes/board/+page.ts
Normal file
37
src/routes/board/+page.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { LOCATIONS } from '$lib/locations-object.svelte';
|
||||
import type { PageLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageLoad = async ({ url }) => {
|
||||
const locId = url.searchParams.get('loc');
|
||||
|
||||
if (!LOCATIONS.loaded) {
|
||||
await LOCATIONS.init(fetch);
|
||||
}
|
||||
|
||||
let title: string = '';
|
||||
|
||||
if (!locId) {
|
||||
error(400, {
|
||||
message: 'Location not provided',
|
||||
owlCode: 'NO_LOCATION_IN_PATH'
|
||||
});
|
||||
}
|
||||
|
||||
if (locId) {
|
||||
const location = LOCATIONS.find(locId);
|
||||
|
||||
if (location) {
|
||||
title = location.n || location.t;
|
||||
} else {
|
||||
error(404, {
|
||||
message: `Location (${locId.toUpperCase()}) not found`,
|
||||
owlCode: 'INVALID_LOCATION_CODE'
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
title,
|
||||
location
|
||||
};
|
||||
};
|
||||
33
src/routes/pis/+page.svelte
Normal file
33
src/routes/pis/+page.svelte
Normal file
@@ -0,0 +1,33 @@
|
||||
<script lang="ts">
|
||||
import PisStartEndCard from '$lib/components/ui/cards/pis/PisStartEndCard.svelte';
|
||||
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
||||
</script>
|
||||
|
||||
<div class="card-container">
|
||||
<PisStartEndCard />
|
||||
<PisCode />
|
||||
</div>
|
||||
|
||||
<div class="result-container">
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.card-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
justify-content: center;
|
||||
padding: 20px 10px;
|
||||
}
|
||||
|
||||
.result-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
justify-content: center;
|
||||
background: var(--color-accent);
|
||||
}
|
||||
</style>
|
||||
5
src/routes/pis/+page.ts
Normal file
5
src/routes/pis/+page.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const load = () => {
|
||||
return {
|
||||
title: 'PIS Codes'
|
||||
};
|
||||
};
|
||||
@@ -99,5 +99,8 @@
|
||||
{"n":"Luton Airport Sidings","t":"LUTSID","c":"","s":"luton airport sidings lutsid"},
|
||||
{"n":"Stevenage Hitchin Junction","t":"STHJC","c":"","s":"stevenage hitchin junction sthjc"},
|
||||
{"n":"Chelmsford New Hall Junction","t":"CHNJCT","c":"","s":"chelmsford new hall junction chnjct"},
|
||||
{"n":"Ipswich Derby Road Depot","t":"IPDRDP","c":"","s":"ipswich derby road depot ipdrdp"}
|
||||
{"n":"","t":"BPWY532","c":"","s":"bpwy532"},
|
||||
{"n":"Ipswich Derby Road Depot","t":"IPDRDP","c":"","s":"ipswich derby road depot ipdrdp"},
|
||||
{"n":"Rhoose Cardiff International Airport","c":"RIA","t":"RHOOSE","s":"rhoose cardiff international airport ria"},
|
||||
{"n":"Southampton Airport Parkway","c":"SOA","t":"SOTAPT","s":"southampton airport parkway soa sotapt"}
|
||||
]
|
||||
Reference in New Issue
Block a user