From 150f4fda2d8488d101e12151a4154a4365c2603c Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 13 May 2022 17:43:14 +0100 Subject: [PATCH] Remember post preview tab when switching between preview/publish refs https://github.com/TryGhost/Team/issues/1621 - added `currentTab` and `changeTab()` data arguments to preview modal allowing for the current tab to be remembered across opens in the `` component that controls open/close of the preview modal --- .../app/components/editor-labs/modals/preview.js | 3 ++- .../app/components/editor-labs/publish-management.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ghost/admin/app/components/editor-labs/modals/preview.js b/ghost/admin/app/components/editor-labs/modals/preview.js index 4e2ae25f4a..c011a99154 100644 --- a/ghost/admin/app/components/editor-labs/modals/preview.js +++ b/ghost/admin/app/components/editor-labs/modals/preview.js @@ -14,7 +14,7 @@ export default class EditorPostPreviewModal extends Component { ignoreBackdropClick: true }; - @tracked tab = 'browser'; + @tracked tab = this.args.data.currentTab || 'browser'; constructor() { super(...arguments); @@ -24,6 +24,7 @@ export default class EditorPostPreviewModal extends Component { @action changeTab(tab) { this.tab = tab; + this.args.data.changeTab?.(tab); } @task diff --git a/ghost/admin/app/components/editor-labs/publish-management.js b/ghost/admin/app/components/editor-labs/publish-management.js index b7d1fc1b7b..b10e7efa11 100644 --- a/ghost/admin/app/components/editor-labs/publish-management.js +++ b/ghost/admin/app/components/editor-labs/publish-management.js @@ -9,6 +9,7 @@ import {action} from '@ember/object'; import {capitalize} from '@ember/string'; import {inject as service} from '@ember/service'; import {task, taskGroup, timeout} from 'ember-concurrency'; +import {tracked} from '@glimmer/tracking'; import {use} from 'ember-could-get-used-to-this'; const SHOW_SAVE_STATUS_DURATION = 3000; @@ -26,6 +27,8 @@ export default class PublishManagement extends Component { // ensure we get a new PublishOptions instance when @post is replaced @use publishOptions = new PublishOptionsResource(() => [this.args.post]); + @tracked previewTab = 'browser'; + publishFlowModal = null; updateFlowModal = null; @@ -88,11 +91,18 @@ export default class PublishManagement extends Component { post: this.publishOptions.post, hasDirtyAttributes: this.args.hasUnsavedChanges, saveTask: this.saveTask, - togglePreviewPublish: this.togglePreviewPublish + togglePreviewPublish: this.togglePreviewPublish, + currentTab: this.previewTab, + changeTab: this.changePreviewTab }); } } + @action + changePreviewTab(tab) { + this.previewTab = tab; + } + @action async togglePreviewPublish(event) { event?.preventDefault();