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';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task, timeout} from 'ember-concurrency';
|
2020-07-01 16:07:52 +03:00
|
|
|
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
|
|
|
|
2021-06-11 13:44:42 +03:00
|
|
|
get scheduledTime() {
|
2020-07-01 16:07:52 +03:00
|
|
|
// force a recompute every second
|
|
|
|
get(this.clock, 'second');
|
2019-11-13 17:31:42 +03:00
|
|
|
|
2021-06-11 13:44:42 +03:00
|
|
|
return formatPostTime(
|
2020-07-01 16:07:52 +03:00
|
|
|
this.args.post.publishedAtUTC,
|
|
|
|
{timezone: this.settings.get('timezone'), scheduled: true}
|
|
|
|
);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|