From 73f8e7087cb0f8d36bf75ec4c131b0c5c3779a0c Mon Sep 17 00:00:00 2001 From: GretaD Date: Thu, 27 Aug 2020 19:40:20 +0200 Subject: [PATCH] fixup! Add rename mailbox option Signed-off-by: GretaD --- src/components/NavigationFolder.vue | 331 --------------------------- src/components/NavigationMailbox.vue | 46 +++- src/service/FolderService.js | 51 ----- src/service/MailboxService.js | 9 + src/store/actions.js | 10 +- src/store/mutations.js | 12 +- 6 files changed, 66 insertions(+), 393 deletions(-) delete mode 100644 src/components/NavigationFolder.vue delete mode 100644 src/service/FolderService.js diff --git a/src/components/NavigationFolder.vue b/src/components/NavigationFolder.vue deleted file mode 100644 index 932689a5ce..0000000000 --- a/src/components/NavigationFolder.vue +++ /dev/null @@ -1,331 +0,0 @@ - - - - - diff --git a/src/components/NavigationMailbox.vue b/src/components/NavigationMailbox.vue index feb25b35f3..17230b58bf 100644 --- a/src/components/NavigationMailbox.vue +++ b/src/components/NavigationMailbox.vue @@ -50,7 +50,6 @@ @click="markAsRead"> {{ t('mail', 'Mark all messages of this mailbox as read') }} - + + {{ t('mail', 'Saving') }} + + {{ t('mail', 'Edit name') }} + + {{ t('mail', 'Saving') }} @@ -101,6 +113,7 @@ import { getMailboxStatus } from '../service/MailboxService' import logger from '../logger' import { translatePlural as n } from '@nextcloud/l10n' import { translate as translateMailboxName } from '../i18n/MailboxTranslator' +import { showInfo } from '@nextcloud/dialogs' export default { name: 'NavigationMailbox', @@ -140,6 +153,9 @@ export default { editing: false, showSubMailboxes: false, menuOpen: false, + renameLabel: true, + renameInput: false, + } }, computed: { @@ -317,6 +333,34 @@ export default { } ) }, + async renameMailbox(event) { + this.renameInput = false + this.showSaving = true + + const newName = event.target.querySelector('input[type=text]').value + try { + await this.$store.dispatch('renameMailbox', { + account: this.account, + mailbox: this.mailbox, + newName, + }) + this.renameLabel = true + this.renameInput = false + this.showSaving = false + } catch (error) { + showInfo(t('mail', 'An error occurred, unable to rename the folder.')) + console.error(error) + this.renameLabel = false + this.renameInput = true + this.showSaving = false + } + }, + openRenameInput() { + // Hide label and show input + this.renameLabel = false + this.renameInput = true + this.showSaving = false + }, }, } diff --git a/src/service/FolderService.js b/src/service/FolderService.js deleted file mode 100644 index 3a3289f931..0000000000 --- a/src/service/FolderService.js +++ /dev/null @@ -1,51 +0,0 @@ -import {generateUrl} from '@nextcloud/router' -import Axios from '@nextcloud/axios' - -export function fetchAll(accountId) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders', { - accountId, - }) - - // FIXME: this return format is weird and should be avoided - // TODO: respect `resp.data.delimiter` value - return Axios.get(url).then((resp) => resp.data.folders) -} - -export function create(accountId, name) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders', { - accountId, - }) - - const data = { - name, - } - return Axios.post(url, data).then((resp) => resp.data) -} - -export function getFolderStats(accountId, folderId) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/stats', { - accountId, - folderId, - }) - - return Axios.get(url).then((resp) => resp.data) -} - -export function markFolderRead(accountId, folderId) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/read', { - accountId, - folderId, - }) - - return Axios.post(url).then((resp) => resp.data) -} - -export async function patchFolder(accountId, folderId, data) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}', { - accountId, - folderId, - }) - - const response = await Axios.patch(url, data) - return response.data.data -} diff --git a/src/service/MailboxService.js b/src/service/MailboxService.js index 0b0e38c4ed..e895d24fc0 100644 --- a/src/service/MailboxService.js +++ b/src/service/MailboxService.js @@ -46,3 +46,12 @@ export const deleteMailbox = async(id) => { await axios.delete(url) } +export async function patchMailbox(accountId, mailboxId, data) { + const url = generateUrl('/apps/mail/api/accounts/{accountId}/mailboxes/{mailboxId}', { + accountId, + mailboxId, + }) + + const response = await axios.patch(url, data) + return response.data.data +} diff --git a/src/store/actions.js b/src/store/actions.js index 659e0b9463..8f04e53b26 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -55,6 +55,7 @@ import { deleteMailbox, fetchAll as fetchAllMailboxes, markMailboxRead, + patchMailbox, } from '../service/MailboxService' import { deleteMessage, @@ -669,12 +670,13 @@ export default { async deleteAlias({ commit }, { account, aliasToDelete }) { await deleteAlias(account, aliasToDelete) commit('deleteAlias', { account, alias: aliasToDelete }) - async renameFolder({commit}, {account, folder, newName}) { - await patchFolder(account.id, folder.id, { + }, + async renameMailbox({ commit }, { account, mailbox, newName }) { + await patchMailbox(account.id, mailbox.id, { name: newName, }) - console.debug(`folder ${folder.id} renamed to ${newName}`, {folder}) - commit('renameFolder', {accountId: account.id, folder, newName}) + console.debug(`folder ${mailbox.id} renamed to ${newName}`, { mailbox }) + commit('renameMailbox', { accountId: account.id, mailbox, newName }) }, } diff --git a/src/store/mutations.js b/src/store/mutations.js index 38d764a915..6d5dc7ea20 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -218,19 +218,19 @@ export default { deleteAlias(state, { account, alias }) { account.aliases.splice(account.aliases.indexOf(alias), 1) }, - renameFolder(state, { accountId, folder, newName }) { - const oldId = folder.id + renameMailbox(state, { accountId, mailbox, newName }) { + const oldId = mailbox.id // Remove the old entry Vue.delete(state.folders, normalizedFolderId(accountId, oldId)) // Update the ID - folder.id = btoa(newName) + mailbox.id = btoa(newName) // Set the new entry - Vue.set(state.folders, normalizedFolderId(accountId, folder.id), folder) + Vue.set(state.mailbox, normalizedFolderId(accountId, mailbox.id), mailbox) // Update the reference const oldNormalized = normalizedFolderId(accountId, oldId) - state.accounts[accountId].folders = state.accounts[accountId].folders.filter(id => id !== oldNormalized) - state.accounts[accountId].folders.push(normalizedFolderId(accountId, folder.id)) + state.accounts[accountId].mailboxes = state.accounts[accountId].mailboxes.filter(id => id !== oldNormalized) + state.accounts[accountId].mailboxes.push(normalizedFolderId(accountId, mailbox.id)) }, }