Skip to content

Commit

Permalink
Dont use the registry
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Aug 12, 2024
1 parent 95cd956 commit ca9a091
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/editor/src/components/start-page-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import { useSelect, useRegistry } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -35,12 +35,14 @@ export default function StartPageOptions() {
[]
);

const { setIsInserterOpened } = useDispatch( editorStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

useEffect( () => {
// Should reset the start page state when navigating to a new page/post.
setIsClosed( false );
}, [ postType, postId ] );

const registry = useRegistry();
// A pattern is a start pattern if it includes 'core/post-content' in its
// blockTypes, and it has no postTypes declared and the current post type is
// page or if the current post type is part of the postTypes declared.
Expand All @@ -55,11 +57,16 @@ export default function StartPageOptions() {
shouldEnableStartPage && ! isClosed && hasStarterPatterns;
useEffect( () => {
if ( showInserterOnNewPage ) {
registry.dispatch( editorStore ).setIsInserterOpened( {
setIsInserterOpened( {
tab: 'patterns',
category: 'core/content',
} );
__unstableSetEditorMode( 'zoom-out' );
}
}, [ showInserterOnNewPage, registry ] );
}, [
showInserterOnNewPage,
setIsInserterOpened,
__unstableSetEditorMode,
] );
return null;
}

0 comments on commit ca9a091

Please sign in to comment.