Skip to content

Commit

Permalink
isMenuBeingDeleted changed to selector
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz_marzencki committed Feb 24, 2021
1 parent 3236954 commit 41a4fab
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ export default function useNavigationEditor() {
);
const [ selectedMenuId, setSelectedMenuId ] = useState( null );
const [ isMenuDeleted, setIsMenuDeleted ] = useState( false );
const [ isMenuBeingDeleted, setIsMenuBeingDeleted ] = useState( false );
const isMenuBeingDeleted = useSelect(
( select ) =>
select( 'core' ).isDeletingEntityRecord(
'root',
'menu',
selectedMenuId
),
[ selectedMenuId ]
);

const { menus, hasLoadedMenus } = useSelect( ( select ) => {
const selectors = select( 'core' );
Expand Down Expand Up @@ -64,12 +72,10 @@ export default function useNavigationEditor() {
const { deleteMenu: _deleteMenu } = useDispatch( 'core' );

const deleteMenu = async () => {
setIsMenuBeingDeleted( true );
const didDeleteMenu = await _deleteMenu( selectedMenuId, {
force: true,
} );
if ( didDeleteMenu ) {
setIsMenuBeingDeleted( false );
setSelectedMenuId( null );
createInfoNotice( __( 'Menu deleted' ), {
type: 'snackbar',
Expand Down

0 comments on commit 41a4fab

Please sign in to comment.