From ef10aa35e843e029f7f98f70657b220deb778968 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 18 Mar 2026 10:23:52 +0100 Subject: [PATCH] refactor: move groupware account loading to store Moves the groupware account loading to the corresponding account store, as we usually keep data loading and the store operations together in the store. --- packages/web-app-mail/src/views/Inbox.vue | 69 ++++++++++--------- .../Groupware/Accounts/AccountsSwitch.vue | 7 +- .../src/composables/groupware/index.ts | 1 - .../composables/groupware/useLoadAccounts.ts | 44 ------------ packages/web-pkg/src/composables/index.ts | 1 - .../piniaStores/groupware/accounts.ts | 50 ++++++++++++-- 6 files changed, 82 insertions(+), 90 deletions(-) delete mode 100644 packages/web-pkg/src/composables/groupware/index.ts delete mode 100644 packages/web-pkg/src/composables/groupware/useLoadAccounts.ts diff --git a/packages/web-app-mail/src/views/Inbox.vue b/packages/web-app-mail/src/views/Inbox.vue index d904c6c6f5..016b085339 100644 --- a/packages/web-app-mail/src/views/Inbox.vue +++ b/packages/web-app-mail/src/views/Inbox.vue @@ -28,28 +28,34 @@ import { ref, unref, onMounted, onUnmounted } from 'vue' import MailList from '../components/MailList.vue' import MailDetails from '../components/MailDetails.vue' import MailWidget from '../components/MailWidget.vue' -import { AppLoadingSpinner, queryItemAsString, useEventBus } from '@opencloud-eu/web-pkg' +import { + AppLoadingSpinner, + queryItemAsString, + useClientService, + useEventBus +} from '@opencloud-eu/web-pkg' import { useRouteQuery } from '@opencloud-eu/web-pkg' import { useMailsStore } from '../composables/piniaStores/mails' -import { useGroupwareAccountsStore, useLoadAccounts } from '@opencloud-eu/web-pkg' +import { useGroupwareAccountsStore } from '@opencloud-eu/web-pkg' import { storeToRefs } from 'pinia' import { useMailboxesStore } from '../composables/piniaStores/mailboxes' import { useLoadMailboxes } from '../composables/useLoadMailboxes' import { useLoadMails } from '../composables/useLoadMails' import { useLoadMail } from '../composables/useLoadMail' +import { Mailbox } from '../types' const accountsStore = useGroupwareAccountsStore() const mailboxesStore = useMailboxesStore() const mailsStore = useMailsStore() const eventBus = useEventBus() +const { httpAuthenticated } = useClientService() -const { accounts, currentAccount } = storeToRefs(accountsStore) -const { setCurrentAccount } = accountsStore +const { currentAccount } = storeToRefs(accountsStore) +const { loadCurrentAccount } = accountsStore const { mailboxes, currentMailbox } = storeToRefs(mailboxesStore) const { setCurrentMailbox } = mailboxesStore const { currentMail } = storeToRefs(mailsStore) -const { loadAccounts } = useLoadAccounts() const { loadMailboxes } = useLoadMailboxes() const { loadMails } = useLoadMails() const { loadMail } = useLoadMail() @@ -72,44 +78,43 @@ const onCloseCompose = () => { showCompose.value = false } -accountsStore.$onAction(async ({ name }) => { - if (name === 'setCurrentAccount' && unref(currentAccount)) { - setCurrentMail(null) - await loadMailboxes(unref(currentAccount).accountId) - setCurrentMailbox(unref(mailboxes)[0]) - await loadMails(unref(currentAccount).accountId, unref(currentMailbox).id) - } -}) - -onMounted(async () => { - mailComposeEventToken = eventBus.subscribe('app.mail.show-compose-mail', onComposeMail) - await loadAccounts() - if (unref(currentAccountIdQuery)) { - setCurrentAccount( - unref(accounts).find((account) => account.accountId === unref(currentAccountIdQuery)) - ) - } else { - setCurrentAccount(unref(accounts)?.[0]) - } - - console.log(unref(currentAccount)) +const loadMailboxesAndMails = async () => { + isLoading.value = true + setCurrentMail(null) + // load mailboxes await loadMailboxes(unref(currentAccount).accountId) + let queryMailbox: Mailbox | undefined if (unref(currentMailboxIdQuery)) { - setCurrentMailbox( - unref(mailboxes).find((mailbox) => mailbox.id === unref(currentMailboxIdQuery)) - ) - } else { - setCurrentMailbox(unref(mailboxes)?.[0]) + queryMailbox = unref(mailboxes).find(({ id }) => id === unref(currentMailboxIdQuery)) } + setCurrentMailbox(queryMailbox || unref(mailboxes)?.[0]) + // load mails await loadMails(unref(currentAccount).accountId, unref(currentMailbox).id) - if (unref(currentMailIdQuery)) { await loadMail(unref(currentAccount).accountId, queryItemAsString(unref(currentMailIdQuery))) } isLoading.value = false +} + +accountsStore.$onAction(({ after, name }) => { + after(() => { + // load mailboxes and mails when the current account is set + if (['loadCurrentAccount', 'setCurrentAccount'].includes(name) && unref(currentAccount)) { + currentAccountIdQuery.value = unref(currentAccount).accountId + loadMailboxesAndMails() + } + }) +}) + +onMounted(() => { + mailComposeEventToken = eventBus.subscribe('app.mail.show-compose-mail', onComposeMail) + loadCurrentAccount({ + client: httpAuthenticated, + query: queryItemAsString(unref(currentAccountIdQuery)) + }) }) onUnmounted(() => { diff --git a/packages/web-pkg/src/components/Groupware/Accounts/AccountsSwitch.vue b/packages/web-pkg/src/components/Groupware/Accounts/AccountsSwitch.vue index 943c0380ca..5e600d48e8 100644 --- a/packages/web-pkg/src/components/Groupware/Accounts/AccountsSwitch.vue +++ b/packages/web-pkg/src/components/Groupware/Accounts/AccountsSwitch.vue @@ -7,7 +7,7 @@ justify-content="space-between" no-hover > - +
@@ -56,15 +56,12 @@