1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-24 15:49:42 +02:00

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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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();
}