Ghost/ghost/admin/app/components/modals/post-preview.js
Kevin Ansfield c09dcd38af 🐛 Fixed preview modal showing outdated content if opened before autosave is triggered
refs https://github.com/TryGhost/Team/issues/609

There's a 3 second timeout before a background save is triggered after the last edit, if the preview modal is opened in that timeframe it would show outdated content.

- added a task that is triggered when the preview modal is opened
  - if a save task is already running it will wait for it to finish
  - otherwise if the post is a draft and the editor has dirty attributes it will trigger a save
- modal shows a loading spinner whilst waiting for the save to finish so the preview contents always match the latest editor changes
2021-11-09 12:13:23 +00:00

32 lines
727 B
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class ModalPostPreviewComponent extends Component {
@tracked tab = 'browser';
constructor() {
super(...arguments);
this.saveFirstTask.perform();
}
@action
changeTab(tab) {
this.tab = tab;
}
@task
*saveFirstTask() {
const {saveTask, post, hasDirtyAttributes} = this.args.data;
if (saveTask.isRunning) {
return yield saveTask.last;
}
if (post.isDraft && hasDirtyAttributes) {
yield saveTask.perform();
}
}
}