2022-05-12 01:46:01 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
export default class EditorPostPreviewModal extends Component {
|
|
|
|
@service settings;
|
|
|
|
@service session;
|
|
|
|
|
|
|
|
static modalOptions = {
|
2022-05-19 14:19:49 +03:00
|
|
|
className: 'fullscreen-modal-total-overlay publish-modal',
|
2022-05-12 01:46:01 +03:00
|
|
|
omitBackdrop: true,
|
|
|
|
ignoreBackdropClick: true
|
|
|
|
};
|
|
|
|
|
2022-05-13 19:43:14 +03:00
|
|
|
@tracked tab = this.args.data.currentTab || 'browser';
|
2022-05-19 15:33:23 +03:00
|
|
|
@tracked isChangingTab = false;
|
2022-05-12 01:46:01 +03:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.saveFirstTask.perform();
|
|
|
|
}
|
|
|
|
|
2022-05-19 15:33:23 +03:00
|
|
|
get skipAnimation() {
|
|
|
|
return this.args.data.skipAnimation || this.isChangingTab;
|
|
|
|
}
|
|
|
|
|
2022-05-12 01:46:01 +03:00
|
|
|
@action
|
|
|
|
changeTab(tab) {
|
|
|
|
this.tab = tab;
|
2022-05-19 15:33:23 +03:00
|
|
|
this.isChangingTab = true;
|
2022-05-13 19:43:14 +03:00
|
|
|
this.args.data.changeTab?.(tab);
|
2022-05-12 01:46:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@task
|
|
|
|
*saveFirstTask() {
|
2022-05-16 16:15:02 +03:00
|
|
|
const {saveTask, publishOptions, hasDirtyAttributes} = this.args.data;
|
2022-05-12 01:46:01 +03:00
|
|
|
|
|
|
|
if (saveTask.isRunning) {
|
|
|
|
return yield saveTask.last;
|
|
|
|
}
|
|
|
|
|
2022-05-16 16:15:02 +03:00
|
|
|
if (publishOptions.post.isDraft && hasDirtyAttributes) {
|
2022-05-12 01:46:01 +03:00
|
|
|
yield saveTask.perform();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|