nidus-sync/ts/store/api.ts
Eli Ribble 203d2014b0
Show map with nuisance and water on status page
Leverages the new declarative map logic. Still missing a bunch of
features
2026-04-24 22:20:01 +00:00

36 lines
880 B
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
import { apiClient } from "@/client";
import { APIProperties } from "@/type/api";
export const useStoreAPI = defineStore("api", () => {
// State
const _response = ref<APIProperties | null>(null);
const loading = ref(false);
const ongoingFetch = ref<Promise<APIProperties> | null>(null);
// Actions
async function doFetch(): Promise<APIProperties> {
loading.value = true;
const url = "/api";
const resp = (await apiClient.JSONGet(url)) as APIProperties;
return resp;
}
async function get(): Promise<APIProperties> {
if (_response.value) {
return _response.value;
}
if (ongoingFetch.value !== null) {
return ongoingFetch.value;
}
ongoingFetch.value = doFetch().finally(() => {
ongoingFetch.value = null;
});
return ongoingFetch.value;
}
return {
// Actions
get,
};
});