diff --git a/ghost/admin/app/components/modal-delete-post.hbs b/ghost/admin/app/components/modal-delete-post.hbs deleted file mode 100644 index d4d2ebee03..0000000000 --- a/ghost/admin/app/components/modal-delete-post.hbs +++ /dev/null @@ -1,15 +0,0 @@ - -{{svg-jar "close"}} - - - - diff --git a/ghost/admin/app/components/modal-delete-post.js b/ghost/admin/app/components/modal-delete-post.js deleted file mode 100644 index 70f6d854c1..0000000000 --- a/ghost/admin/app/components/modal-delete-post.js +++ /dev/null @@ -1,52 +0,0 @@ -import ModalComponent from 'ghost-admin/components/modal-base'; -import {alias} from '@ember/object/computed'; -import {inject as service} from '@ember/service'; -import {task} from 'ember-concurrency'; - -export default ModalComponent.extend({ - notifications: service(), - - post: alias('model.post'), - onSuccess: alias('model.onSuccess'), - - actions: { - confirm() { - this.deletePost.perform(); - } - }, - - _deletePost() { - let post = this.post; - - // definitely want to clear the data store and post of any unsaved, - // client-generated tags - post.updateTags(); - - return post.destroyRecord(); - }, - - _success() { - // clear any previous error messages - this.notifications.closeAlerts('post.delete'); - - // trigger the success action - if (this.onSuccess) { - this.onSuccess(); - } - }, - - _failure(error) { - this.notifications.showAPIError(error, {key: 'post.delete.failed'}); - }, - - deletePost: task(function* () { - try { - yield this._deletePost(); - this._success(); - } catch (e) { - this._failure(e); - } finally { - this.send('closeModal'); - } - }).drop() -}); diff --git a/ghost/admin/app/components/modals/delete-post.hbs b/ghost/admin/app/components/modals/delete-post.hbs new file mode 100644 index 0000000000..4417db2257 --- /dev/null +++ b/ghost/admin/app/components/modals/delete-post.hbs @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/ghost/admin/app/components/modals/delete-post.js b/ghost/admin/app/components/modals/delete-post.js new file mode 100644 index 0000000000..1e030eb0c1 --- /dev/null +++ b/ghost/admin/app/components/modals/delete-post.js @@ -0,0 +1,26 @@ +import Component from '@glimmer/component'; +import {inject as service} from '@ember/service'; +import {task} from 'ember-concurrency-decorators'; + +export default class DeletePostModalComponent extends Component { + @service notifications; + @service router; + + @task + *deletePostTask() { + try { + const {post} = this.args.data; + + // clear the data store and post of any unsaved client-generated tags before deleting + post.updateTags(); + yield post.destroyRecord(); + + this.notifications.closeAlerts('post.delete'); + this.router.transitionTo(post.displayName === 'page' ? 'pages' : 'posts'); + } catch (error) { + this.notifications.showAPIError(error, {key: 'post.delete.failed'}); + } finally { + this.args.close(); + } + } +} diff --git a/ghost/admin/app/controllers/editor.js b/ghost/admin/app/controllers/editor.js index 4675444608..e890399a5d 100644 --- a/ghost/admin/app/controllers/editor.js +++ b/ghost/admin/app/controllers/editor.js @@ -95,6 +95,7 @@ export default Controller.extend({ config: service(), feature: service(), membersCountCache: service(), + modals: service(), notifications: service(), router: service(), slugGenerator: service(), @@ -106,7 +107,6 @@ export default Controller.extend({ leaveEditorTransition: null, shouldFocusTitle: false, - showDeletePostModal: false, showLeaveEditorModal: false, showReAuthenticateModal: false, showEmailPreviewModal: false, @@ -275,7 +275,7 @@ export default Controller.extend({ return transition.retry(); }, - toggleDeletePostModal() { + openDeletePostModal() { if (!this.get('post.isNew')) { this.modals.open('modals/delete-post', { post: this.post diff --git a/ghost/admin/app/routes/editor.js b/ghost/admin/app/routes/editor.js index 33bff3e125..2b4a7b545b 100644 --- a/ghost/admin/app/routes/editor.js +++ b/ghost/admin/app/routes/editor.js @@ -67,10 +67,6 @@ export default AuthenticatedRoute.extend(ShortcutsRoute, { this.controller.send('toggleReAuthenticateModal'); }, - redirectToContentScreen(displayName) { - this.transitionTo(displayName === 'page' ? 'pages' : 'posts'); - }, - willTransition(transition) { // exit early if an upgrade is required because our extended route // class will abort the transition and show an error diff --git a/ghost/admin/app/templates/editor.hbs b/ghost/admin/app/templates/editor.hbs index 1c856bcc9e..0f043d4e71 100644 --- a/ghost/admin/app/templates/editor.hbs +++ b/ghost/admin/app/templates/editor.hbs @@ -108,7 +108,7 @@ @@ -123,13 +123,6 @@ {{/if}} - {{#if this.showDeletePostModal}} - - {{/if}} - {{#if this.showLeaveEditorModal}}