mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
5f7c79d04e
refs https://github.com/TryGhost/Team/issues/1121 Double-clicking the delete button in the confirmation modal could trigger a second attempt to delete the post/page when it had already been deleted resulting in an ugly/incomprehensible error bubbling up. - added `{drop:true}` to the task instance so it can't be called again whilst it's currently running - added a guard for `isDeleted` so we don't attempt to destroy an already deleted record - added a `true` return so the button indicates a successful state rather than an error state whilst the modal is closing
32 lines
963 B
JavaScript
32 lines
963 B
JavaScript
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({drop: true})
|
|
*deletePostTask() {
|
|
try {
|
|
const {post} = this.args.data;
|
|
|
|
if (post.isDeleted) {
|
|
return true;
|
|
}
|
|
|
|
// 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');
|
|
return true;
|
|
} catch (error) {
|
|
this.notifications.showAPIError(error, {key: 'post.delete.failed'});
|
|
} finally {
|
|
this.args.close();
|
|
}
|
|
}
|
|
}
|