From 87aaa45932cedbad1aa6d6d0d4fe9d1fd069dae5 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 30 Jun 2025 20:07:49 +0000 Subject: [PATCH] refactor store constructor and add i18n to logged in user flow --- frontend/components/Layout/DefaultLayout.vue | 42 ++++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/frontend/components/Layout/DefaultLayout.vue b/frontend/components/Layout/DefaultLayout.vue index 17ad3507b..52831f4d0 100644 --- a/frontend/components/Layout/DefaultLayout.vue +++ b/frontend/components/Layout/DefaultLayout.vue @@ -139,31 +139,29 @@ export default defineNuxtComponent({ const cookbookPreferences = useCookbookPreferences(); - function useStoreWithRefresh(getStore: () => { store: Ref; actions: { refresh: () => void } }) { - const { store, actions } = getStore(); - if (!store.value.length) { - actions.refresh(); + function getStoreData( + ownGroupStoreFn: (i18n: any) => { store: Ref; actions: { refresh: () => void } }, + publicStoreFn: (groupSlug: string, i18n: any) => { store: Ref; actions: { refresh: () => void } } + ): 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(() => { - if (isOwnGroup.value) { - 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 cookbooks = computed(() => getStoreData(useCookbookStore, usePublicCookbookStore)); + const households = computed(() => getStoreData(useHouseholdStore, usePublicHouseholdStore)); const householdsById = computed(() => { return households.value.reduce((acc, household) => {