Move 'LocationFilter' fetching to API Lib package
This commit is contained in:
@@ -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