From 0e8039b0acc962ae72b014eaafe1ab489b187b15 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 26 Jun 2024 10:42:07 +0300 Subject: [PATCH] Editor: Fix duplicate save panels --- .../edit-site/src/components/editor/index.js | 6 +++ .../edit-site/src/components/layout/index.js | 3 -- .../src/components/editor-interface/index.js | 5 +- .../components/save-publish-panels/index.js | 53 +++++++++++-------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index 85a9a428fe2f2f..ac26cd16233630 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -40,6 +40,7 @@ import { useHasEditorCanvasContainer, } from '../editor-canvas-container'; import SaveButton from '../save-button'; +import SavePanel from '../save-panel'; import SiteEditorMoreMenu from '../more-menu'; import SiteIcon from '../site-icon'; import useEditorIframeProps from '../block-editor/use-editor-iframe-props'; @@ -199,6 +200,11 @@ export default function EditSiteEditor( { isLoading } ) { customSaveButton={ _isPreviewingTheme && } + customSavePanel={ + ( _isPreviewingTheme || canvasMode === 'view' ) && ( + + ) + } forceDisableBlockTools={ ! hasDefaultEditorCanvasView } title={ title } icon={ icon } diff --git a/packages/edit-site/src/components/layout/index.js b/packages/edit-site/src/components/layout/index.js index 72d48122057ac9..06328443800d28 100644 --- a/packages/edit-site/src/components/layout/index.js +++ b/packages/edit-site/src/components/layout/index.js @@ -37,7 +37,6 @@ import { store as editSiteStore } from '../../store'; import SiteHub from '../site-hub'; import ResizableFrame from '../resizable-frame'; import { unlock } from '../../lock-unlock'; -import SavePanel from '../save-panel'; import KeyboardShortcutsRegister from '../keyboard-shortcuts/register'; import KeyboardShortcutsGlobal from '../keyboard-shortcuts/global'; import { useIsSiteEditorLoading } from './hooks'; @@ -236,8 +235,6 @@ export default function Layout( { route } ) { ) } - - ); diff --git a/packages/editor/src/components/editor-interface/index.js b/packages/editor/src/components/editor-interface/index.js index 88ac950c4ae229..5ea54185542f7c 100644 --- a/packages/editor/src/components/editor-interface/index.js +++ b/packages/editor/src/components/editor-interface/index.js @@ -55,6 +55,7 @@ export default function EditorInterface( { disableIframe, autoFocus, customSaveButton, + customSavePanel, forceDisableBlockTools, title, icon, @@ -214,7 +215,7 @@ export default function EditorInterface( { ) } actions={ - ! isPreviewMode ? ( + customSavePanel || ( - ) : undefined + ) } shortcuts={ { previous: previousShortcut, diff --git a/packages/editor/src/components/save-publish-panels/index.js b/packages/editor/src/components/save-publish-panels/index.js index 3ae871c354bb62..2f1c820b0d53d9 100644 --- a/packages/editor/src/components/save-publish-panels/index.js +++ b/packages/editor/src/components/save-publish-panels/index.js @@ -28,20 +28,25 @@ export default function SavePublishPanels( { } ) { const { closePublishSidebar, togglePublishSidebar } = useDispatch( editorStore ); - const { - publishSidebarOpened, - hasNonPostEntityChanges, - hasPostMetaChanges, - } = useSelect( - ( select ) => ( { - publishSidebarOpened: - select( editorStore ).isPublishSidebarOpened(), - hasNonPostEntityChanges: - select( editorStore ).hasNonPostEntityChanges(), - hasPostMetaChanges: unlock( - select( editorStore ) - ).hasPostMetaChanges(), - } ), + const { publishSidebarOpened, isPublishable, isDirty } = useSelect( + ( select ) => { + const { + isPublishSidebarOpened, + isEditedPostPublishable, + isCurrentPostPublished, + isEditedPostDirty, + hasNonPostEntityChanges: _hasNonPostEntityChanges, + } = select( editorStore ); + return { + publishSidebarOpened: isPublishSidebarOpened(), + isPublishable: + ! isCurrentPostPublished() && isEditedPostPublishable(), + isDirty: + _hasNonPostEntityChanges() || + isEditedPostDirty() || + unlock( select( editorStore ) ).hasPostMetaChanges(), + }; + }, [] ); @@ -62,29 +67,31 @@ export default function SavePublishPanels( { PostPublishExtension={ PluginPostPublishPanel.Slot } /> ); - } else if ( hasNonPostEntityChanges || hasPostMetaChanges ) { + } else if ( isPublishable ) { unmountableContent = ( -
+
); } else { unmountableContent = ( -
+
);