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
>
-