Ghost/ghost/admin/app/components/modals/delete-post.js
Kevin Ansfield 8cc4c6c4a1 Dropped ember-concurrency-decorators dependency
no issue

- since `ember-concurrency@2.0` it's possible to use the standard imports as decorators removing the need for the extra `ember-concurrency-decorators` dependency and imports
2022-02-09 10:49:38 +00:00

32 lines
952 B
JavaScript

import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
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();
}
}
}