Ghost/ghost/admin/app/controllers/settings/announcement-bar/index.js
Elena Baidakova f69674ff9a
Fixed announcement bar preview (#16715)
refs TryGhost/Team#3122
- Fixed that preview takes data from user input before saving on
backend.

---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 54d5b2d</samp>

This pull request adds the ability to preview the announcement bar in
the Ghost admin panel and the theme settings. It also adds a
confirmation dialog to discard or save unsaved changes before leaving
the announcement bar settings. It refactors some components and methods
to remove unnecessary or redundant calls to save the settings. It
modifies the `ghost_head` helper, the `theme-management` service, and
the `announcement-bar/src` files to support the preview feature.
2023-04-27 16:40:11 +04:00

63 lines
1.4 KiB
JavaScript

import Controller from '@ember/controller';
import {action} from '@ember/object';
import {inject} from 'ghost-admin/decorators/inject';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
export default class SettingsAnnouncementBarIndexController extends Controller {
@service customThemeSettings;
@service notifications;
@service settings;
@service themeManagement;
@inject config;
@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.errors.length !== 0) {
return;
}
yield Promise.all([
this.settings.save()
]);
// ensure task button switches to success state
return true;
} catch (error) {
if (error) {
this.notifications.showAPIError(error);
throw error;
}
}
}
reset() {
this.previewSize = 'desktop';
this.themeManagement.setPreviewType('homepage');
}
}