Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move dispatch to initialize editor methods to avoid unnecessary re-re…
…nders using useEffect
  • Loading branch information
ramonjd committed May 4, 2022
commit 48fe306a19786713d26afa1846dd139a1c4b2204
12 changes: 0 additions & 12 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function Layout( { styles } ) {
setIsInserterOpened,
} = useDispatch( editPostStore );
const { createErrorNotice } = useDispatch( noticesStore );
const { setIsListViewOpened } = useDispatch( editPostStore );
const {
mode,
isFullscreenActive,
Expand All @@ -90,7 +89,6 @@ function Layout( { styles } ) {
showBlockBreadcrumbs,
isTemplateMode,
documentLabel,
isListViewOpenByDefault,
} = useSelect( ( select ) => {
const { getEditorSettings, getPostTypeLabel } = select( editorStore );
const editorSettings = getEditorSettings();
Expand Down Expand Up @@ -131,9 +129,6 @@ function Layout( { styles } ) {
),
// translators: Default label for the Document in the Block Breadcrumb.
documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
isListViewOpenByDefault: select( editPostStore ).isFeatureActive(
'showListViewByDefault'
),
};
}, [] );
const className = classnames( 'edit-post-layout', 'is-mode-' + mode, {
Expand All @@ -147,13 +142,6 @@ function Layout( { styles } ) {
hasBlockSelected ? 'edit-post/block' : 'edit-post/document'
);

// Check if the block list view should be open by default.
useEffect( () => {
if ( isListViewOpenByDefault ) {
setIsListViewOpened( true );
}
}, [] );

// Inserter and Sidebars are mutually exclusive
useEffect( () => {
if ( sidebarIsOpened && ! isHugeViewport ) {
Expand Down
6 changes: 6 additions & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export function initializeEditor(
} );

dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();

// Check if the block list view should be open by default.
if ( select( editPostStore ).isFeatureActive( 'showListViewByDefault' ) ) {
dispatch( editPostStore ).setIsListViewOpened( true );
}

registerCoreBlocks();
if ( process.env.IS_GUTENBERG_PLUGIN ) {
__experimentalRegisterExperimentalCoreBlocks( {
Expand Down
16 changes: 1 addition & 15 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function Editor( { onError } ) {
nextShortcut,
editorMode,
showIconLabels,
isListViewOpenByDefault,
} = useSelect( ( select ) => {
const {
isInserterOpened,
Expand Down Expand Up @@ -115,15 +114,9 @@ function Editor( { onError } ) {
'core/edit-site',
'showIconLabels'
),
isListViewOpenByDefault: select( preferencesStore ).get(
'core/edit-site',
'showListViewByDefault'
),
};
}, [] );
const { setPage, setIsInserterOpened, setIsListViewOpened } = useDispatch(
editSiteStore
);
const { setPage, setIsInserterOpened } = useDispatch( editSiteStore );
const { enableComplementaryArea } = useDispatch( interfaceStore );

const [
Expand Down Expand Up @@ -159,13 +152,6 @@ function Editor( { onError } ) {
[ page?.context ]
);

// Check if the block list view should be open by default.
useEffect( () => {
if ( isListViewOpenByDefault ) {
setIsListViewOpened( true );
}
}, [] );

useEffect( () => {
if ( isNavigationOpen ) {
document.body.classList.add( 'is-navigation-sidebar-open' );
Expand Down
11 changes: 11 additions & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,19 @@ export function reinitializeEditor( target, settings ) {
keepCaretInsideBlock: false,
welcomeGuide: true,
welcomeGuideStyles: true,
shouldListViewOpenByDefault: false,
} );

// Check if the block list view should be open by default.
if (
select( preferencesStore ).get(
'core/edit-site',
'showListViewByDefault'
)
) {
dispatch( editSiteStore ).setIsListViewOpened( true );
}

dispatch( editSiteStore ).updateSettings( settings );

// Keep the defaultTemplateTypes in the core/editor settings too,
Expand Down