Add initial logic for 'boards'
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="manifest" href="/manifest.webmanifest" />
|
<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
|
<meta
|
||||||
name="description"
|
name="description"
|
||||||
content="Live station departures, Live train tracking, PIS Codes & more"
|
content="Live station departures, Live train tracking, PIS Codes & more"
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ class LocationStore {
|
|||||||
data = $state<LocationRecord[]>([]);
|
data = $state<LocationRecord[]>([]);
|
||||||
loaded = $state(false);
|
loaded = $state(false);
|
||||||
|
|
||||||
async init() {
|
async init(fetcher = fetch) {
|
||||||
if (this.loaded) return;
|
if (this.loaded) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/tiplocs');
|
const res = await fetcher('/api/tiplocs');
|
||||||
this.data = await res.json();
|
this.data = await res.json();
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -21,6 +21,18 @@ class LocationStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
export const LOCATIONS = new LocationStore();
|
||||||
@@ -59,12 +59,14 @@
|
|||||||
color: var(--color-title);
|
color: var(--color-title);
|
||||||
max-width: 300px;
|
max-width: 300px;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
margin-bottom: 30px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.debug-info {
|
.debug-info {
|
||||||
background: rgba(255, 255, 255, 0.05);
|
background: rgba(255, 255, 255, 0.05);
|
||||||
padding: 5px 12px;
|
padding: 5px 15px;
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 20px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte';
|
import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte';
|
||||||
|
|
||||||
onMount(() => LOCATIONS.init());
|
onMount(() => LOCATIONS.init(fetch));
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
|
|
||||||
@@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
const navItems = [
|
const navItems = [
|
||||||
{ label: 'Home', path: '/', icon: IconHome },
|
{ label: 'Home', path: '/', icon: IconHome },
|
||||||
{ label: 'PIS', path: '/pis', icon: IconDialpad },
|
{ label: 'PIS', path: '/pis/', icon: IconDialpad },
|
||||||
{ label: 'Options', path: '/preferences', icon: IconSettings },
|
{ label: 'Options', path: '/preferences/', icon: IconSettings },
|
||||||
{ label: 'About', path: '/about', icon: IconHelp }
|
{ label: 'About', path: '/about/', icon: IconHelp }
|
||||||
];
|
];
|
||||||
|
|
||||||
let navWidth = $state(0);
|
let navWidth = $state(0);
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<nav bind:clientWidth={navWidth}>
|
<nav bind:clientWidth={navWidth}>
|
||||||
<!-- Dynamic Nav Elements Here! -->
|
<!-- Dynamic Nav Elements Here! -->
|
||||||
{#each visibleItems as item}
|
{#each visibleItems as item}
|
||||||
{@const isActive = activePath === item.path}
|
{@const isActive = activePath.replace(/\/$/, '') === item.path.replace(/\/$/, '')}
|
||||||
<a
|
<a
|
||||||
href={item.path}
|
href={item.path}
|
||||||
class="nav-item"
|
class="nav-item"
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
></div>
|
></div>
|
||||||
<div class="menu-popover" transition:slide={{ axis: 'y', duration: 250 }}>
|
<div class="menu-popover" transition:slide={{ axis: 'y', duration: 250 }}>
|
||||||
{#each hiddenItems as item}
|
{#each hiddenItems as item}
|
||||||
{@const isActive = activePath === item.path}
|
{@const isActive = activePath.replace(/\/$/, '') === item.path.replace(/\/$/, '')}
|
||||||
<a
|
<a
|
||||||
href={item.path}
|
href={item.path}
|
||||||
class="menu-popover-item"
|
class="menu-popover-item"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
export const trailingSlash = 'always';
|
export const trailingSlash = 'always';
|
||||||
export const csr = true;
|
export const csr = true;
|
||||||
|
export const ssr = false;
|
||||||
|
|||||||
15
src/routes/board/+page.svelte
Normal file
15
src/routes/board/+page.svelte
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<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}) not found`,
|
||||||
|
owlCode: 'INVALID_LOCATION_CODE',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
location,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -99,5 +99,6 @@
|
|||||||
{"n":"Luton Airport Sidings","t":"LUTSID","c":"","s":"luton airport sidings lutsid"},
|
{"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":"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":"Chelmsford New Hall Junction","t":"CHNJCT","c":"","s":"chelmsford new hall junction chnjct"},
|
||||||
|
{"n":"","t":"BPWY532","c":"","s":"bpwy532"},
|
||||||
{"n":"Ipswich Derby Road Depot","t":"IPDRDP","c":"","s":"ipswich derby road depot ipdrdp"}
|
{"n":"Ipswich Derby Road Depot","t":"IPDRDP","c":"","s":"ipswich derby road depot ipdrdp"}
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user