mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
refactor to fix infinite loop when instance has no cookbooks
This commit is contained in:
parent
ba5c8a3afb
commit
517216e9eb
1 changed files with 40 additions and 20 deletions
|
@ -139,31 +139,47 @@ export default defineNuxtComponent({
|
||||||
|
|
||||||
const cookbookPreferences = useCookbookPreferences();
|
const cookbookPreferences = useCookbookPreferences();
|
||||||
|
|
||||||
function getStoreData<T>(
|
const ownCookbookStore = useCookbookStore(i18n);
|
||||||
ownGroupStoreFn: (i18n: any) => { store: Ref<T[]>; actions: { refresh: () => void } },
|
const ownHouseholdStore = useHouseholdStore(i18n);
|
||||||
publicStoreFn: (groupSlug: string, i18n: any) => { store: Ref<T[]>; actions: { refresh: () => void } },
|
|
||||||
): T[] {
|
|
||||||
let store;
|
|
||||||
|
|
||||||
if (isOwnGroup.value) {
|
const publicCookbookStoreCache = ref<Record<string, ReturnType<typeof usePublicCookbookStore>>>({});
|
||||||
store = ownGroupStoreFn(i18n);
|
const publicHouseholdStoreCache = ref<Record<string, ReturnType<typeof usePublicHouseholdStore>>>({});
|
||||||
}
|
|
||||||
else if (groupSlug.value) {
|
|
||||||
store = publicStoreFn(groupSlug.value, i18n);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!store.store.value.length) {
|
function getPublicCookbookStore(slug: string) {
|
||||||
store.actions.refresh();
|
if (!publicCookbookStoreCache.value[slug]) {
|
||||||
|
publicCookbookStoreCache.value[slug] = usePublicCookbookStore(slug, i18n);
|
||||||
}
|
}
|
||||||
|
return publicCookbookStoreCache.value[slug];
|
||||||
return store.store.value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cookbooks = computed(() => getStoreData(useCookbookStore, usePublicCookbookStore));
|
function getPublicHouseholdStore(slug: string) {
|
||||||
const households = computed(() => getStoreData(useHouseholdStore, usePublicHouseholdStore));
|
if (!publicHouseholdStoreCache.value[slug]) {
|
||||||
|
publicHouseholdStoreCache.value[slug] = usePublicHouseholdStore(slug, i18n);
|
||||||
|
}
|
||||||
|
return publicHouseholdStoreCache.value[slug];
|
||||||
|
}
|
||||||
|
|
||||||
|
const cookbooks = computed(() => {
|
||||||
|
if (isOwnGroup.value) {
|
||||||
|
return ownCookbookStore.store.value;
|
||||||
|
}
|
||||||
|
else if (groupSlug.value) {
|
||||||
|
const publicStore = getPublicCookbookStore(groupSlug.value);
|
||||||
|
return unref(publicStore.store);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
const households = computed(() => {
|
||||||
|
if (isOwnGroup.value) {
|
||||||
|
return ownHouseholdStore.store.value;
|
||||||
|
}
|
||||||
|
else if (groupSlug.value) {
|
||||||
|
const publicStore = getPublicHouseholdStore(groupSlug.value);
|
||||||
|
return unref(publicStore.store);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
const householdsById = computed(() => {
|
const householdsById = computed(() => {
|
||||||
return households.value.reduce((acc, household) => {
|
return households.value.reduce((acc, household) => {
|
||||||
|
@ -196,6 +212,10 @@ export default defineNuxtComponent({
|
||||||
|
|
||||||
const currentUserHouseholdId = computed(() => $auth.user.value?.householdId);
|
const currentUserHouseholdId = computed(() => $auth.user.value?.householdId);
|
||||||
const cookbookLinks = computed<SideBarLink[]>(() => {
|
const cookbookLinks = computed<SideBarLink[]>(() => {
|
||||||
|
if (!cookbooks.value?.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const sortedCookbooks = [...cookbooks.value].sort((a, b) => (a.position || 0) - (b.position || 0));
|
const sortedCookbooks = [...cookbooks.value].sort((a, b) => (a.position || 0) - (b.position || 0));
|
||||||
|
|
||||||
const ownLinks: SideBarLink[] = [];
|
const ownLinks: SideBarLink[] = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue