2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2018-05-03 19:52:39 +03:00
|
|
|
import config from 'ghost-admin/config/environment';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {reads} from '@ember/object/computed';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {task, timeout} from 'ember-concurrency';
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
post: null,
|
|
|
|
isSaving: false,
|
|
|
|
|
|
|
|
'data-test-editor-post-status': true,
|
|
|
|
|
|
|
|
_isSaving: false,
|
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
isNew: reads('post.isNew'),
|
|
|
|
isScheduled: reads('post.isScheduled'),
|
|
|
|
|
2017-04-11 16:39:45 +03:00
|
|
|
isPublished: computed('post.{isPublished,pastScheduledTime}', function () {
|
|
|
|
let isPublished = this.get('post.isPublished');
|
|
|
|
let pastScheduledTime = this.get('post.pastScheduledTime');
|
|
|
|
|
|
|
|
return isPublished || pastScheduledTime;
|
|
|
|
}),
|
|
|
|
|
|
|
|
// isSaving will only be true briefly whilst the post is saving,
|
|
|
|
// we want to ensure that the "Saving..." message is shown for at least
|
|
|
|
// a few seconds so that it's noticeable
|
|
|
|
didReceiveAttrs() {
|
2019-03-06 16:53:54 +03:00
|
|
|
if (this.isSaving) {
|
|
|
|
this.showSavingMessage.perform();
|
2017-04-11 16:39:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showSavingMessage: task(function* () {
|
|
|
|
this.set('_isSaving', true);
|
2018-05-03 19:52:39 +03:00
|
|
|
yield timeout(config.environment === 'test' ? 0 : 3000);
|
2017-04-11 16:39:45 +03:00
|
|
|
this.set('_isSaving', false);
|
|
|
|
}).drop()
|
|
|
|
});
|