- { __( 'There are no Navigation Menus.' ) } -
- ) } - - { ! hasResolvedNavigationMenus && ( - - ) } - { isLoading && ( - <> - - - - > - ) } - { hasInnerBlocks && ! isLoading && ( -- { __( 'Navigation Menu is empty.' ) } -
- ) } -+ { __( + 'Browse your site, edit pages, and manage your primary navigation menu.' + ) } +
+ { children } + > + } + /> + ); +} export default function SidebarNavigationScreenNavigationMenus() { const history = useHistory(); + const { navigationMenus, hasResolvedNavigationMenus } = useSelect( + ( select ) => { + const { getEntityRecords, hasFinishedResolution } = + select( coreStore ); + + const navigationMenusQuery = [ + 'postType', + 'wp_navigation', + NAVIGATION_MENUS_QUERY, + ]; + return { + navigationMenus: getEntityRecords( ...navigationMenusQuery ), + hasResolvedNavigationMenus: hasFinishedResolution( + 'getEntityRecords', + navigationMenusQuery + ), + }; + }, + [] + ); + + // Sort navigation menus by date. + const orderedNavigationMenus = useMemo( + () => + navigationMenus?.sort( ( menuA, menuB ) => { + const menuADate = new Date( menuA.date ); + const menuBDate = new Date( menuB.date ); + return menuADate.getTime() > menuBDate.getTime(); + } ), + [ navigationMenus ] + ); + const firstNavigationMenu = orderedNavigationMenus?.[ 0 ]?.id; + const blocks = useMemo( () => { + return [ + createBlock( 'core/navigation', { ref: firstNavigationMenu } ), + ]; + }, [ firstNavigationMenu ] ); + + const isLoading = ! hasResolvedNavigationMenus; + const hasNavigationMenus = !! navigationMenus?.length; + const onSelect = useCallback( ( selectedBlock ) => { const { attributes, name } = selectedBlock; @@ -36,14 +105,52 @@ export default function SidebarNavigationScreenNavigationMenus() { }, [ history ] ); + + if ( hasResolvedNavigationMenus && ! hasNavigationMenus ) { + return ( +