From f22aed65225a9540c9f541a5b1b882cb361051d0 Mon Sep 17 00:00:00 2001 From: Grigory V Date: Wed, 18 Sep 2024 17:46:34 +0200 Subject: [PATCH] chore: a little more bugfixing and move state back into main file, didn't work if not Signed-off-by: Grigory V --- src/components/AppSettingsMenu.vue | 1 + src/components/NewMessageModal.vue | 5 +- src/store/mainStore.js | 95 ++++++++++++++++++++++++++++-- src/store/mainStore/actions.js | 4 +- src/store/mainStore/getters.js | 5 +- src/store/mainStore/state.js | 95 ------------------------------ 6 files changed, 98 insertions(+), 107 deletions(-) delete mode 100644 src/store/mainStore/state.js diff --git a/src/components/AppSettingsMenu.vue b/src/components/AppSettingsMenu.vue index e77d2601a1..8ced436f35 100755 --- a/src/components/AppSettingsMenu.vue +++ b/src/components/AppSettingsMenu.vue @@ -367,6 +367,7 @@ export default { } }, computed: { + ...mapStores(useMainStore), ...mapState(useMainStore, ['accounts', 'isFollowUpFeatureAvailable']), searchPriorityBody() { return this.mainStore.getPreference('search-priority-body', 'false') === 'true' diff --git a/src/components/NewMessageModal.vue b/src/components/NewMessageModal.vue index f5c33bc0cc..4a84cd4ee8 100644 --- a/src/components/NewMessageModal.vue +++ b/src/components/NewMessageModal.vue @@ -137,7 +137,7 @@ import DefaultComposerIcon from 'vue-material-design-icons/ArrowCollapse.vue' import { deleteDraft, saveDraft, updateDraft } from '../service/DraftService.js' import useOutboxStore from '../store/outboxStore.js' import useMainStore from '../store/mainStore.js' -import { mapStores, mapState } from 'pinia' +import { mapStores, mapState, mapActions } from 'pinia' export default { name: 'NewMessageModal', @@ -178,7 +178,8 @@ export default { }, computed: { ...mapStores(useOutboxStore, useMainStore), - ...mapState(useMainStore, ['showMessageComposer', 'getPreference']), + ...mapState(useMainStore, ['showMessageComposer']), + ...mapActions(useMainStore, ['getPreference']), modalTitle() { if (this.composerMessage.type === 'outbox') { return t('mail', 'Edit message') diff --git a/src/store/mainStore.js b/src/store/mainStore.js index 5f0f2b27be..0c6449c24f 100644 --- a/src/store/mainStore.js +++ b/src/store/mainStore.js @@ -3,18 +3,105 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import { defineStore } from 'pinia' -import mapStoreState from './mainStore/state.js' import mapStoreGetters from './mainStore/getters.js' import mapStoreActions from './mainStore/actions.js' +import { FOLLOW_UP_MAILBOX_ID, PRIORITY_INBOX_ID, UNIFIED_ACCOUNT_ID, UNIFIED_INBOX_ID } from './constants' export default defineStore('main', { - state: mapStoreState(), + state: () => { + return { + isExpiredSession: false, + preferences: {}, + accountsUnmapped: { + [UNIFIED_ACCOUNT_ID]: { + id: UNIFIED_ACCOUNT_ID, + accountId: UNIFIED_ACCOUNT_ID, + isUnified: true, + mailboxes: [PRIORITY_INBOX_ID, UNIFIED_INBOX_ID, FOLLOW_UP_MAILBOX_ID], + aliases: [], + collapsed: false, + emailAddress: '', + name: '', + showSubscribedOnly: false, + signatureAboveQuote: false, + }, + }, + accountList: [UNIFIED_ACCOUNT_ID], + allAccountSettings: [], + mailboxes: { + [UNIFIED_INBOX_ID]: { + id: UNIFIED_INBOX_ID, + databaseId: UNIFIED_INBOX_ID, + accountId: 0, + attributes: ['\\subscribed'], + isUnified: true, + path: '', + specialUse: ['inbox'], + specialRole: 'inbox', + unread: 0, + mailboxes: [], + envelopeLists: {}, + name: 'UNIFIED INBOX', + }, + [PRIORITY_INBOX_ID]: { + id: PRIORITY_INBOX_ID, + databaseId: PRIORITY_INBOX_ID, + accountId: 0, + attributes: ['\\subscribed'], + isPriorityInbox: true, + path: '', + specialUse: ['inbox'], + specialRole: 'inbox', + unread: 0, + mailboxes: [], + envelopeLists: {}, + name: 'PRIORITY INBOX', + }, + [FOLLOW_UP_MAILBOX_ID]: { + id: FOLLOW_UP_MAILBOX_ID, + databaseId: FOLLOW_UP_MAILBOX_ID, + accountId: 0, + attributes: ['\\subscribed'], + isUnified: true, + path: '', + specialUse: ['sent'], + specialRole: 'sent', + unread: 0, + mailboxes: [], + envelopeLists: {}, + name: 'FOLLOW UP REMINDERS', + }, + }, + envelopes: {}, + messages: {}, + newMessage: undefined, + showMessageComposer: false, + composerMessageIsSaved: false, + composerSessionId: undefined, + nextComposerSessionId: 1, + autocompleteEntries: [], + tags: {}, + tagList: [], + isScheduledSendingDisabled: false, + isSnoozeDisabled: false, + currentUserPrincipal: undefined, + googleOauthUrl: null, + masterPasswordEnabled: false, + sieveScript: {}, + calendars: [], + smimeCertificates: [], + hasFetchedInitialEnvelopes: false, + followUpFeatureAvailable: false, + internalAddress: [], + hasCurrentUserPrincipalAndCollections: false, + showAccountSettings: null, + } + }, getters: { ...mapStoreGetters(), }, actions: { ...mapStoreActions(), }, -}); +}) diff --git a/src/store/mainStore/actions.js b/src/store/mainStore/actions.js index 389e27045e..64cc48dd17 100644 --- a/src/store/mainStore/actions.js +++ b/src/store/mainStore/actions.js @@ -142,7 +142,7 @@ const addMailboxToState = curry((store, account, mailbox) => { mailbox.mailboxes = [] Vue.set(mailbox, 'envelopeLists', {}) - transformMailboxName(account, mailbox) + mainStoreActions().transformMailboxName(account, mailbox) Vue.set(store.mailboxes, mailbox.databaseId, mailbox) const parent = Object.values(store.mailboxes) @@ -1823,7 +1823,7 @@ export default function mainStoreActions() { }, savePreferenceMutation({ key, - value + value, }) { Vue.set(this.preferences, key, value) }, diff --git a/src/store/mainStore/getters.js b/src/store/mainStore/getters.js index f8af359584..e1ba4f5b4d 100644 --- a/src/store/mainStore/getters.js +++ b/src/store/mainStore/getters.js @@ -11,7 +11,7 @@ import toCalendar from '../../util/calendar.js' export default function mainStore() { return { accounts: (state) => { - return state.accountList.map((id) => state.accounts[id]) + return state.accountList.map((id) => state.accountsUnmapped[id]) }, composerMessage: (state) => { return state.newMessage @@ -60,9 +60,6 @@ export default function mainStore() { getAppVersion: (state) => state.preferences?.version, isOneLineLayout: (state) => state.list, - hasFetchedInitialEnvelopes: (state) => state.hasFetchedInitialEnvelopes, - isFollowUpFeatureAvailable: (state) => state.followUpFeatureAvailable, getInternalAddresses: (state) => state.internalAddress?.filter(internalAddress => internalAddress !== undefined), - hasCurrentUserPrincipalAndCollections: (state) => state.hasCurrentUserPrincipalAndCollections, } } diff --git a/src/store/mainStore/state.js b/src/store/mainStore/state.js deleted file mode 100644 index 62acaf389d..0000000000 --- a/src/store/mainStore/state.js +++ /dev/null @@ -1,95 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { FOLLOW_UP_MAILBOX_ID, PRIORITY_INBOX_ID, UNIFIED_ACCOUNT_ID, UNIFIED_INBOX_ID } from '../constants.js' - -export default function mainStoreState() { - return { - isExpiredSession: false, - preferences: {}, - accounts: { - [UNIFIED_ACCOUNT_ID]: { - id: UNIFIED_ACCOUNT_ID, - accountId: UNIFIED_ACCOUNT_ID, - isUnified: true, - mailboxes: [PRIORITY_INBOX_ID, UNIFIED_INBOX_ID, FOLLOW_UP_MAILBOX_ID], - aliases: [], - collapsed: false, - emailAddress: '', - name: '', - showSubscribedOnly: false, - signatureAboveQuote: false, - }, - }, - accountList: [UNIFIED_ACCOUNT_ID], - allAccountSettings: [], - mailboxes: { - [UNIFIED_INBOX_ID]: { - id: UNIFIED_INBOX_ID, - databaseId: UNIFIED_INBOX_ID, - accountId: 0, - attributes: ['\\subscribed'], - isUnified: true, - path: '', - specialUse: ['inbox'], - specialRole: 'inbox', - unread: 0, - mailboxes: [], - envelopeLists: {}, - name: 'UNIFIED INBOX', - }, - [PRIORITY_INBOX_ID]: { - id: PRIORITY_INBOX_ID, - databaseId: PRIORITY_INBOX_ID, - accountId: 0, - attributes: ['\\subscribed'], - isPriorityInbox: true, - path: '', - specialUse: ['inbox'], - specialRole: 'inbox', - unread: 0, - mailboxes: [], - envelopeLists: {}, - name: 'PRIORITY INBOX', - }, - [FOLLOW_UP_MAILBOX_ID]: { - id: FOLLOW_UP_MAILBOX_ID, - databaseId: FOLLOW_UP_MAILBOX_ID, - accountId: 0, - attributes: ['\\subscribed'], - isUnified: true, - path: '', - specialUse: ['sent'], - specialRole: 'sent', - unread: 0, - mailboxes: [], - envelopeLists: {}, - name: 'FOLLOW UP REMINDERS', - }, - }, - envelopes: {}, - messages: {}, - newMessage: undefined, - showMessageComposer: false, - composerMessageIsSaved: false, - composerSessionId: undefined, - nextComposerSessionId: 1, - autocompleteEntries: [], - tags: {}, - tagList: [], - isScheduledSendingDisabled: false, - isSnoozeDisabled: false, - currentUserPrincipal: undefined, - googleOauthUrl: null, - masterPasswordEnabled: false, - sieveScript: {}, - calendars: [], - smimeCertificates: [], - hasFetchedInitialEnvelopes: false, - followUpFeatureAvailable: false, - internalAddress: [], - hasCurrentUserPrincipalAndCollections: false, - showAccountSettings: null, - } -}