Refactor location object into separate module so that it can be used in multiple locations

This commit is contained in:
2026-03-17 19:28:02 +00:00
parent a327582629
commit 3240560a0b
3 changed files with 43 additions and 26 deletions

View 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();