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

@@ -37,6 +37,7 @@ export function usePublicStoreActions<T extends BoundT>(
loading.value = true;
const allItems = useAsync(async () => {
const { data } = await api.getAll(page, perPage, params);
loading.value = false;
if (data && allRef) {
allRef.value = data.items;
@@ -49,7 +50,6 @@ export function usePublicStoreActions<T extends BoundT>(
}
}, useAsyncKey());
loading.value = false;
return allItems;
}
@@ -88,6 +88,7 @@ export function useStoreActions<T extends BoundT>(
loading.value = true;
const allItems = useAsync(async () => {
const { data } = await api.getAll(page, perPage, params);
loading.value = false;
if (data && allRef) {
allRef.value = data.items;
@@ -100,7 +101,6 @@ export function useStoreActions<T extends BoundT>(
}
}, useAsyncKey());
loading.value = false;
return allItems;
}