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:
parent
0a344731c8
commit
42523bbfc9
7 changed files with 32 additions and 22 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue