Compare commits
4 Commits
v3.0.0-dev
...
v3.0.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
| abb8663766 | |||
| 3225b60140 | |||
| f7b1b7fe0d | |||
| 8c0d385772 |
39
package-lock.json
generated
39
package-lock.json
generated
@@ -8,12 +8,12 @@
|
||||
"name": "web-pwa",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348",
|
||||
"@tabler/icons-svelte": "^3.40.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.2",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@owlboard/owlboard-ts": "^3.0.0-dev.202603302258",
|
||||
"@playwright/test": "^1.58.1",
|
||||
"@sveltejs/adapter-static": "^3.0.10",
|
||||
"@sveltejs/kit": "^2.50.2",
|
||||
@@ -780,20 +780,18 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@owlboard/api-schema-types": {
|
||||
"version": "3.0.2-alpha3",
|
||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fapi-schema-types/-/3.0.2-alpha3/api-schema-types-3.0.2-alpha3.tgz",
|
||||
"integrity": "sha512-3NFP21QdSfjziwlGQixlNnUWC55HlKZGyWANIOimWu0FZejWQWExJiaAVfb6m3Sbv+zvQMu3B8mzcMCcGadZCQ==",
|
||||
"dev": true,
|
||||
"version": "3.0.3-alpha1",
|
||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fapi-schema-types/-/3.0.3-alpha1/api-schema-types-3.0.3-alpha1.tgz",
|
||||
"integrity": "sha512-UWe2nbJWb2B/LuZW1UXHJ2lpqOGwugiXTa4G6X5xLiaws3ISEdciweorX8kr2/JAz5+iFYIe1xXRFAWsFtpn/w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@owlboard/owlboard-ts": {
|
||||
"version": "3.0.0-dev.202603302258",
|
||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.202603302258/owlboard-ts-3.0.0-dev.202603302258.tgz",
|
||||
"integrity": "sha512-uJRoahtqnkmkPg8QsIWhtxhAibWY8xG25fhjzzdDFNE/2+uCj1ev5iD+t0O1dkE7ic3yTcMZqDitEspW216bjw==",
|
||||
"dev": true,
|
||||
"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==",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@owlboard/api-schema-types": "^3.0.2-alpha3",
|
||||
"@owlboard/api-schema-types": "^3.0.3-alpha1",
|
||||
"latlon-geohash": "^2.0.0"
|
||||
}
|
||||
},
|
||||
@@ -1197,9 +1195,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sveltejs/kit": {
|
||||
"version": "2.55.0",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.55.0.tgz",
|
||||
"integrity": "sha512-MdFRjevVxmAknf2NbaUkDF16jSIzXMWd4Nfah0Qp8TtQVoSp3bV4jKt8mX7z7qTUTWvgSaxtR0EG5WJf53gcuA==",
|
||||
"version": "2.58.0",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.58.0.tgz",
|
||||
"integrity": "sha512-kT9GCN8yJTkCK1W+Gi/bvGooWAM7y7WXP+yd+rf6QOIjyoK1ERPrMwSufXJUNu2pMWIqruhFvmz+LbOqsEmKmA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -1226,7 +1224,7 @@
|
||||
"@opentelemetry/api": "^1.0.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0 || ^7.0.0",
|
||||
"svelte": "^4.0.0 || ^5.0.0-next.0",
|
||||
"typescript": "^5.3.3",
|
||||
"typescript": "^5.3.3 || ^6.0.0",
|
||||
"vite": "^5.0.3 || ^6.0.0 || ^7.0.0-beta.0 || ^8.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
@@ -2669,7 +2667,6 @@
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/latlon-geohash/-/latlon-geohash-2.0.0.tgz",
|
||||
"integrity": "sha512-OKBswTwrvTdtenV+9C9euBmvgGuqyjJNAzpQCarRz1m8/pYD2nz9fKkXmLs2S3jeXaLi3Ry76twQplKKUlgS/g==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/levn": {
|
||||
@@ -2977,9 +2974,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.5.6",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz",
|
||||
"integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==",
|
||||
"version": "8.5.12",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.12.tgz",
|
||||
"integrity": "sha512-W62t/Se6rA0Az3DfCL0AqJwXuKwBeYg6nOaIgzP+xZ7N5BFCI7DYi1qs6ygUYT6rvfi6t9k65UMLJC+PHZpDAA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -3581,9 +3578,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-7.3.1.tgz",
|
||||
"integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==",
|
||||
"version": "7.3.2",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-7.3.2.tgz",
|
||||
"integrity": "sha512-Bby3NOsna2jsjfLVOHKes8sGwgl4TT0E6vvpYgnAYDIF/tie7MRaFthmKuHx1NSXjiTueXH3do80FMQgvEktRg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.2",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@owlboard/owlboard-ts": "^3.0.0-dev.202603302258",
|
||||
"@playwright/test": "^1.58.1",
|
||||
"@sveltejs/adapter-static": "^3.0.10",
|
||||
"@sveltejs/kit": "^2.50.2",
|
||||
@@ -42,6 +41,7 @@
|
||||
"vitest-browser-svelte": "^2.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@owlboard/owlboard-ts": "^3.0.0-dev.20260427T2348",
|
||||
"@tabler/icons-svelte": "^3.40.0"
|
||||
}
|
||||
}
|
||||
|
||||
5
src/app.d.ts
vendored
5
src/app.d.ts
vendored
@@ -2,7 +2,10 @@
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
interface Error {
|
||||
message: string;
|
||||
owlCode?: string;
|
||||
}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
</script>
|
||||
|
||||
{#if isNotLondon}
|
||||
<div transition:slide={{duration: 300}} class="tzWarn"><p class="tzText">
|
||||
<div transition:slide={{ duration: 300 }} class="tzWarn">
|
||||
<p class="tzText">
|
||||
All times are shown in <strong>{londonZone}</strong>
|
||||
</p></div>
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
|
||||
45
src/lib/components/ui/cards/HeadcodeSearchCard.svelte
Normal file
45
src/lib/components/ui/cards/HeadcodeSearchCard.svelte
Normal file
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
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 headcode = $state('');
|
||||
|
||||
function handleSearch(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
if (!headcode.trim()) return;
|
||||
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.append('h', headcode.trim().toUpperCase());
|
||||
|
||||
goto(`/trains?${searchParams.toString()}`)
|
||||
}
|
||||
</script>
|
||||
|
||||
<BaseCard header={'Search Train & PIS'}>
|
||||
|
||||
<form onsubmit={handleSearch} class="card-content">
|
||||
<Textbox
|
||||
placeholder="Enter Headcode"
|
||||
bind:value={headcode}
|
||||
maxLength={4}
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={!headcode}
|
||||
>Search</Button>
|
||||
</form>
|
||||
</BaseCard>
|
||||
|
||||
<style>
|
||||
.card-content {
|
||||
text-align: center;
|
||||
width: 90%;
|
||||
margin: auto;
|
||||
padding: 10px 0 10px 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
</style>
|
||||
71
src/lib/components/ui/cards/QuickLinksCard.svelte
Normal file
71
src/lib/components/ui/cards/QuickLinksCard.svelte
Normal file
@@ -0,0 +1,71 @@
|
||||
<script lang="ts">
|
||||
import BaseCard from '$lib/components/ui/cards/BaseCard.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
|
||||
import { fade } from 'svelte/transition';
|
||||
import { flip } from 'svelte/animate';
|
||||
|
||||
import { quickLinks } from '$lib/quick-links.svelte';
|
||||
|
||||
const flipDuration = 300;
|
||||
</script>
|
||||
|
||||
<BaseCard header={'Quick Links'}>
|
||||
<div class="card-content">
|
||||
{#if quickLinks.list.length === 0}
|
||||
<p class="msg">Your most viewed stations will appear here</p>
|
||||
{:else}
|
||||
<div class="stations-flex">
|
||||
{#each quickLinks.list as station (station.id)}
|
||||
<div
|
||||
class="btn-container"
|
||||
animate:flip={{ duration: flipDuration }}
|
||||
in:fade|global={{ duration: 200 }}
|
||||
>
|
||||
<Button href={`/board?loc=${station.id}`}
|
||||
><span class="stn-name">{station.id}</span></Button
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</BaseCard>
|
||||
|
||||
<style>
|
||||
.card-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
width: 90%;
|
||||
min-height: 98px;
|
||||
margin: auto;
|
||||
padding: 10px 0 10px 0;
|
||||
}
|
||||
|
||||
.stations-flex {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.1rem 0.5rem;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.btn-container {
|
||||
display: block;
|
||||
width: fit-content;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.msg {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-title);
|
||||
}
|
||||
|
||||
.stn-name {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
</style>
|
||||
@@ -7,10 +7,16 @@ class NearestStationsState {
|
||||
loading = $state(true);
|
||||
error = $state<string | null>(null);
|
||||
|
||||
private initGeoConfig: PositionOptions = {
|
||||
enableHighAccuracy: false,
|
||||
timeout: 500,
|
||||
maximumAge: Infinity,
|
||||
}
|
||||
|
||||
private geoConfig: PositionOptions = {
|
||||
enableHighAccuracy: false,
|
||||
timeout: 30000,
|
||||
maximumAge: 120000
|
||||
timeout: 20000,
|
||||
maximumAge: 30000,
|
||||
};
|
||||
|
||||
constructor() {
|
||||
@@ -24,7 +30,7 @@ class NearestStationsState {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => this.handleUpdate(pos.coords.latitude, pos.coords.longitude),
|
||||
(err) => this.handleError(err),
|
||||
this.geoConfig
|
||||
this.initGeoConfig
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
60
src/lib/quick-links.svelte.ts
Normal file
60
src/lib/quick-links.svelte.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
export interface QuickLink {
|
||||
id: string;
|
||||
score: number;
|
||||
lastAccessed: number;
|
||||
}
|
||||
|
||||
const RETURNED_LENGTH: number = 9;
|
||||
const MAX_SCORE: number = 50;
|
||||
const MAX_ENTRIES: number = RETURNED_LENGTH * 4;
|
||||
|
||||
class QuickLinksService {
|
||||
#links = $state<QuickLink[]>([]);
|
||||
|
||||
constructor() {
|
||||
if (typeof window !== 'undefined') {
|
||||
const saved = localStorage.getItem('ql');
|
||||
if (saved) {
|
||||
this.#links = JSON.parse(saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get list(): QuickLink[] {
|
||||
return this.#links.slice(0, RETURNED_LENGTH);
|
||||
}
|
||||
|
||||
recordVisit(id: string) {
|
||||
if (id == '') return;
|
||||
const existing = this.#links.find((l) => l.id === id);
|
||||
|
||||
if (existing) {
|
||||
existing.score += 1;
|
||||
existing.lastAccessed = Date.now();
|
||||
} else {
|
||||
this.#links.push({
|
||||
id: id,
|
||||
score: 1,
|
||||
lastAccessed: Date.now()
|
||||
});
|
||||
}
|
||||
|
||||
// Score decay - if MAX_SCORE reached, divide all by two
|
||||
if (this.#links.some((l) => l.score > MAX_SCORE)) {
|
||||
this.#links.forEach((l) => {
|
||||
l.score = Math.max(1, Math.floor(l.score / 2));
|
||||
});
|
||||
}
|
||||
|
||||
// Sort & Prune
|
||||
const sorted = [...this.#links].sort(
|
||||
(a, b) => b.score - a.score || b.lastAccessed - a.lastAccessed
|
||||
);
|
||||
|
||||
this.#links = sorted.slice(0, MAX_ENTRIES);
|
||||
|
||||
localStorage.setItem('ql', JSON.stringify(this.#links));
|
||||
}
|
||||
}
|
||||
|
||||
export const quickLinks = new QuickLinksService();
|
||||
@@ -1,11 +1,15 @@
|
||||
<script lang="ts">
|
||||
import LocationBoardCard from '$lib/components/ui/cards/LocationBoardCard.svelte';
|
||||
import HeadcodeSearchCard from '$lib/components/ui/cards/HeadcodeSearchCard.svelte';
|
||||
import NearbyStationsCard from '$lib/components/ui/cards/NearbyStationsCard.svelte';
|
||||
import QuickLinksCard from '$lib/components/ui/cards/QuickLinksCard.svelte';
|
||||
</script>
|
||||
|
||||
<div class="card-container">
|
||||
<LocationBoardCard />
|
||||
<HeadcodeSearchCard />
|
||||
<NearbyStationsCard />
|
||||
<QuickLinksCard />
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { quickLinks } from '$lib/quick-links.svelte';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
// Update 'QuickLinks'
|
||||
$effect(() => {
|
||||
if (data.BoardLocation) {
|
||||
const id = data.BoardLocation?.c ?? data.BoardLocation?.t;
|
||||
if (id) {
|
||||
// Untrack, as we do not need to handle changes to quickLinks - this is WRITE_ONLY
|
||||
untrack(() => {
|
||||
quickLinks.recordVisit(id);
|
||||
console.log(`QuickLink visit recorded: ${JSON.stringify(data.BoardLocation)}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<section>Live board are not yet implemented on the server</section>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -18,11 +18,13 @@ export const load: PageLoad = async ({ url }) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (locId) {
|
||||
const location = LOCATIONS.find(locId);
|
||||
let BoardLocation;
|
||||
|
||||
if (location) {
|
||||
title = location.n || location.t;
|
||||
if (locId) {
|
||||
BoardLocation = LOCATIONS.find(locId);
|
||||
|
||||
if (BoardLocation) {
|
||||
title = BoardLocation.n || BoardLocation.t || 'Live Arr/Dep';
|
||||
} else {
|
||||
error(404, {
|
||||
message: `Location (${locId.toUpperCase()}) not found`,
|
||||
@@ -32,6 +34,6 @@ export const load: PageLoad = async ({ url }) => {
|
||||
}
|
||||
return {
|
||||
title,
|
||||
location
|
||||
BoardLocation
|
||||
};
|
||||
};
|
||||
|
||||
12
src/routes/trains/+page.svelte
Normal file
12
src/routes/trains/+page.svelte
Normal file
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
let { data } = $props();
|
||||
</script>
|
||||
<pre>{JSON.stringify(data.results, null, 1)}</pre>
|
||||
<style>
|
||||
pre {
|
||||
background: #1e1e1e;
|
||||
color: #00ff00;
|
||||
padding: 1rem;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
55
src/routes/trains/+page.ts
Normal file
55
src/routes/trains/+page.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
|
||||
import type { ApiTrainsTrainByHeadcode } from '@owlboard/owlboard-ts';
|
||||
import type { PageLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageLoad = async ({ url }) => {
|
||||
const headcode = url.searchParams.get('h');
|
||||
let dateParam = url.searchParams.get('d');
|
||||
const toc = url.searchParams.get('t') || "";
|
||||
|
||||
const date: string | Date = (dateParam === "" || dateParam === null)
|
||||
? new Date()
|
||||
: dateParam;
|
||||
|
||||
if (!headcode) {
|
||||
throw error(400, {
|
||||
message: 'Headcode not provided',
|
||||
owlCode: 'INVALID_DATA'
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await OwlClient.trains.getByHeadcode(headcode, date, toc);
|
||||
|
||||
// Shouldn't be needed to cast the type...
|
||||
const results = (response.data || []);
|
||||
return {
|
||||
title: headcode.toUpperCase(),
|
||||
results: results,
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof ValidationError) {
|
||||
throw error(400, {
|
||||
message: e.message,
|
||||
owlCode: 'VALIDATION_ERROR',
|
||||
});
|
||||
} else if (e instanceof ApiError) {
|
||||
console.log(e);
|
||||
throw error(20, {
|
||||
message: e.message,
|
||||
owlCode: 'API_ERROR',
|
||||
});
|
||||
} else if (e instanceof Error) {
|
||||
throw error(20, {
|
||||
message: e.message,
|
||||
owlCode: 'GEN_ERROR',
|
||||
})
|
||||
} else {
|
||||
throw error(500, {
|
||||
message: "Unexpected error",
|
||||
owlCode: "UNKNOWN_ERR",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user