Move 'LocationFilter' fetching to API Lib package
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
import { fade } from 'svelte/transition';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { LOCATIONS } from '$lib/locations-object.svelte.ts';
|
||||
import { LOCATIONS } from '$lib/locations-object.svelte';
|
||||
import type { ApiLocationFilter } from '@owlboard/api-schema-types';
|
||||
|
||||
let { value = $bindable() } = $props();
|
||||
|
||||
@@ -59,7 +60,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
function choose(loc: LocationRecord) {
|
||||
function choose(loc: ApiLocationFilter.LocationFilterObject) {
|
||||
showResults = false;
|
||||
selectedIndex = -1;
|
||||
value = '';
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
interface LocationRecord {
|
||||
n: string; // name
|
||||
t: string; // tiploc
|
||||
c?: string; // crs
|
||||
s: string; // search string
|
||||
}
|
||||
import { OwlClient } from "./owlClient";
|
||||
import type { ApiLocationFilter } from "@owlboard/api-schema-types";
|
||||
|
||||
class LocationStore {
|
||||
data = $state<LocationRecord[]>([]);
|
||||
data = $state<ApiLocationFilter.LocationFilterObject[]>([]);
|
||||
loaded = $state(false);
|
||||
|
||||
async init(fetcher = fetch) {
|
||||
async init() {
|
||||
if (this.loaded) return;
|
||||
|
||||
try {
|
||||
const res = await fetcher('/api/tiplocs');
|
||||
this.data = await res.json();
|
||||
const fetch = await OwlClient.locationFilter.getLocationFilterData()
|
||||
this.data = fetch.data;
|
||||
this.loaded = true;
|
||||
} catch (err) {
|
||||
console.error('Failed to load locations', err);
|
||||
}
|
||||
}
|
||||
|
||||
find(id: string | null): LocationRecord | undefined {
|
||||
find(id: string | null): ApiLocationFilter.LocationFilterObject | undefined {
|
||||
if (!id) return undefined;
|
||||
|
||||
const query = id.toUpperCase().trim();
|
||||
|
||||
Reference in New Issue
Block a user