Add district header on root page

This commit is contained in:
Eli Ribble 2026-04-03 18:28:41 +00:00
parent bfecae7d61
commit 5842b6251d
No known key found for this signature in database
10 changed files with 124 additions and 157 deletions

48
ts/rmo/store/district.ts Normal file
View file

@ -0,0 +1,48 @@
import { ref } from "vue";
import { defineStore } from "pinia";
import { District } from "@/rmo/type";
export const useDistrictStore = defineStore("district", () => {
const districts = ref<District[] | null>(null);
const error = ref<string | null>(null);
const loading = ref<boolean>(false);
const ongoingFetch = ref<Promise<District[]> | null>(null);
async function fetchDistricts(): Promise<District[]> {
loading.value = true;
error.value = null;
try {
const response = await fetch("/api/district");
if (!response.ok) throw new Error("Failed to fetch districts");
const data: District[] = await response.json();
districts.value = data;
return data;
} catch (e) {
error.value = e instanceof Error ? e.message : "an error ocurred";
console.error("Error fetching districts:", e);
throw new Error(error.value);
} finally {
loading.value = false;
}
}
async function get(): Promise<District[]> {
if (districts.value != null) {
return districts.value;
}
if (ongoingFetch.value !== null) {
return ongoingFetch.value;
}
const s = await fetchDistricts();
districts.value = s;
ongoingFetch.value = null;
return s;
}
return {
error,
get,
};
});