1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-04 21:15:22 +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

@ -5,6 +5,8 @@ import { useUserApi } from "~/composables/api";
import { RecipeTool } from "~/lib/api/types/recipe";
const toolStore: Ref<RecipeTool[]> = ref([]);
const publicStoreLoading = ref(false);
const storeLoading = ref(false);
export function useToolData() {
const data = reactive({
@ -29,7 +31,7 @@ export function useToolData() {
export function usePublicToolStore(groupSlug: string) {
const api = usePublicExploreApi(groupSlug).explore;
const loading = ref(false);
const loading = publicStoreLoading;
const actions = {
...usePublicStoreActions<RecipeTool>(api.tools, toolStore, loading),
@ -38,7 +40,7 @@ export function usePublicToolStore(groupSlug: string) {
},
};
if (!toolStore.value || toolStore.value?.length === 0) {
if (!loading.value && (!toolStore.value || toolStore.value?.length === 0)) {
actions.getAll();
}
@ -51,7 +53,7 @@ export function usePublicToolStore(groupSlug: string) {
export function useToolStore() {
const api = useUserApi();
const loading = ref(false);
const loading = storeLoading;
const actions = {
...useStoreActions<RecipeTool>(api.tools, toolStore, loading),
@ -60,7 +62,7 @@ export function useToolStore() {
},
};
if (!toolStore.value || toolStore.value?.length === 0) {
if (!loading.value && (!toolStore.value || toolStore.value?.length === 0)) {
actions.getAll();
}