diff --git a/src/lib/components/ui/LocationSearchBox.svelte b/src/lib/components/ui/LocationSearchBox.svelte index d4853e8..5142dde 100644 --- a/src/lib/components/ui/LocationSearchBox.svelte +++ b/src/lib/components/ui/LocationSearchBox.svelte @@ -6,8 +6,6 @@ import { LOCATIONS } from '$lib/locations-object.svelte.ts'; - - let { value = $bindable() } = $props(); let showResults = $state(false); @@ -15,7 +13,6 @@ const MAX_RESULTS = 5; - function tokenize(query: string) { return query.toLowerCase().trim().split(/\s+/).filter(Boolean); } @@ -41,12 +38,11 @@ return a.n.localeCompare(b.n); }) .slice(0, MAX_RESULTS); - }) - + }); $effect(() => { - if (results) selectedIndex = -1; - }); + if (results) selectedIndex = -1; + }); // Hide results when click outside of container $effect(() => { @@ -68,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()}`); } diff --git a/src/lib/locations-object.svelte.ts b/src/lib/locations-object.svelte.ts index 8166fda..a0a4a6d 100644 --- a/src/lib/locations-object.svelte.ts +++ b/src/lib/locations-object.svelte.ts @@ -1,38 +1,37 @@ - interface LocationRecord { - n: string; // name - t: string; // tiploc - c?: string; // crs - s: string; // search string - } - -class LocationStore { - data = $state([]); - 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; - }); - } - +interface LocationRecord { + n: string; // name + t: string; // tiploc + c?: string; // crs + s: string; // search string } -export const LOCATIONS = new LocationStore(); \ No newline at end of file +class LocationStore { + data = $state([]); + 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(); diff --git a/src/routes/board/+page.svelte b/src/routes/board/+page.svelte index f05609e..5a93fab 100644 --- a/src/routes/board/+page.svelte +++ b/src/routes/board/+page.svelte @@ -1,15 +1,13 @@ -
- Live board are not yet implemented on the server -
+
Live board are not yet implemented on the server
\ No newline at end of file + section { + font-family: 'URW Gothic', sans-serif; + text-align: center; + font-size: 2rem; + width: 90%; + margin: auto; + padding-top: 25px; + max-width: 500px; + } + diff --git a/src/routes/board/+page.ts b/src/routes/board/+page.ts index aeb2e25..8aa96c4 100644 --- a/src/routes/board/+page.ts +++ b/src/routes/board/+page.ts @@ -3,35 +3,35 @@ import type { PageLoad } from './$types'; import { error } from '@sveltejs/kit'; export const load: PageLoad = async ({ url }) => { - const locId = url.searchParams.get('loc'); + const locId = url.searchParams.get('loc'); - if (!LOCATIONS.loaded) { - await LOCATIONS.init(fetch); - } + if (!LOCATIONS.loaded) { + await LOCATIONS.init(fetch); + } - let title: string = ""; + let title: string = ''; - if (!locId) { - error(400, { - message: 'Location not provided', - owlCode: 'NO_LOCATION_IN_PATH', - }); - } + if (!locId) { + error(400, { + message: 'Location not provided', + owlCode: 'NO_LOCATION_IN_PATH' + }); + } - if (locId) { - const location = LOCATIONS.find(locId); + 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', - }); - } - } + if (location) { + title = location.n || location.t; + } else { + error(404, { + message: `Location (${locId}) not found`, + owlCode: 'INVALID_LOCATION_CODE' + }); + } + } return { title, - location, + location }; -}; \ No newline at end of file +};