Skip to content

Commit

Permalink
chore: migrate all getters of the main store
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory V <[email protected]>
  • Loading branch information
GVodyanov committed Sep 16, 2024
1 parent 8110385 commit 2f34aa3
Show file tree
Hide file tree
Showing 30 changed files with 210 additions and 135 deletions.
8 changes: 5 additions & 3 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 Down
15 changes: 9 additions & 6 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 Down
29 changes: 13 additions & 16 deletions src/components/AppSettingsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ import TrustedSenders from './TrustedSenders.vue'
import InternalAddress from './InternalAddress.vue'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
import { mapGetters } from 'vuex'

Check failure on line 315 in src/components/AppSettingsMenu.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'mapGetters' is defined but never used
import useMainStore from '../store/mainStore.js'
import { mapStores, mapState } from 'pinia'

Check failure on line 317 in src/components/AppSettingsMenu.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'mapStores' is defined but never used
export default {
name: 'AppSettingsMenu',
Expand Down Expand Up @@ -366,38 +368,33 @@ export default {
}
},
computed: {
...mapGetters([
'isFollowUpFeatureAvailable',
]),
...mapGetters({
accounts: 'accounts',
}),
...mapState(useMainStore, ['accounts', 'isFollowUpFeatureAvailable']),
searchPriorityBody() {
return this.$store.getters.getPreference('search-priority-body', 'false') === 'true'
return this.mainStore.getPreference('search-priority-body', 'false') === 'true'
},
useBottomReplies() {
return this.$store.getters.getPreference('reply-mode', 'top') === 'bottom'
return this.mainStore.getPreference('reply-mode', 'top') === 'bottom'
},
useExternalAvatars() {
return this.$store.getters.getPreference('external-avatars', 'true') === 'true'
return this.mainStore.getPreference('external-avatars', 'true') === 'true'
},
useDataCollection() {
return this.$store.getters.getPreference('collect-data', 'true') === 'true'
return this.mainStore.getPreference('collect-data', 'true') === 'true'
},
useAutoTagging() {
return this.$store.getters.getPreference('tag-classified-messages', 'true') === 'true'
return this.mainStore.getPreference('tag-classified-messages', 'true') === 'true'
},
useInternalAddresses() {
return this.$store.getters.getPreference('internal-addresses', 'false') === 'true'
return this.mainStore.getPreference('internal-addresses', 'false') === 'true'
},
useFollowUpReminders() {
return this.$store.getters.getPreference('follow-up-reminders', 'true') === 'true'
return this.mainStore.getPreference('follow-up-reminders', 'true') === 'true'
},
allowNewMailAccounts() {
return this.$store.getters.getPreference('allow-new-accounts', true)
return this.mainStore.getPreference('allow-new-accounts', true)
},
layoutMode() {
return this.$store.getters.getPreference('layout-mode', 'vertical-split')
return this.mainStore.getPreference('layout-mode', 'vertical-split')
},
},
watch: {
Expand All @@ -413,7 +410,7 @@ export default {
},
},
mounted() {
this.sortOrder = this.$store.getters.getPreference('sort-order', 'newest')
this.sortOrder = this.mainStore.getPreference('sort-order', 'newest')
document.addEventListener.call(window, 'mailvelope', () => this.checkMailvelope())
},
updated() {
Expand Down
24 changes: 12 additions & 12 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,10 @@ import { NcReferencePickerModal } from '@nextcloud/vue/dist/Components/NcRichTex
import Send from 'vue-material-design-icons/Send.vue'
import SendClock from 'vue-material-design-icons/SendClock.vue'
import moment from '@nextcloud/moment'
import { mapGetters } from 'vuex'
import { TRIGGER_CHANGE_ALIAS, TRIGGER_EDITOR_READY } from '../ckeditor/signature/InsertSignatureCommand.js'
import { EDITOR_MODE_HTML, EDITOR_MODE_TEXT } from '../store/constants.js'
import useMainStore from '../store/mainStore.js'
import { mapStores, mapState } from 'pinia'
const debouncedSearch = debouncePromise(findRecipient, 500)
Expand Down Expand Up @@ -693,11 +694,10 @@ export default {
}
},
computed: {
...mapGetters([
'isScheduledSendingDisabled',
]),
...mapStores(useMainStore),
...mapState(useMainStore, ['isScheduledSendingDisabled']),
isPickerAvailable() {
return parseInt(this.$store.getters.getNcVersion) >= 26
return parseInt(this.mainStore.getNcVersion) >= 26
},
aliases() {
let cnt = 0
Expand Down Expand Up @@ -739,7 +739,7 @@ export default {
return new Date(new Date().setDate(new Date().getDate()))
},
attachmentSizeLimit() {
return this.$store.getters.getPreference('attachment-size-limit')
return this.mainStore.getPreference('attachment-size-limit')
},
selectableRecipients() {
return uniqBy('email')(this.newRecipients
Expand Down Expand Up @@ -880,7 +880,7 @@ export default {
const missingCertificates = []
this.allRecipients.forEach((recipient) => {
const recipientCertificate = this.$store.getters.getSmimeCertificateByEmail(recipient.email)
const recipientCertificate = this.mainStore.getSmimeCertificateByEmail(recipient.email)
if (!recipientCertificate) {
missingCertificates.push(recipient.email)
}
Expand Down Expand Up @@ -967,7 +967,7 @@ export default {
// Add messages forwarded as attachments
for (const id of this.forwardedMessages) {
const env = this.$store.getters.getEnvelope(id)
const env = this.mainStore.getEnvelope(id)
if (!env) {
// TODO: also happens when the composer page is reloaded
showError(t('mail', 'Message {id} could not be found', {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ export default {
return alias.id === this.fromAccount && !alias.aliasId
})
} else {
const currentAccountId = this.$store.getters.getMailbox(this.$route.params.mailboxId)?.accountId
const currentAccountId = this.mainStore.getMailbox(this.$route.params.mailboxId)?.accountId
if (currentAccountId) {
this.selectedAlias = this.aliases.find((alias) => {
return alias.id === currentAccountId
Expand Down Expand Up @@ -1063,14 +1063,14 @@ export default {
this.editorPlainText ? toPlain(this.body) : toHtml(this.body),
this.replyTo.from[0],
this.replyTo.dateInt,
this.$store.getters.getPreference('reply-mode', 'top') === 'top',
this.mainStore.getPreference('reply-mode', 'top') === 'top',
).value
} else if (this.forwardFrom && this.isFirstOpen) {
body = buildReplyBody(
this.editorPlainText ? toPlain(this.body) : toHtml(this.body),
this.forwardFrom.from[0],
this.forwardFrom.dateInt,
this.$store.getters.getPreference('reply-mode', 'top') === 'top',
this.mainStore.getPreference('reply-mode', 'top') === 'top',
).value
} else {
body = this.bodyVal
Expand Down Expand Up @@ -1405,7 +1405,7 @@ export default {
if (!certificateId) {
return undefined
}
return this.$store.getters.getSmimeCertificate(certificateId)
return this.mainStore.getSmimeCertificate(certificateId)
},
/**
Expand Down
16 changes: 9 additions & 7 deletions src/components/Envelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ import DownloadIcon from 'vue-material-design-icons/Download.vue'
import CalendarClock from 'vue-material-design-icons/CalendarClock.vue'
import AlarmIcon from 'vue-material-design-icons/Alarm.vue'
import moment from '@nextcloud/moment'
import { mapGetters } from 'vuex'
import { mapState, mapStores } from 'pinia'
import useMainStore from '../store/mainStore.js'
import { FOLLOW_UP_TAG_LABEL } from '../store/constants.js'
import { translateTagDisplayName } from '../util/tag.js'
Expand Down Expand Up @@ -483,14 +484,15 @@ export default {
window.addEventListener('resize', this.onWindowResize)
},
computed: {

Check warning on line 486 in src/components/Envelope.vue

View workflow job for this annotation

GitHub Actions / NPM lint

The "computed" property should be above the "mounted" property on line 481
...mapGetters([
...mapStores(useMainStore),
...mapState(useMainStore, [
'isSnoozeDisabled',
]),
messageLongDate() {
return messageDateTime(new Date(this.data.dateInt))
},
oneLineLayout() {
return this.overwriteOneLineMobile ? false : this.$store.getters.getPreference('layout-mode', 'vertical-split') === 'no-split'
return this.overwriteOneLineMobile ? false : this.mainStore.getPreference('layout-mode', 'vertical-split') === 'no-split'
},
hasMultipleRecipients() {
if (!this.account) {
Expand All @@ -509,7 +511,7 @@ export default {
},
account() {
const accountId = this.data.accountId
return this.$store.getters.getAccount(accountId)
return this.mainStore.getAccount(accountId)
},
link() {
if (this.draft) {
Expand Down Expand Up @@ -570,12 +572,12 @@ export default {
|| (this.data.previewText && isPgpText(this.data.previewText)) // PGP/Mailvelope
},
isImportant() {
return this.$store.getters
return this.mainStore
.getEnvelopeTags(this.data.databaseId)
.some((tag) => tag.imapLabel === '$label1')
},
tags() {
let tags = this.$store.getters.getEnvelopeTags(this.data.databaseId).filter(
let tags = this.mainStore.getEnvelopeTags(this.data.databaseId).filter(
(tag) => tag.imapLabel && tag.imapLabel !== '$label1' && !(tag.displayName.toLowerCase() in hiddenTags),
)
Expand Down Expand Up @@ -637,7 +639,7 @@ export default {
return mailboxHasRights(this.mailbox, 'w')
},
archiveMailbox() {
return this.$store.getters.getMailbox(this.account.archiveMailboxId)
return this.mainStore.getMailbox(this.account.archiveMailboxId)
},
isSnoozedMailbox() {
return this.mailbox.databaseId === this.account.snoozeMailboxId
Expand Down
9 changes: 6 additions & 3 deletions src/components/EnvelopeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ import ShareIcon from 'vue-material-design-icons/Share.vue'
import AlertOctagonIcon from 'vue-material-design-icons/AlertOctagon.vue'
import TagIcon from 'vue-material-design-icons/Tag.vue'
import TagModal from './TagModal.vue'
import useMainStore from '../store/mainStore.js'
import { mapStores } from 'pinia'
export default {
name: 'EnvelopeList',
Expand Down Expand Up @@ -328,8 +330,9 @@ export default {
}
},
computed: {
...mapStores(useMainStore),
sortOrder() {
return this.$store.getters.getPreference('sort-order', 'newest')
return this.mainStore.getPreference('sort-order', 'newest')
},
sortedEnvelops() {
Expand All @@ -351,15 +354,15 @@ export default {
isAtLeastOneSelectedImportant() {
// returns true if at least one selected message is marked as important
return this.selectedEnvelopes.some((env) => {
return this.$store.getters
return this.mainStore
.getEnvelopeTags(env.databaseId)
.some((tag) => tag.imapLabel === '$label1')
})
},
isAtLeastOneSelectedUnimportant() {
// returns true if at least one selected message is not marked as important
return this.selectedEnvelopes.some((env) => {
return !this.$store.getters
return !this.mainStore
.getEnvelopeTags(env.databaseId)
.some((tag) => tag.imapLabel === '$label1')
})
Expand Down
5 changes: 4 additions & 1 deletion src/components/InternalAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import IconCancel from '@mdi/svg/svg/cancel.svg'
import IconCheck from '@mdi/svg/svg/check.svg'
import logger from '../logger.js'
import { showError } from '@nextcloud/dialogs'
import { mapStores } from 'pinia'
import useMainStore from '../store/mainStore.js'
const sortByAddress = sortBy(prop('address'))
Expand Down Expand Up @@ -91,8 +93,9 @@ export default {
}
},
computed: {
...mapStores(useMainStore),
list() {
return this.$store.getters.getInternalAddresses
return this.mainStore.getInternalAddresses
},
sortedDomains() {
return sortByAddress(this.list.filter(a => a.type === 'domain'))
Expand Down
Loading

0 comments on commit 2f34aa3

Please sign in to comment.