diff options
author | Johannes Brückner <johannes@dotplex.com> | 2020-11-02 15:15:12 +0300 |
---|---|---|
committer | Johannes Brückner <johannes@dotplex.com> | 2020-11-10 11:59:20 +0300 |
commit | aa274e8451f3a55839f1c23799cd11f5d9491c33 (patch) | |
tree | 90ad5644e2732c932a7936e86a48cedf33c60035 /src | |
parent | 156573989ff58c7ce3de85b3dd12ef20f5f80a2b (diff) |
Store collapsed-folder settings in abstracted account settings
Signed-off-by: Johannes Brückner <johannes@dotplex.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/NavigationAccountExpandCollapse.vue | 18 | ||||
-rw-r--r-- | src/main.js | 14 | ||||
-rw-r--r-- | src/store/actions.js | 5 | ||||
-rw-r--r-- | src/store/getters.js | 3 | ||||
-rw-r--r-- | src/store/index.js | 1 | ||||
-rw-r--r-- | src/store/mutations.js | 12 |
6 files changed, 49 insertions, 4 deletions
diff --git a/src/components/NavigationAccountExpandCollapse.vue b/src/components/NavigationAccountExpandCollapse.vue index 233a80d94..6ac1e7b1a 100644 --- a/src/components/NavigationAccountExpandCollapse.vue +++ b/src/components/NavigationAccountExpandCollapse.vue @@ -25,6 +25,7 @@ <script> import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem' +import logger from '../logger' export default { name: 'NavigationAccountExpandCollapse', @@ -51,8 +52,21 @@ export default { }, }, methods: { - toggleCollapse() { - this.$store.commit('toggleAccountCollapsed', this.account.id) + async toggleCollapse() { + logger.debug('toggling collapsed folders for account ' + this.account.id) + try { + await this.$store.commit('toggleAccountCollapsed', this.account.id) + await this.$store + .dispatch('setAccountSetting', { + accountId: this.account.id, + key: 'collapsed', + value: this.account.collapsed, + }) + } catch (error) { + logger.error('could not update account settings', { + error, + }) + } }, }, } diff --git a/src/main.js b/src/main.js index 005c2e161..018906c26 100644 --- a/src/main.js +++ b/src/main.js @@ -72,9 +72,21 @@ store.commit('savePreference', { value: getPreferenceFromPage('collect-data'), }) +const accountSettings = JSON.parse(Base64.decode(getPreferenceFromPage('account-settings'))) const accounts = JSON.parse(Base64.decode(getPreferenceFromPage('serialized-accounts'))) accounts.map(fixAccountId).forEach((account) => { - store.commit('addAccount', account) + const settings = accountSettings.find(settings => settings.accountId === account.id) + if (settings) { + delete settings.accountId + Object.entries(settings).forEach(([key, value]) => { + store.commit('setAccountSetting', { + accountId: account.id, + key, + value, + }) + }) + } + store.commit('addAccount', { ...account, ...settings }) }) export default new Vue({ diff --git a/src/store/actions.js b/src/store/actions.js index daf53db77..85ab40fa1 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -148,6 +148,10 @@ export default { return account }) }, + setAccountSetting({ commit, getters }, { accountId, key, value }) { + commit('setAccountSetting', { accountId, key, value }) + return savePreference('account-settings', JSON.stringify(getters.getAllAccountSettings)) + }, deleteAccount({ commit }, account) { return deleteAccount(account.id).catch((err) => { console.error('could not delete account', err) @@ -166,6 +170,7 @@ export default { console.debug(`mailbox ${prefixed} created for account ${account.id}`, { mailbox }) commit('addMailbox', { account, mailbox }) commit('expandAccount', account.id) + commit('setAccountSetting', { accountId: account.id, key: 'collapsed', value: false }) return mailbox }, moveAccount({ commit, getters }, { account, up }) { diff --git a/src/store/getters.js b/src/store/getters.js index 99bb27e3c..3b75c5699 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -31,6 +31,9 @@ export const getters = { getAccount: (state) => (id) => { return state.accounts[id] }, + getAllAccountSettings: (state) => { + return state.allAccountSettings + }, accounts: (state) => { return state.accountList.map((id) => state.accounts[id]) }, diff --git a/src/store/index.js b/src/store/index.js index 224dcf24b..101b76abf 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -50,6 +50,7 @@ export default new Vuex.Store({ }, }, accountList: [UNIFIED_ACCOUNT_ID], + allAccountSettings: [], mailboxes: { [UNIFIED_INBOX_ID]: { id: UNIFIED_INBOX_ID, diff --git a/src/store/mutations.js b/src/store/mutations.js index 54960fe00..7970046e3 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -77,7 +77,7 @@ export default { Vue.set(state.preferences, key, value) }, addAccount(state, account) { - account.collapsed = true + account.collapsed = account.collapsed ?? true Vue.set(state.accounts, account.id, account) Vue.set( state, @@ -110,6 +110,16 @@ export default { expandAccount(state, accountId) { state.accounts[accountId].collapsed = false }, + setAccountSetting(state, { accountId, key, value }) { + const accountSettings = state.allAccountSettings.find(settings => settings.accountId === accountId) + if (accountSettings) { + accountSettings[key] = value + } else { + const newAccountSettings = { accountId } + newAccountSettings[key] = value + state.allAccountSettings.push(newAccountSettings) + } + }, addMailbox(state, { account, mailbox }) { addMailboxToState(state, account, mailbox) }, |