mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-28 22:54:25 -05:00
fix: Stores Not Populating Sometimes (#6266)
This commit is contained in:
@@ -13,12 +13,13 @@ export const useData = function <T extends BoundT>(defaultObject: T) {
|
||||
};
|
||||
|
||||
export const useReadOnlyStore = function <T extends BoundT>(
|
||||
storeKey: string,
|
||||
store: Ref<T[]>,
|
||||
loading: Ref<boolean>,
|
||||
api: BaseCRUDAPIReadOnly<T>,
|
||||
params = {} as Record<string, QueryValue>,
|
||||
) {
|
||||
const storeActions = useReadOnlyActions(api, store, loading);
|
||||
const storeActions = useReadOnlyActions(`${storeKey}-store-readonly`, api, store, loading);
|
||||
const actions = {
|
||||
...storeActions,
|
||||
async refresh() {
|
||||
@@ -29,21 +30,22 @@ export const useReadOnlyStore = function <T extends BoundT>(
|
||||
},
|
||||
};
|
||||
|
||||
// initial hydration
|
||||
if (!loading.value && !store.value.length) {
|
||||
const result = actions.getAll(1, -1, params);
|
||||
store.value = result.value || [];
|
||||
actions.refresh();
|
||||
}
|
||||
|
||||
return { store, actions };
|
||||
};
|
||||
|
||||
export const useStore = function <T extends BoundT>(
|
||||
storeKey: string,
|
||||
store: Ref<T[]>,
|
||||
loading: Ref<boolean>,
|
||||
api: BaseCRUDAPI<unknown, T, unknown>,
|
||||
params = {} as Record<string, QueryValue>,
|
||||
) {
|
||||
const storeActions = useStoreActions(api, store, loading);
|
||||
const storeActions = useStoreActions(`${storeKey}-store`, api, store, loading);
|
||||
const actions = {
|
||||
...storeActions,
|
||||
async refresh() {
|
||||
@@ -54,9 +56,9 @@ export const useStore = function <T extends BoundT>(
|
||||
},
|
||||
};
|
||||
|
||||
// initial hydration
|
||||
if (!loading.value && !store.value.length) {
|
||||
const result = actions.getAll(1, -1, params);
|
||||
store.value = result.value || [];
|
||||
actions.refresh();
|
||||
}
|
||||
|
||||
return { store, actions };
|
||||
|
||||
Reference in New Issue
Block a user