34 lines
781 B
TypeScript
34 lines
781 B
TypeScript
import { OwlClient } from './owlClient';
|
|
import type { ApiLocationFilter } from '@owlboard/owlboard-ts';
|
|
|
|
class LocationStore {
|
|
data = $state<ApiLocationFilter.LocationFilterObject[]>([]);
|
|
loaded = $state(false);
|
|
|
|
async init() {
|
|
if (this.loaded) return;
|
|
|
|
try {
|
|
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): ApiLocationFilter.LocationFilterObject | 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();
|