Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate the main mail store to Pinia #10138

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
16 changes: 9 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
</template>

<script>
import { mapGetters } from 'vuex'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'

import logger from './logger.js'
import { matchError } from './errors/match.js'
import MailboxLockedError from './errors/MailboxLockedError.js'
import { mapStores, mapState } from 'pinia'
import useMainStore from './store/mainStore.js'

export default {
name: 'App',
computed: {
...mapGetters([
...mapStores(useMainStore),
...mapState(useMainStore, [
'isExpiredSession',
]),
hasMailAccounts() {
return !!this.$store.getters.accounts.find((account) => !account.isUnified)
return !!this.mainStore.accounts.find((account) => !account.isUnified)
},
},
watch: {
Expand All @@ -46,9 +48,9 @@ export default {
}

this.sync()
await this.$store.dispatch('fetchCurrentUserPrincipal')
await this.$store.dispatch('loadCollections')
this.$store.commit('hasCurrentUserPrincipalAndCollections', true)
await this.mainStore.fetchCurrentUserPrincipal()
await this.mainStore.loadCollections()
this.mainStore.hasCurrentUserPrincipalAndCollectionsMutation(true)
},
methods: {
reload() {
Expand All @@ -57,7 +59,7 @@ export default {
sync() {
setTimeout(async () => {
try {
await this.$store.dispatch('syncInboxes')
await this.mainStore.syncInboxes()

logger.debug("Inboxes sync'ed in background")
} catch (error) {
Expand Down
27 changes: 15 additions & 12 deletions src/components/AccountDefaultsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<script>
import logger from '../logger.js'
import MailboxInlinePicker from './MailboxInlinePicker.vue'
import { mapStores } from 'pinia'
import useMainStore from '../store/mainStore.js'

export default {
name: 'AccountDefaultsSettings',
Expand All @@ -59,9 +61,10 @@ export default {
}
},
computed: {
...mapStores(useMainStore),
draftsMailbox: {
get() {
const mb = this.$store.getters.getMailbox(this.account.draftsMailboxId)
const mb = this.mainStore.getMailbox(this.account.draftsMailboxId)
if (!mb) {
return
}
Expand All @@ -71,7 +74,7 @@ export default {
logger.debug('setting drafts mailbox to ' + draftsMailboxId)
this.saving = true
try {
await this.$store.dispatch('patchAccount', {
await this.mainStore.patchAccount({
account: this.account,
data: {
draftsMailboxId,
Expand All @@ -88,7 +91,7 @@ export default {
},
sentMailbox: {
get() {
const mb = this.$store.getters.getMailbox(this.account.sentMailboxId)
const mb = this.mainStore.getMailbox(this.account.sentMailboxId)
if (!mb) {
return
}
Expand All @@ -98,7 +101,7 @@ export default {
logger.debug('setting sent mailbox to ' + sentMailboxId)
this.saving = true
try {
await this.$store.dispatch('patchAccount', {
await this.mainStore.patchAccount({
account: this.account,
data: {
sentMailboxId,
Expand All @@ -115,7 +118,7 @@ export default {
},
trashMailbox: {
get() {
const mb = this.$store.getters.getMailbox(this.account.trashMailboxId)
const mb = this.mainStore.getMailbox(this.account.trashMailboxId)
if (!mb) {
return
}
Expand All @@ -125,7 +128,7 @@ export default {
logger.debug('setting trash mailbox to ' + trashMailboxId)
this.saving = true
try {
await this.$store.dispatch('patchAccount', {
await this.mainStore.patchAccount({
account: this.account,
data: {
trashMailboxId,
Expand All @@ -142,7 +145,7 @@ export default {
},
archiveMailbox: {
get() {
const mb = this.$store.getters.getMailbox(this.account.archiveMailboxId)
const mb = this.mainStore.getMailbox(this.account.archiveMailboxId)
if (!mb) {
return
}
Expand All @@ -152,7 +155,7 @@ export default {
logger.debug('setting archive mailbox to ' + archiveMailboxId)
this.saving = true
try {
await this.$store.dispatch('patchAccount', {
await this.mainStore.patchAccount({
account: this.account,
data: {
archiveMailboxId,
Expand All @@ -169,7 +172,7 @@ export default {
},
junkMailbox: {
get() {
const mb = this.$store.getters.getMailbox(this.account.junkMailboxId)
const mb = this.mainStore.getMailbox(this.account.junkMailboxId)
if (!mb) {
return
}
Expand All @@ -179,7 +182,7 @@ export default {
logger.debug('setting junk mailbox to ' + junkMailboxId)
this.saving = true
try {
await this.$store.dispatch('patchAccount', {
await this.mainStore.patchAccount({
account: this.account,
data: {
junkMailboxId,
Expand All @@ -196,7 +199,7 @@ export default {
},
snoozeMailbox: {
get() {
const mb = this.$store.getters.getMailbox(this.account.snoozeMailboxId)
const mb = this.mainStore.getMailbox(this.account.snoozeMailboxId)
if (!mb) {
return
}
Expand All @@ -206,7 +209,7 @@ export default {
logger.debug('setting snooze mailbox to ' + snoozeMailboxId)
this.saving = true
try {
await this.$store.dispatch('patchAccount', {
await this.mainStore.patchAccount({
account: this.account,
data: {
snoozeMailboxId,
Expand Down
16 changes: 9 additions & 7 deletions src/components/AccountForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@

<script>
import { Tab, Tabs } from 'vue-tabs-component'
import { mapGetters } from 'vuex'
import { NcButton as ButtonVue, NcLoadingIcon as IconLoading, NcPasswordField, NcInputField, NcCheckboxRadioSwitch } from '@nextcloud/vue'
import IconCheck from 'vue-material-design-icons/Check.vue'
import { translate as t } from '@nextcloud/l10n'
Expand All @@ -251,6 +250,8 @@ import {
testConnectivity,
} from '../service/AutoConfigService.js'
import { CONSENT_ABORTED, getUserConsent } from '../integration/oauth.js'
import useMainStore from '../store/mainStore.js'
import { mapStores, mapState } from 'pinia'

export default {
name: 'AccountForm',
Expand Down Expand Up @@ -314,7 +315,8 @@ export default {
}
},
computed: {
...mapGetters([
...mapStores(useMainStore),
...mapState(useMainStore, [
'googleOauthUrl',
'microsoftOauthUrl',
]),
Expand Down Expand Up @@ -563,7 +565,7 @@ export default {
delete data.smtpPassword
}
if (!this.account) {
const account = await this.$store.dispatch('startAccountSetup', data)
const account = await this.mainStore.startAccountSetup(data)
if (this.useOauth) {
this.loadingMessage = t('mail', 'Awaiting user consent')
try {
Expand All @@ -584,18 +586,18 @@ export default {
}
} catch (e) {
// Clean up the temporary account before we continue
this.$store.dispatch('deleteAccount', account)
this.mainStore.deleteAccount(account)
logger.info(`Temporary account ${account.id} deleted`)
throw e
}
this.clearFeedback()
}
this.loadingMessage = t('mail', 'Loading account')
await this.$store.dispatch('finishAccountSetup', { account })
await this.mainStore.finishAccountSetup({ account })
this.$emit('account-created', account)
} else {
const oldAccountData = this.account
const account = await this.$store.dispatch('updateAccount', {
const account = await this.mainStore.updateAccount({
...data,
accountId: this.account.id,
})
Expand All @@ -619,7 +621,7 @@ export default {
}
} catch (e) {
// Undo changes
await this.$store.dispatch('updateAccount', {
await this.mainStore.updateAccount({
...oldAccountData,
accountId: oldAccountData.id,
})
Expand Down
5 changes: 4 additions & 1 deletion src/components/AccountSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ import CertificateSettings from './CertificateSettings.vue'
import SearchSettings from './SearchSettings.vue'
import TrashRetentionSettings from './TrashRetentionSettings.vue'
import logger from '../logger.js'
import useMainStore from '../store/mainStore.js'
import { mapStores } from 'pinia'

export default {
name: 'AccountSettings',
Expand Down Expand Up @@ -139,6 +141,7 @@ export default {
}
},
computed: {
...mapStores(useMainStore),
displayName() {
return this.account.name
},
Expand All @@ -151,7 +154,7 @@ export default {
if (newState === true && this.fetchActiveSieveScript === true) {
logger.debug(`Load active sieve script for account ${this.account.accountId}`)
this.fetchActiveSieveScript = false
this.$store.dispatch('fetchActiveSieveScript', {
this.mainStore.fetchActiveSieveScript({
accountId: this.account.id,
})
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/AliasSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import IconCheck from 'vue-material-design-icons/Check.vue'
import IconRename from 'vue-material-design-icons/Pencil.vue'
import logger from '../logger.js'
import AliasForm from './AliasForm.vue'
import useMainStore from '../store/mainStore.js'
import { mapStores } from 'pinia'

export default {
name: 'AliasSettings',
Expand All @@ -108,6 +110,7 @@ export default {
}
},
computed: {
...mapStores(useMainStore),
aliases() {
return this.account.aliases
},
Expand All @@ -124,7 +127,7 @@ export default {
async createAlias() {
this.loading = true

await this.$store.dispatch('createAlias', {
await this.mainStore.createAlias({
account: this.account,
alias: this.newAlias,
name: this.newName,
Expand All @@ -147,7 +150,7 @@ export default {

async updateAlias(aliasId, newAlias) {
const alias = this.aliases.find((alias) => alias.id === aliasId)
await this.$store.dispatch('updateAlias', {
await this.mainStore.updateAlias({
account: this.account,
aliasId: alias.id,
alias: newAlias.alias,
Expand All @@ -156,7 +159,7 @@ export default {
})
},
async deleteAlias(aliasId) {
await this.$store.dispatch('deleteAlias', {
await this.mainStore.deleteAlias({
account: this.account,
aliasId,
})
Expand Down
Loading
Loading