mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
refactor store constructor and add i18n to logged in user flow
This commit is contained in:
parent
6503ab48b4
commit
87aaa45932
1 changed files with 20 additions and 22 deletions
|
@ -139,31 +139,29 @@ export default defineNuxtComponent({
|
||||||
|
|
||||||
const cookbookPreferences = useCookbookPreferences();
|
const cookbookPreferences = useCookbookPreferences();
|
||||||
|
|
||||||
function useStoreWithRefresh<T>(getStore: () => { store: Ref<T[]>; actions: { refresh: () => void } }) {
|
function getStoreData<T>(
|
||||||
const { store, actions } = getStore();
|
ownGroupStoreFn: (i18n: any) => { store: Ref<T[]>; actions: { refresh: () => void } },
|
||||||
if (!store.value.length) {
|
publicStoreFn: (groupSlug: string, i18n: any) => { store: Ref<T[]>; actions: { refresh: () => void } }
|
||||||
actions.refresh();
|
): T[] {
|
||||||
|
let store;
|
||||||
|
|
||||||
|
if (isOwnGroup.value) {
|
||||||
|
store = ownGroupStoreFn(i18n);
|
||||||
|
} else if (groupSlug.value) {
|
||||||
|
store = publicStoreFn(groupSlug.value, i18n);
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
return store.value;
|
|
||||||
|
if (!store.store.value.length) {
|
||||||
|
store.actions.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
return store.store.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cookbooks = computed(() => {
|
const cookbooks = computed(() => getStoreData(useCookbookStore, usePublicCookbookStore));
|
||||||
if (isOwnGroup.value) {
|
const households = computed(() => getStoreData(useHouseholdStore, usePublicHouseholdStore));
|
||||||
return useStoreWithRefresh(() => useCookbookStore());
|
|
||||||
} else if (groupSlug.value) {
|
|
||||||
return useStoreWithRefresh(() => usePublicCookbookStore(groupSlug.value, i18n));
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
})
|
|
||||||
|
|
||||||
const households = computed(() => {
|
|
||||||
if (isOwnGroup.value) {
|
|
||||||
return useStoreWithRefresh(() => useHouseholdStore());
|
|
||||||
} else if (groupSlug.value) {
|
|
||||||
return useStoreWithRefresh(() => usePublicHouseholdStore(groupSlug.value, i18n));
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
|
|
||||||
const householdsById = computed(() => {
|
const householdsById = computed(() => {
|
||||||
return households.value.reduce((acc, household) => {
|
return households.value.reduce((acc, household) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue