2021-09-03 20:24:46 +03:00
|
|
|
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;
|
|
|
|
|
2021-11-16 20:59:59 +03:00
|
|
|
@task({drop: true})
|
2021-09-03 20:24:46 +03:00
|
|
|
*deletePostTask() {
|
|
|
|
try {
|
|
|
|
const {post} = this.args.data;
|
|
|
|
|
2021-11-16 20:59:59 +03:00
|
|
|
if (post.isDeleted) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-03 20:24:46 +03:00
|
|
|
// 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');
|
2021-11-16 20:59:59 +03:00
|
|
|
return true;
|
2021-09-03 20:24:46 +03:00
|
|
|
} catch (error) {
|
|
|
|
this.notifications.showAPIError(error, {key: 'post.delete.failed'});
|
|
|
|
} finally {
|
|
|
|
this.args.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|