Skip to content

Commit

Permalink
Save panel only visible when there are unsaved changes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 2, 2023
1 parent 572df8c commit ad7c0ba
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/edit-site/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* WordPress dependencies
*/
import { memo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { __experimentalNavigatorProvider as NavigatorProvider } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -27,6 +29,16 @@ function SidebarScreens() {
}

function Sidebar() {
const { isDirty } = useSelect( ( select ) => {
const { __experimentalGetDirtyEntityRecords } = select( coreStore );
const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
// The currently selected entity to display.
// Typically template or template part in the site editor.
return {
isDirty: dirtyEntityRecords.length > 0,
};
}, [] );

return (
<>
<NavigatorProvider
Expand All @@ -35,9 +47,11 @@ function Sidebar() {
>
<SidebarScreens />
</NavigatorProvider>
<div className="edit-site-sidebar__footer">
<SaveButton />
</div>
{ isDirty && (
<div className="edit-site-sidebar__footer">
<SaveButton />
</div>
) }
</>
);
}
Expand Down

0 comments on commit ad7c0ba

Please sign in to comment.