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:
parent
0a344731c8
commit
42523bbfc9
7 changed files with 32 additions and 22 deletions
|
@ -4,6 +4,7 @@ import { MultiPurposeLabelOut } from "~/lib/api/types/labels";
|
|||
import { useUserApi } from "~/composables/api";
|
||||
|
||||
let labelStore: Ref<MultiPurposeLabelOut[] | null> = ref([]);
|
||||
const storeLoading = ref(false);
|
||||
|
||||
export function useLabelData() {
|
||||
const data = reactive({
|
||||
|
@ -28,7 +29,7 @@ export function useLabelData() {
|
|||
|
||||
export function useLabelStore() {
|
||||
const api = useUserApi();
|
||||
const loading = ref(false);
|
||||
const loading = storeLoading;
|
||||
|
||||
const actions = {
|
||||
...useStoreActions<MultiPurposeLabelOut>(api.multiPurposeLabels, labelStore, loading),
|
||||
|
@ -37,7 +38,7 @@ export function useLabelStore() {
|
|||
},
|
||||
};
|
||||
|
||||
if (!labelStore.value || labelStore.value?.length === 0) {
|
||||
if (!loading.value && (!labelStore.value || labelStore.value?.length === 0)) {
|
||||
labelStore = actions.getAll();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue