Skip to content

Commit

Permalink
Navigation Editor: Indicate unsaved changes (#31119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored May 5, 2021
1 parent d3fabc0 commit 42c5fcd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/edit-navigation/src/components/header/save-button.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
/**
* WordPress dependencies
*/
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { store as editNavigationStore } from '../../store';

export default function SaveButton( { navigationPost } ) {
const { isDirty } = useSelect( ( select ) => {
const { __experimentalGetDirtyEntityRecords } = select( coreStore );
const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();

return {
isDirty: dirtyEntityRecords.length > 0,
};
}, [] );

const { saveNavigationPost } = useDispatch( editNavigationStore );

const disabled = ! isDirty || ! navigationPost;

return (
<Button
className="edit-navigation-toolbar__save-button"
isPrimary
onClick={ () => {
saveNavigationPost( navigationPost );
} }
disabled={ ! navigationPost }
disabled={ disabled }
>
{ __( 'Save' ) }
</Button>
Expand Down

0 comments on commit 42c5fcd

Please sign in to comment.