diff --git a/src/components/App.vue b/src/components/App.vue index 936a999f..fbd456a2 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -92,20 +92,19 @@ export default { return !!this.$store.getters['modal/config']; }, }, - created() { - syncSvc.init() - .then(() => { - networkSvc.init(); - sponsorSvc.init(); - this.ready = true; - tempFileSvc.setReady(); - }) - .catch((err) => { - if (err && err.message !== 'reload') { - console.error(err); // eslint-disable-line no-console - this.$store.dispatch('notification/error', err); - } - }); + async created() { + try { + await syncSvc.init(); + await networkSvc.init(); + await sponsorSvc.init(); + this.ready = true; + tempFileSvc.setReady(); + } catch (err) { + if (err && err.message !== 'reload') { + console.error(err); // eslint-disable-line no-console + this.$store.dispatch('notification/error', err); + } + } }, }; diff --git a/src/components/ExplorerNode.vue b/src/components/ExplorerNode.vue index 428e2eb2..1309048c 100644 --- a/src/components/ExplorerNode.vue +++ b/src/components/ExplorerNode.vue @@ -97,29 +97,36 @@ export default { } return true; }, - submitNewChild(cancel) { + async submitNewChild(cancel) { const { newChildNode } = this.$store.state.explorer; if (!cancel && !newChildNode.isNil && newChildNode.item.name) { - if (newChildNode.isFolder) { - fileSvc.storeItem(newChildNode.item) - .then(item => this.select(item.id), () => { /* cancel */ }); - } else { - fileSvc.createFile(newChildNode.item) - .then(item => this.select(item.id), () => { /* cancel */ }); + try { + if (newChildNode.isFolder) { + const item = await fileSvc.storeItem(newChildNode.item); + this.select(item.id); + } else { + const item = await fileSvc.createFile(newChildNode.item); + this.select(item.id); + } + } catch (e) { + // Cancel } } this.$store.commit('explorer/setNewItem', null); }, - submitEdit(cancel) { + async submitEdit(cancel) { const { item } = this.$store.getters['explorer/editingNode']; const value = this.editingValue; this.setEditingId(null); if (!cancel && item.id && value) { - fileSvc.storeItem({ - ...item, - name: value, - }) - .catch(() => { /* cancel */ }); + try { + await fileSvc.storeItem({ + ...item, + name: value, + }); + } catch (e) { + // Cancel + } } }, setDragSourceId(evt) { @@ -140,22 +147,17 @@ export default { && !targetNode.isNil && sourceNode.item.id !== targetNode.item.id ) { - const patch = { - id: sourceNode.item.id, + fileSvc.storeItem({ + ...sourceNode.item, parentId: targetNode.item.id, - }; - if (sourceNode.isFolder) { - this.$store.commit('folder/patchItem', patch); - } else { - this.$store.commit('file/patchItem', patch); - } + }); } }, - onContextMenu(evt) { + async onContextMenu(evt) { if (this.select(undefined, false)) { evt.preventDefault(); evt.stopPropagation(); - this.$store.dispatch('contextMenu/open', { + const item = await this.$store.dispatch('contextMenu/open', { coordinates: { left: evt.clientX, top: evt.clientY, @@ -178,8 +180,8 @@ export default { name: 'Delete', perform: () => explorerSvc.deleteItem(), }], - }) - .then(item => item.perform()); + }); + item.perform(); } }, }, diff --git a/src/components/Modal.vue b/src/components/Modal.vue index 91d84182..176b9781 100644 --- a/src/components/Modal.vue +++ b/src/components/Modal.vue @@ -175,10 +175,6 @@ export default { background-color: rgba(160, 160, 160, 0.5); overflow: auto; - hr { - margin: 0.5em 0; - } - p { line-height: 1.5; } diff --git a/src/components/NavigationBar.vue b/src/components/NavigationBar.vue index bbf77c10..9ed152b9 100644 --- a/src/components/NavigationBar.vue +++ b/src/components/NavigationBar.vue @@ -192,7 +192,7 @@ export default { editorSvc.pagedownEditor.uiManager.doClick(name); } }, - editTitle(toggle) { + async editTitle(toggle) { this.titleFocus = toggle; if (toggle) { this.titleInputElt.setSelectionRange(0, this.titleInputElt.value.length); @@ -200,11 +200,14 @@ export default { const title = this.title.trim(); this.title = this.$store.getters['file/current'].name; if (title) { - fileSvc.storeItem({ - ...this.$store.getters['file/current'], - name: title, - }) - .catch(() => { /* Cancel */ }); + try { + await fileSvc.storeItem({ + ...this.$store.getters['file/current'], + name: title, + }); + } catch (e) { + // Cancel + } } } }, diff --git a/src/components/gutters/Comment.vue b/src/components/gutters/Comment.vue index 21588430..b3e063ea 100644 --- a/src/components/gutters/Comment.vue +++ b/src/components/gutters/Comment.vue @@ -47,12 +47,13 @@ export default { ...mapMutations('discussion', [ 'setIsCommenting', ]), - removeComment() { - this.$store.dispatch('modal/commentDeletion') - .then( - () => this.$store.dispatch('discussion/cleanCurrentFile', { filterComment: this.comment }), - () => { /* Cancel */ }, - ); + async removeComment() { + try { + await this.$store.dispatch('modal/commentDeletion'); + this.$store.dispatch('discussion/cleanCurrentFile', { filterComment: this.comment }); + } catch (e) { + // Cancel + } }, }, mounted() { diff --git a/src/components/gutters/CurrentDiscussion.vue b/src/components/gutters/CurrentDiscussion.vue index 36262d4c..f14b68be 100644 --- a/src/components/gutters/CurrentDiscussion.vue +++ b/src/components/gutters/CurrentDiscussion.vue @@ -93,14 +93,15 @@ export default { .start(); } }, - removeDiscussion() { - this.$store.dispatch('modal/discussionDeletion') - .then( - () => this.$store.dispatch('discussion/cleanCurrentFile', { - filterDiscussion: this.currentDiscussion, - }), - () => { /* Cancel */ }, - ); + async removeDiscussion() { + try { + await this.$store.dispatch('modal/discussionDeletion'); + this.$store.dispatch('discussion/cleanCurrentFile', { + filterDiscussion: this.currentDiscussion, + }); + } catch (e) { + // Cancel + } }, }, }; diff --git a/src/components/menus/HistoryMenu.vue b/src/components/menus/HistoryMenu.vue index 329aa22d..57a63139 100644 --- a/src/components/menus/HistoryMenu.vue +++ b/src/components/menus/HistoryMenu.vue @@ -96,12 +96,13 @@ export default { ...mapMutations('content', [ 'setRevisionContent', ]), - signin() { - return googleHelper.signin() - .then( - () => syncSvc.requestSync(), - () => { /* Cancel */ }, - ); + async signin() { + try { + await googleHelper.signin(); + syncSvc.requestSync(); + } catch (e) { + // Cancel + } }, close() { this.$store.dispatch('data/setSideBarPanel', 'menu'); @@ -117,10 +118,15 @@ export default { const currentFile = this.$store.getters['file/current']; this.$store.dispatch( 'queue/enqueue', - () => Promise.resolve() - .then(() => this.workspaceProvider - .getRevisionContent(syncToken, currentFile.id, revision.id)) - .then(resolve, reject), + async () => { + try { + const content = await this.workspaceProvider + .getRevisionContent(syncToken, currentFile.id, revision.id); + resolve(content); + } catch (e) { + reject(e); + } + }, ); }); revisionContentPromises[revision.id] = revisionContentPromise; @@ -181,9 +187,15 @@ export default { revisionsPromise = new Promise((resolve, reject) => { this.$store.dispatch( 'queue/enqueue', - () => Promise.resolve() - .then(() => this.workspaceProvider.listRevisions(syncToken, currentFile.id)) - .then(resolve, reject), + async () => { + try { + const revisions = await this.workspaceProvider + .listRevisions(syncToken, currentFile.id); + resolve(revisions); + } catch (e) { + reject(e); + } + }, ); }) .catch(() => { diff --git a/src/components/menus/MainMenu.vue b/src/components/menus/MainMenu.vue index 3eaf751f..9d4eccde 100644 --- a/src/components/menus/MainMenu.vue +++ b/src/components/menus/MainMenu.vue @@ -104,16 +104,20 @@ export default { ...mapActions('data', { setPanel: 'setSideBarPanel', }), - signin() { - return googleHelper.signin() - .then( - () => syncSvc.requestSync(), - () => { /* Cancel */ }, - ); + async signin() { + try { + await googleHelper.signin(); + syncSvc.requestSync(); + } catch (e) { + // Cancel + } }, - fileProperties() { - return this.$store.dispatch('modal/open', 'fileProperties') - .catch(() => { /* Cancel */ }); + async fileProperties() { + try { + await this.$store.dispatch('modal/open', 'fileProperties'); + } catch (e) { + // Cancel + } }, print() { window.print(); diff --git a/src/components/menus/MoreMenu.vue b/src/components/menus/MoreMenu.vue index f1ebb76f..38735eb1 100644 --- a/src/components/menus/MoreMenu.vue +++ b/src/components/menus/MoreMenu.vue @@ -78,29 +78,33 @@ export default { document.body.removeChild(iframeElt); }, 60000); }, - settings() { - return this.$store.dispatch('modal/open', 'settings') - .then( - settings => this.$store.dispatch('data/setSettings', settings), - () => { /* Cancel */ }, - ); + async settings() { + try { + const settings = await this.$store.dispatch('modal/open', 'settings'); + this.$store.dispatch('data/setSettings', settings); + } catch (e) { + // Cancel + } }, - templates() { - return this.$store.dispatch('modal/open', 'templates') - .then( - ({ templates }) => this.$store.dispatch('data/setTemplates', templates), - () => { /* Cancel */ }, - ); + async templates() { + try { + const { templates } = await this.$store.dispatch('modal/open', 'templates'); + this.$store.dispatch('data/setTemplates', templates); + } catch (e) { + // Cancel + } }, - reset() { - return this.$store.dispatch('modal/reset') - .then(() => { - window.location.href = '#reset=true'; - window.location.reload(); - }); + async reset() { + try { + await this.$store.dispatch('modal/reset'); + window.location.href = '#reset=true'; + window.location.reload(); + } catch (e) { + // Cancel + } }, about() { - return this.$store.dispatch('modal/open', 'about'); + this.$store.dispatch('modal/open', 'about'); }, }, }; diff --git a/src/components/menus/PublishMenu.vue b/src/components/menus/PublishMenu.vue index 6995ecf1..cadb3a40 100644 --- a/src/components/menus/PublishMenu.vue +++ b/src/components/menus/PublishMenu.vue @@ -118,12 +118,15 @@ const tokensToArray = (tokens, filter = () => true) => Object.keys(tokens) .filter(token => filter(token)) .sort((token1, token2) => token1.name.localeCompare(token2.name)); -const openPublishModal = (token, type) => store.dispatch('modal/open', { - type, - token, -}).then(publishLocation => publishSvc.createPublishLocation(publishLocation)); - -const onCancel = () => {}; +const publishModalOpener = type => async (token) => { + try { + const publishLocation = await store.dispatch('modal/open', { + type, + token, + }); + publishSvc.createPublishLocation(publishLocation); + } catch (e) { /* cancel */ } +}; export default { components: { @@ -178,74 +181,48 @@ export default { managePublish() { return this.$store.dispatch('modal/open', 'publishManagement'); }, - addGoogleDriveAccount() { - return this.$store.dispatch('modal/open', { - type: 'googleDriveAccount', - onResolve: () => googleHelper.addDriveAccount(!store.getters['data/localSettings'].googleDriveRestrictedAccess), - }) - .catch(onCancel); + async addGoogleDriveAccount() { + try { + await this.$store.dispatch('modal/open', { type: 'googleDriveAccount' }); + await googleHelper.addDriveAccount(!store.getters['data/localSettings'].googleDriveRestrictedAccess); + } catch (e) { /* cancel */ } }, - addDropboxAccount() { - return this.$store.dispatch('modal/open', { - type: 'dropboxAccount', - onResolve: () => dropboxHelper.addAccount(!store.getters['data/localSettings'].dropboxRestrictedAccess), - }) - .catch(onCancel); + async addDropboxAccount() { + try { + await this.$store.dispatch('modal/open', { type: 'dropboxAccount' }); + await dropboxHelper.addAccount(!store.getters['data/localSettings'].dropboxRestrictedAccess); + } catch (e) { /* cancel */ } }, - addGithubAccount() { - return this.$store.dispatch('modal/open', { - type: 'githubAccount', - onResolve: () => githubHelper.addAccount(store.getters['data/localSettings'].githubRepoFullAccess), - }) - .catch(onCancel); + async addGithubAccount() { + try { + await this.$store.dispatch('modal/open', { type: 'githubAccount' }); + await githubHelper.addAccount(store.getters['data/localSettings'].githubRepoFullAccess); + } catch (e) { /* cancel */ } }, - addWordpressAccount() { - return wordpressHelper.addAccount() - .catch(onCancel); + async addWordpressAccount() { + try { + await wordpressHelper.addAccount(); + } catch (e) { /* cancel */ } }, - addBloggerAccount() { - return googleHelper.addBloggerAccount() - .catch(onCancel); + async addBloggerAccount() { + try { + await googleHelper.addBloggerAccount(); + } catch (e) { /* cancel */ } }, - addZendeskAccount() { - return this.$store.dispatch('modal/open', { - type: 'zendeskAccount', - onResolve: ({ subdomain, clientId }) => zendeskHelper.addAccount(subdomain, clientId), - }) - .catch(onCancel); - }, - publishGoogleDrive(token) { - return openPublishModal(token, 'googleDrivePublish') - .catch(onCancel); - }, - publishDropbox(token) { - return openPublishModal(token, 'dropboxPublish') - .catch(onCancel); - }, - publishGithub(token) { - return openPublishModal(token, 'githubPublish') - .catch(onCancel); - }, - publishGist(token) { - return openPublishModal(token, 'gistPublish') - .catch(onCancel); - }, - publishWordpress(token) { - return openPublishModal(token, 'wordpressPublish') - .catch(onCancel); - }, - publishBlogger(token) { - return openPublishModal(token, 'bloggerPublish') - .catch(onCancel); - }, - publishBloggerPage(token) { - return openPublishModal(token, 'bloggerPagePublish') - .catch(onCancel); - }, - publishZendesk(token) { - return openPublishModal(token, 'zendeskPublish') - .catch(onCancel); + async addZendeskAccount() { + try { + const { subdomain, clientId } = await this.$store.dispatch('modal/open', { type: 'zendeskAccount' }); + await zendeskHelper.addAccount(subdomain, clientId); + } catch (e) { /* cancel */ } }, + publishGoogleDrive: publishModalOpener('googleDrivePublish'), + publishDropbox: publishModalOpener('dropboxPublish'), + publishGithub: publishModalOpener('githubPublish'), + publishGist: publishModalOpener('gistPublish'), + publishWordpress: publishModalOpener('wordpressPublish'), + publishBlogger: publishModalOpener('bloggerPublish'), + publishBloggerPage: publishModalOpener('bloggerPagePublish'), + publishZendesk: publishModalOpener('zendeskPublish'), }, }; diff --git a/src/components/menus/SyncMenu.vue b/src/components/menus/SyncMenu.vue index f30dcd1e..89d36e8c 100644 --- a/src/components/menus/SyncMenu.vue +++ b/src/components/menus/SyncMenu.vue @@ -101,8 +101,6 @@ const openSyncModal = (token, type) => store.dispatch('modal/open', { token, }).then(syncLocation => syncSvc.createSyncLocation(syncLocation)); -const onCancel = () => {}; - export default { components: { MenuEntry, @@ -147,66 +145,79 @@ export default { manageSync() { return this.$store.dispatch('modal/open', 'syncManagement'); }, - addGoogleDriveAccount() { - return this.$store.dispatch('modal/open', { - type: 'googleDriveAccount', - onResolve: () => googleHelper.addDriveAccount(!store.getters['data/localSettings'].googleDriveRestrictedAccess), - }) - .catch(onCancel); + async addGoogleDriveAccount() { + try { + await this.$store.dispatch('modal/open', { type: 'googleDriveAccount' }); + await googleHelper.addDriveAccount(!store.getters['data/localSettings'].googleDriveRestrictedAccess); + } catch (e) { /* cancel */ } }, - addDropboxAccount() { - return this.$store.dispatch('modal/open', { - type: 'dropboxAccount', - onResolve: () => dropboxHelper.addAccount(!store.getters['data/localSettings'].dropboxRestrictedAccess), - }) - .catch(onCancel); + async addDropboxAccount() { + try { + await this.$store.dispatch('modal/open', { type: 'dropboxAccount' }); + await dropboxHelper.addAccount(!store.getters['data/localSettings'].dropboxRestrictedAccess); + } catch (e) { /* cancel */ } }, - addGithubAccount() { - return this.$store.dispatch('modal/open', { - type: 'githubAccount', - onResolve: () => githubHelper.addAccount(store.getters['data/localSettings'].githubRepoFullAccess), - }) - .catch(onCancel); + async addGithubAccount() { + try { + await this.$store.dispatch('modal/open', { type: 'githubAccount' }); + await githubHelper.addAccount(store.getters['data/localSettings'].githubRepoFullAccess); + } catch (e) { /* cancel */ } }, - openGoogleDrive(token) { - return googleHelper.openPicker(token, 'doc') - .then(files => this.$store.dispatch( - 'queue/enqueue', - () => googleDriveProvider.openFiles(token, files), - )); + async openGoogleDrive(token) { + const files = await googleHelper.openPicker(token, 'doc'); + this.$store.dispatch( + 'queue/enqueue', + () => googleDriveProvider.openFiles(token, files), + ); }, - openDropbox(token) { - return dropboxHelper.openChooser(token) - .then(paths => this.$store.dispatch( - 'queue/enqueue', - () => dropboxProvider.openFiles(token, paths), - )); + async openDropbox(token) { + const paths = await dropboxHelper.openChooser(token); + this.$store.dispatch( + 'queue/enqueue', + () => dropboxProvider.openFiles(token, paths), + ); }, - saveGoogleDrive(token) { - return openSyncModal(token, 'googleDriveSave') - .catch(onCancel); + async saveGoogleDrive(token) { + try { + await openSyncModal(token, 'googleDriveSave'); + } catch (e) { + // Cancel + } }, - saveDropbox(token) { - return openSyncModal(token, 'dropboxSave') - .catch(onCancel); + async saveDropbox(token) { + try { + await openSyncModal(token, 'dropboxSave'); + } catch (e) { + // Cancel + } }, - openGithub(token) { - return store.dispatch('modal/open', { - type: 'githubOpen', - token, - }) - .then(syncLocation => this.$store.dispatch( + async openGithub(token) { + try { + const syncLocation = await store.dispatch('modal/open', { + type: 'githubOpen', + token, + }); + this.$store.dispatch( 'queue/enqueue', () => githubProvider.openFile(token, syncLocation), - )); + ); + } catch (e) { + // Cancel + } }, - saveGithub(token) { - return openSyncModal(token, 'githubSave') - .catch(onCancel); + async saveGithub(token) { + try { + await openSyncModal(token, 'githubSave'); + } catch (e) { + // Cancel + } }, - saveGist(token) { - return openSyncModal(token, 'gistSync') - .catch(onCancel); + async saveGist(token) { + try { + await openSyncModal(token, 'gistSync'); + } catch (e) { + // Cancel + } }, }, }; diff --git a/src/components/menus/WorkspacesMenu.vue b/src/components/menus/WorkspacesMenu.vue index 7254ef2c..5457e463 100644 --- a/src/components/menus/WorkspacesMenu.vue +++ b/src/components/menus/WorkspacesMenu.vue @@ -31,8 +31,6 @@ import { mapGetters } from 'vuex'; import MenuEntry from './common/MenuEntry'; import googleHelper from '../../services/providers/helpers/googleHelper'; -const onCancel = () => {}; - export default { components: { MenuEntry, @@ -46,28 +44,37 @@ export default { ]), }, methods: { - addCouchdbWorkspace() { - return this.$store.dispatch('modal/open', { - type: 'couchdbWorkspace', - }) - .catch(onCancel); + async addCouchdbWorkspace() { + try { + this.$store.dispatch('modal/open', { + type: 'couchdbWorkspace', + }); + } catch (e) { + // Cancel + } }, - addGithubWorkspace() { - return this.$store.dispatch('modal/open', { - type: 'githubWorkspace', - }) - .catch(onCancel); + async addGithubWorkspace() { + try { + this.$store.dispatch('modal/open', { + type: 'githubWorkspace', + }); + } catch (e) { + // Cancel + } }, - addGoogleDriveWorkspace() { - return googleHelper.addDriveAccount(true) - .then(token => this.$store.dispatch('modal/open', { + async addGoogleDriveWorkspace() { + try { + const token = await googleHelper.addDriveAccount(true); + this.$store.dispatch('modal/open', { type: 'googleDriveWorkspace', token, - })) - .catch(onCancel); + }); + } catch (e) { + // Cancel + } }, manageWorkspaces() { - return this.$store.dispatch('modal/open', 'workspaceManagement'); + this.$store.dispatch('modal/open', 'workspaceManagement'); }, }, }; diff --git a/src/components/modals/AboutModal.vue b/src/components/modals/AboutModal.vue index 05858e6f..3d1550bd 100644 --- a/src/components/modals/AboutModal.vue +++ b/src/components/modals/AboutModal.vue @@ -2,7 +2,7 @@