Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav Browse mode remove "ghost" Nav block #50847

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useCallback, useMemo } from '@wordpress/element';
import { useCallback } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { BlockEditorProvider } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import {
store as coreStore,
EntityProvider,
useEntityBlockEditor,
} from '@wordpress/core-data';

import { privateApis as routerPrivateApis } from '@wordpress/router';
import { BlockEditorProvider } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -23,7 +27,6 @@ import {

const { useHistory } = unlock( routerPrivateApis );

const noop = () => {};
const NAVIGATION_MENUS_QUERY = {
per_page: 1,
status: 'publish',
Expand Down Expand Up @@ -68,11 +71,14 @@ export default function SidebarNavigationScreenNavigationMenus() {
}, [] );

const firstNavigationMenu = navigationMenus?.[ 0 ]?.id;
const blocks = useMemo( () => {
return [
createBlock( 'core/navigation', { ref: firstNavigationMenu } ),
];
}, [ firstNavigationMenu ] );

const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'postType',
'wp_navigation',
{
id: firstNavigationMenu,
}
);

const hasNavigationMenus = !! navigationMenus?.length;

Expand Down Expand Up @@ -115,20 +121,26 @@ export default function SidebarNavigationScreenNavigationMenus() {
}

return (
<BlockEditorProvider
settings={ storedSettings }
value={ blocks }
onChange={ noop }
onInput={ noop }
<EntityProvider
kind="postType"
type="wp_navigation"
id={ firstNavigationMenu }
>
<SidebarNavigationScreenWrapper>
<div className="edit-site-sidebar-navigation-screen-navigation-menus__content">
<NavigationMenuContent
rootClientId={ blocks[ 0 ].clientId }
onSelect={ onSelect }
/>
</div>
</SidebarNavigationScreenWrapper>
</BlockEditorProvider>
<BlockEditorProvider
settings={ storedSettings }
value={ blocks }
onChange={ onChange }
onInput={ onInput }
>
<SidebarNavigationScreenWrapper>
<div className="edit-site-sidebar-navigation-screen-navigation-menus__content">
<NavigationMenuContent
rootClientId={ blocks[ 0 ]?.clientId }
onSelect={ onSelect }
/>
</div>
</SidebarNavigationScreenWrapper>
</BlockEditorProvider>
</EntityProvider>
);
}