Skip to content

Commit

Permalink
restore code from bad refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian authored and jeryj committed May 10, 2024
1 parent d0a77b1 commit 6da1734
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { __experimentalLibrary as Library } from '@wordpress/block-editor';
import {
__experimentalLibrary as Library,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useViewportMatch } from '@wordpress/compose';
import { useCallback, useRef } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';
import { ESCAPE } from '@wordpress/keycodes';

/**
* Internal dependencies
*/
Expand All @@ -17,18 +21,34 @@ export default function InserterSidebar( {
closeGeneralSidebar,
isRightSidebarOpen,
} ) {
const { inserterSidebarToggleRef, insertionPoint, showMostUsedBlocks } =
useSelect( ( select ) => {
const { getInserterSidebarToggleRef, getInsertionPoint } = unlock(
select( editorStore )
);
const { get } = select( preferencesStore );
return {
inserterSidebarToggleRef: getInserterSidebarToggleRef(),
insertionPoint: getInsertionPoint(),
showMostUsedBlocks: get( 'core', 'mostUsedBlocks' ),
};
}, [] );
const {
blockSectionRootClientId,
inserterSidebarToggleRef,
insertionPoint,
showMostUsedBlocks,
} = useSelect( ( select ) => {
const { getInserterSidebarToggleRef, getInsertionPoint } = unlock(
select( editorStore )
);
const { getBlockRootClientId, __unstableGetEditorMode, getSettings } =
select( blockEditorStore );
const { get } = select( preferencesStore );
const getBlockSectionRootClientId = () => {
if ( __unstableGetEditorMode() === 'zoom-out' ) {
const { sectionRootClientId } = unlock( getSettings() );
if ( sectionRootClientId ) {
return sectionRootClientId;
}
}
return getBlockRootClientId();
};
return {
inserterSidebarToggleRef: getInserterSidebarToggleRef(),
insertionPoint: getInsertionPoint(),
showMostUsedBlocks: get( 'core', 'mostUsedBlocks' ),
blockSectionRootClientId: getBlockSectionRootClientId(),
};
}, [] );
const { setIsInserterOpened } = useDispatch( editorStore );

const isMobileViewport = useViewportMatch( 'medium', '<' );
Expand Down Expand Up @@ -58,7 +78,9 @@ export default function InserterSidebar( {
showMostUsedBlocks={ showMostUsedBlocks }
showInserterHelpPanel
shouldFocusBlock={ isMobileViewport }
rootClientId={ insertionPoint.rootClientId }
rootClientId={
blockSectionRootClientId ?? insertionPoint.rootClientId
}
__experimentalInsertionIndex={
insertionPoint.insertionIndex
}
Expand Down

0 comments on commit 6da1734

Please sign in to comment.