Add initial logic for 'boards'
This commit is contained in:
@@ -9,11 +9,11 @@ class LocationStore {
|
||||
data = $state<LocationRecord[]>([]);
|
||||
loaded = $state(false);
|
||||
|
||||
async init() {
|
||||
async init(fetcher = fetch) {
|
||||
if (this.loaded) return;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/tiplocs');
|
||||
const res = await fetcher('/api/tiplocs');
|
||||
this.data = await res.json();
|
||||
this.loaded = true;
|
||||
} catch (err) {
|
||||
@@ -21,6 +21,18 @@ class LocationStore {
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
Reference in New Issue
Block a user