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

Editor: Remove useless props from InserterSidebar component #62103

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
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
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
Loading