Ghost/ghost/admin/app/components/editor-labs/publish-options/publish-at.js
Kevin Ansfield 43d417858a Switched publish flow dropdowns to expanding blocks and added publish time options
refs https://github.com/TryGhost/Team/issues/1542

- moved publish-flow modal into `components/editor-labs/modals/publish-flow` as we have enough editor-related components to keep them in one place
- updated publish flow design to use expanding blocks in place of dropdowns
  - added `openSection` property in publish-flow modal and associated action for toggling sections
  - moved "publish at" option into a separate component to keep publish-flow modal cleaner (keeps option-specific actions out of the main modal component)
  - used `{{liquid-if}}` to animate the expanding blocks
- added schedule time properties to `PublishOptions`
  - kept "is scheduled" and "scheduled at" separate so it's possible to keep the selected schedule time across selecting/deselecting the option to schedule
  - ensures schedule date is kept to the minimum 5-minute in the future across option changes
  - updated publish-management to reset the scheduled option to "Right now" when the publish-flow modal is opened if a schedule time was previously set but is now in the past
2022-04-27 18:21:01 +01:00

48 lines
1.4 KiB
JavaScript

import Component from '@glimmer/component';
import moment from 'moment';
import {action} from '@ember/object';
export default class PublishAtOption extends Component {
@action
setDate(selectedDate) {
const newDate = moment(this.args.publishOptions.scheduledAtUTC);
const {year, month, date} = moment(selectedDate).toObject();
newDate.set({year, month, date});
this.args.publishOptions.setScheduledAt(newDate);
}
@action
setTime(time) {
if (!time) {
return;
}
if (time.match(/^\d:\d\d$/)) {
time = `0${time}`;
}
if (!time.match(/^\d\d:\d\d$/)) {
return;
}
const [hour, minute] = time.split(':').map(n => parseInt(n, 10));
if (isNaN(hour) || hour < 0 || hour > 23 || isNaN(minute) || minute < 0 || minute > 59) {
return;
}
// hour/minute will be the site timezone equivalent but we need the hour/minute
// as it would be in UTC
const conversionDate = moment();
conversionDate.set({hour, minute});
const utcDate = moment.utc(conversionDate);
const newDate = moment.utc(this.args.publishOptions.scheduledAtUTC);
newDate.set({hour: utcDate.get('hour'), minute: utcDate.get('minute')});
this.args.publishOptions.setScheduledAt(newDate);
}
}