Ghost/ghost/admin/app/components/gh-timezone-select.js
Gabriel Csapo d51f2bcf23 [chore] migrate to eslint@8 and run --fix (#2256)
closes https://github.com/TryGhost/Admin/pull/2107

- updated related babel dependencies
- bumped eslint
- ran `yarn lint:js --fix`
- added eslint ignore comments for some required non-camel-case properties
2022-02-10 10:41:36 +00:00

72 lines
2.1 KiB
JavaScript

import Component from '@ember/component';
import classic from 'ember-classic-decorator';
import moment from 'moment';
import {action, computed} from '@ember/object';
import {classNames} from '@ember-decorators/component';
import {mapBy} from '@ember/object/computed';
import {inject as service} from '@ember/service';
@classic
@classNames('form-group', 'for-select')
export default class GhTimezoneSelect extends Component {
@service clock;
timezone = null;
availableTimezones = null;
// Allowed actions
update = () => {};
@mapBy('availableTimezones', 'name')
availableTimezoneNames;
@computed('timezone', 'availableTimezoneNames')
get hasTimezoneOverride() {
let timezone = this.timezone;
let availableTimezoneNames = this.availableTimezoneNames;
return !availableTimezoneNames.includes(timezone);
}
@computed('timezone', 'availableTimezones', 'hasTimezoneOverride')
get selectedTimezone() {
let hasTimezoneOverride = this.hasTimezoneOverride;
let timezone = this.timezone;
let availableTimezones = this.availableTimezones;
if (hasTimezoneOverride) {
return {name: '', label: ''};
}
return availableTimezones
.filterBy('name', timezone)
.get('firstObject');
}
@computed('availableTimezones', 'hasTimezoneOverride')
get selectableTimezones() {
let hasTimezoneOverride = this.hasTimezoneOverride;
let availableTimezones = this.availableTimezones;
if (hasTimezoneOverride) {
return [{name: '', label: ''}, ...availableTimezones];
}
return availableTimezones;
}
@computed('hasTimezoneOverride', 'timezone', 'selectedTimezone', 'clock.second')
get localTime() {
let hasTimezoneOverride = this.hasTimezoneOverride;
let timezone = hasTimezoneOverride ? this.timezone : this.get('selectedTimezone.name');
this.get('clock.second');
return timezone ? moment().tz(timezone).format('HH:mm:ss') : moment().utc().format('HH:mm:ss');
}
@action
setTimezone(timezone) {
this.update(timezone);
}
}