fix: Only call store APIs once (#3306)

* move loading value to inside async function

* share loading state and use it for throttling
This commit is contained in:
Michael Genson
2024-03-12 17:36:30 -05:00
committed by GitHub
parent 0a344731c8
commit 42523bbfc9
7 changed files with 32 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import { useUserApi } from "~/composables/api";
import { IngredientUnit } from "~/lib/api/types/recipe";
let unitStore: Ref<IngredientUnit[] | null> = ref([]);
const storeLoading = ref(false);
/**
* useUnitData returns a template reactive object
@@ -35,7 +36,7 @@ export const useUnitData = function () {
export const useUnitStore = function () {
const api = useUserApi();
const loading = ref(false);
const loading = storeLoading;
const actions = {
...useStoreActions<IngredientUnit>(api.units, unitStore, loading),
@@ -44,7 +45,7 @@ export const useUnitStore = function () {
},
};
if (!unitStore.value || unitStore.value.length === 0) {
if (!loading.value && (!unitStore.value || unitStore.value.length === 0)) {
unitStore = actions.getAll();
}