Refactor location object into separate module so that it can be used in multiple locations
This commit is contained in:
26
src/lib/locations-object.svelte.ts
Normal file
26
src/lib/locations-object.svelte.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
interface LocationRecord {
|
||||
n: string; // name
|
||||
t: string; // tiploc
|
||||
c?: string; // crs
|
||||
s: string; // search string
|
||||
}
|
||||
|
||||
class LocationStore {
|
||||
data = $state<LocationRecord[]>([]);
|
||||
loaded = $state(false);
|
||||
|
||||
async init() {
|
||||
if (this.loaded) return;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/tiplocs');
|
||||
this.data = await res.json();
|
||||
this.loaded = true;
|
||||
} catch (err) {
|
||||
console.error('Failed to load locations', err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const LOCATIONS = new LocationStore();
|
||||
Reference in New Issue
Block a user