Ghost/ghost/admin/app/controllers/settings/design/index.js
Kevin Ansfield e9911d5e20 Added ctrl/cmd+s save on design settings screen
refs https://github.com/TryGhost/Team/issues/1149

- use ember-keyboard's `{{on-key}}` modifier to attach keyboard event listener when the design settings index screen is shown - ensures that ctrl/cmd+s on the change-theme screen won't trigger an unexpected save
- blur active element when saving so the preview is updated and reflects what has just been saved (text fields only update preview on blur)
2021-10-19 11:59:34 +01:00

58 lines
1.4 KiB
JavaScript

import Controller from '@ember/controller';
import {action} from '@ember/object';
import {next} from '@ember/runloop';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class SettingsDesignIndexController extends Controller {
@service config;
@service customThemeSettings;
@service notifications;
@service settings;
@service themeManagement;
@tracked previewSize = 'desktop';
get isDesktopPreview() {
return this.previewSize === 'desktop';
}
get isMobilePreview() {
return this.previewSize === 'mobile';
}
@action
setPreviewSize(size) {
this.previewSize = size;
}
@action
saveFromKeyboard() {
document.activeElement.blur?.();
return this.saveTask.perform();
}
@task
*saveTask() {
try {
if (this.settings.get('errors').length !== 0) {
return;
}
yield Promise.all([
this.settings.save(),
this.customThemeSettings.save()
]);
// ensure task button switches to success state
return true;
} catch (error) {
if (error) {
this.notifications.showAPIError(error);
throw error;
}
}
}
}