2020-07-01 16:07:52 +03:00
|
|
|
import Component from '@glimmer/component';
|
2018-05-03 19:52:39 +03:00
|
|
|
import config from 'ghost-admin/config/environment';
|
2020-07-01 16:07:52 +03:00
|
|
|
import {formatPostTime} from 'ghost-admin/helpers/gh-format-post-time';
|
|
|
|
import {get} from '@ember/object';
|
2019-11-13 17:31:42 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2020-07-01 16:07:52 +03:00
|
|
|
import {task} from 'ember-concurrency-decorators';
|
|
|
|
import {timeout} from 'ember-concurrency';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
export default class GhEditorPostStatusComponent extends Component {
|
|
|
|
@service clock;
|
|
|
|
@service settings;
|
2019-11-13 19:10:29 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
@tracked _isSaving = false;
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
// this.args.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 so we use autotracking to trigger
|
|
|
|
// a task that sets _isSaving to true for 3 seconds
|
|
|
|
get isSaving() {
|
|
|
|
if (this.args.isSaving) {
|
|
|
|
this.showSavingMessage.perform();
|
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
return this._isSaving;
|
|
|
|
}
|
2019-11-13 17:31:42 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
get scheduledText() {
|
|
|
|
// force a recompute every second
|
|
|
|
get(this.clock, 'second');
|
2019-11-13 17:31:42 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
let text = [];
|
2020-11-06 21:54:27 +03:00
|
|
|
const sendEmailWhenPublished = this.args.post.emailRecipientFilter;
|
|
|
|
if (sendEmailWhenPublished && sendEmailWhenPublished !== 'none') {
|
|
|
|
text.push(`and sent to ${sendEmailWhenPublished} members`);
|
2019-11-13 17:31:42 +03:00
|
|
|
}
|
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
let formattedTime = formatPostTime(
|
|
|
|
this.args.post.publishedAtUTC,
|
|
|
|
{timezone: this.settings.get('timezone'), scheduled: true}
|
|
|
|
);
|
|
|
|
text.push(formattedTime);
|
|
|
|
|
|
|
|
return text.join(' ');
|
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2020-07-01 16:07:52 +03:00
|
|
|
@task({drop: true})
|
|
|
|
*showSavingMessage() {
|
|
|
|
this._isSaving = true;
|
2018-05-03 19:52:39 +03:00
|
|
|
yield timeout(config.environment === 'test' ? 0 : 3000);
|
2019-12-17 12:57:37 +03:00
|
|
|
|
|
|
|
if (!this.isDestroyed && !this.isDestroying) {
|
2020-07-01 16:07:52 +03:00
|
|
|
this._isSaving = false;
|
2019-12-17 12:57:37 +03:00
|
|
|
}
|
2020-07-01 16:07:52 +03:00
|
|
|
}
|
|
|
|
}
|