Skip to content

Commit

Permalink
chore: migrate the main store to pinia
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory Vodyanov <[email protected]>
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
GVodyanov authored and st3iny committed Jan 7, 2025
1 parent 272a9b8 commit 9dfd5c3
Show file tree
Hide file tree
Showing 81 changed files with 4,175 additions and 3,833 deletions.
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@nextcloud/paths": "^2.2.1",
"@nextcloud/router": "^3.0.1",
"@nextcloud/vue": "^8.20.0",
"@pinia/testing": "^0.1.6",
"@riophae/vue-treeselect": "^0.4.0",
"@vue/babel-preset-app": "^5.0.8",
"address-rfc2822": "^2.2.2",
Expand Down
18 changes: 11 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
</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'
import initAfterAppCreation from './init.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.getAccounts.find((account) => !account.isUnified)
},
},
watch: {
Expand All @@ -38,6 +41,7 @@ export default {
},
},
async mounted() {
initAfterAppCreation()
// Redirect to setup page if no accounts are configured
if (!this.hasMailAccounts) {
this.$router.replace({
Expand All @@ -46,9 +50,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 +61,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 @@ -112,6 +112,8 @@ import SearchSettings from './SearchSettings.vue'
import TrashRetentionSettings from './TrashRetentionSettings.vue'
import logger from '../logger.js'
import MailFilters from './mailFilter/MailFilters.vue'
import useMainStore from '../store/mainStore.js'
import { mapStores } from 'pinia'

export default {
name: 'AccountSettings',
Expand Down Expand Up @@ -148,6 +150,7 @@ export default {
}
},
computed: {
...mapStores(useMainStore),
displayName() {
return this.account.name
},
Expand All @@ -160,7 +163,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

0 comments on commit 9dfd5c3

Please sign in to comment.