Skip to content

Commit

Permalink
Editor: Remove uselss props from InserterSidebar component (WordPress…
Browse files Browse the repository at this point in the history
…#62103)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
3 people authored and carstingaxion committed Jun 4, 2024
1 parent 0deafae commit 5d0e996
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 38 deletions.
23 changes: 5 additions & 18 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function Layout( { initialPost } ) {
const isWideViewport = useViewportMatch( 'large' );
const isLargeViewport = useViewportMatch( 'medium' );

const { closeGeneralSidebar } = useDispatch( editPostStore );
const { createErrorNotice } = useDispatch( noticesStore );
const {
mode,
Expand Down Expand Up @@ -244,22 +243,6 @@ function Layout( { initialPost } ) {
? __( 'Document Overview' )
: __( 'Block Library' );

const secondarySidebar = () => {
if ( mode === 'visual' && isInserterOpened ) {
return (
<InserterSidebar
closeGeneralSidebar={ closeGeneralSidebar }
isRightSidebarOpen={ sidebarIsOpened }
/>
);
}
if ( mode === 'visual' && isListViewOpened ) {
return <ListViewSidebar />;
}

return null;
};

function onPluginAreaError( name ) {
createErrorNotice(
sprintf(
Expand Down Expand Up @@ -351,7 +334,11 @@ function Layout( { initialPost } ) {
/>
}
editorNotices={ <EditorNotices /> }
secondarySidebar={ secondarySidebar() }
secondarySidebar={
mode === 'visual' &&
( ( isInserterOpened && <InserterSidebar /> ) ||
( isListViewOpened && <ListViewSidebar /> ) )
}
sidebar={
! isDistractionFree && (
<ComplementaryArea.Slot scope="core" />
Expand Down
13 changes: 1 addition & 12 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const {
ListViewSidebar,
InterfaceSkeleton,
ComplementaryArea,
interfaceStore,
SavePublishPanels,
Sidebar,
TextEditor,
Expand Down Expand Up @@ -101,7 +100,6 @@ export default function Editor( { isLoading } ) {
editorMode,
canvasMode,
blockEditorMode,
isRightSidebarOpen,
isInserterOpen,
isListViewOpen,
isDistractionFree,
Expand All @@ -116,7 +114,6 @@ export default function Editor( { isLoading } ) {
select( editSiteStore )
);
const { __unstableGetEditorMode } = select( blockEditorStore );
const { getActiveComplementaryArea } = select( interfaceStore );
const { getEntityRecord, getCurrentTheme } = select( coreDataStore );
const {
isInserterOpened,
Expand All @@ -142,7 +139,6 @@ export default function Editor( { isLoading } ) {
blockEditorMode: __unstableGetEditorMode(),
isInserterOpen: isInserterOpened(),
isListViewOpen: isListViewOpened(),
isRightSidebarOpen: getActiveComplementaryArea( 'core' ),
isDistractionFree: get( 'core', 'distractionFree' ),
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
showIconLabels: get( 'core', 'showIconLabels' ),
Expand Down Expand Up @@ -188,8 +184,6 @@ export default function Editor( { isLoading } ) {
'edit-site-editor__loading-progress'
);

const { closeGeneralSidebar } = useDispatch( editSiteStore );

const settings = useSpecificEditorSettings();

// Local state for save panel.
Expand Down Expand Up @@ -357,12 +351,7 @@ export default function Editor( { isLoading } ) {
}
secondarySidebar={
isEditMode &&
( ( shouldShowInserter && (
<InserterSidebar
closeGeneralSidebar={ closeGeneralSidebar }
isRightSidebarOpen={ isRightSidebarOpen }
/>
) ) ||
( ( shouldShowInserter && <InserterSidebar /> ) ||
( shouldShowListView && <ListViewSidebar /> ) )
}
sidebar={
Expand Down
24 changes: 16 additions & 8 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { useCallback, useRef } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';
import { ESCAPE } from '@wordpress/keycodes';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand All @@ -22,22 +23,23 @@ import { store as editorStore } from '../../store';

const { PrivateInserterLibrary } = unlock( blockEditorPrivateApis );

export default function InserterSidebar( {
closeGeneralSidebar,
isRightSidebarOpen,
} ) {
export default function InserterSidebar() {
const {
blockSectionRootClientId,
inserterSidebarToggleRef,
insertionPoint,
showMostUsedBlocks,
sidebarIsOpened,
} = useSelect( ( select ) => {
const { getInserterSidebarToggleRef, getInsertionPoint } = unlock(
select( editorStore )
);
const {
getInserterSidebarToggleRef,
getInsertionPoint,
isPublishSidebarOpened,
} = unlock( select( editorStore ) );
const { getBlockRootClientId, __unstableGetEditorMode, getSettings } =
select( blockEditorStore );
const { get } = select( preferencesStore );
const { getActiveComplementaryArea } = select( interfaceStore );
const getBlockSectionRootClientId = () => {
if ( __unstableGetEditorMode() === 'zoom-out' ) {
const { sectionRootClientId } = unlock( getSettings() );
Expand All @@ -52,9 +54,13 @@ export default function InserterSidebar( {
insertionPoint: getInsertionPoint(),
showMostUsedBlocks: get( 'core', 'mostUsedBlocks' ),
blockSectionRootClientId: getBlockSectionRootClientId(),
sidebarIsOpened: !! (
getActiveComplementaryArea( 'core' ) || isPublishSidebarOpened()
),
};
}, [] );
const { setIsInserterOpened } = useDispatch( editorStore );
const { disableComplementaryArea } = useDispatch( interfaceStore );

const isMobileViewport = useViewportMatch( 'medium', '<' );
const [ inserterDialogRef, inserterDialogProps ] = useDialog( {
Expand Down Expand Up @@ -93,7 +99,9 @@ export default function InserterSidebar( {
__experimentalInitialCategory={ insertionPoint.category }
__experimentalFilterValue={ insertionPoint.filterValue }
onPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
sidebarIsOpened
? () => disableComplementaryArea( 'core' )
: undefined
}
ref={ libraryRef }
onClose={ closeInserterSidebar }
Expand Down

0 comments on commit 5d0e996

Please sign in to comment.