Ghost/ghost/admin/app/components/gh-editor-post-status.js
Kevin Ansfield 397a1b52f2 Added console log with reason unsaved changes modal is shown in editor
no issue

- output the reason we're showing the unsaved changes modal along with some context to the console
- to share it, right click on the object that is logged to the web inspector console next to the text "showing leave editor modal" and choose "Store as global variable" in the popup menu, then execute `copy(temp1)` (if `temp1` was the variable that was created for you) which will copy a string representation of the object to your clipboard ready for sharing
2019-12-17 09:57:37 +00:00

53 lines
1.6 KiB
JavaScript

import Component from '@ember/component';
import config from 'ghost-admin/config/environment';
import moment from 'moment';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
import {task, timeout} from 'ember-concurrency';
export default Component.extend({
clock: service(),
post: null,
isSaving: false,
'data-test-editor-post-status': true,
_isSaving: false,
countdown: computed('post.{publishedAtUTC,isScheduled}', 'clock.second', function () {
let isScheduled = this.get('post.isScheduled');
let publishTime = this.get('post.publishedAtUTC') || moment.utc();
let timeUntilPublished = publishTime.diff(moment.utc(), 'minutes', true);
let isPublishedSoon = timeUntilPublished > 0 && timeUntilPublished < 15;
// force a recompute
this.get('clock.second');
if (isScheduled && isPublishedSoon) {
return moment(publishTime).fromNow();
} else {
return false;
}
}),
// 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() {
if (this.isSaving) {
this.showSavingMessage.perform();
}
},
showSavingMessage: task(function* () {
this.set('_isSaving', true);
yield timeout(config.environment === 'test' ? 0 : 3000);
if (!this.isDestroyed && !this.isDestroying) {
this.set('_isSaving', false);
}
}).drop()
});