2021-09-03 20:24:46 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2021-09-03 20:24:46 +03:00
|
|
|
|
2022-03-14 13:52:04 +03:00
|
|
|
export default class DeletePostModal extends Component {
|
2021-09-03 20:24:46 +03:00
|
|
|
@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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|