Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose edit site store
Browse files Browse the repository at this point in the history
david-szabo97 committed Feb 4, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f7fc728 commit 938d27e
Showing 3 changed files with 26 additions and 25 deletions.
14 changes: 12 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ const interfaceLabels = {
drawer: __( 'Navigation Sidebar' ),
};

function Editor() {
function Editor( { initialSettings } ) {
const {
isFullscreenActive,
isInserterOpen,
@@ -94,7 +94,12 @@ function Editor() {
};
}, [] );
const { updateEditorSettings } = useDispatch( 'core/editor' );
const { setPage, setIsInserterOpened } = useDispatch( editSiteStore );
const { setPage, setIsInserterOpened, updateSettings } = useDispatch(
editSiteStore
);
useEffect( () => {
updateSettings( initialSettings );
}, [ initialSettings ] );

// Keep the defaultTemplateTypes in the core/editor settings too,
// so that they can be selected with core/editor selectors in any editor.
@@ -152,6 +157,11 @@ function Editor() {
onClose: () => setIsInserterOpened( false ),
} );

// Don't render the Editor until the settings are set and loaded
if ( ! settings?.siteUrl ) {
return null;
}

return (
<>
<URLQueryController />
9 changes: 5 additions & 4 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import { render } from '@wordpress/element';
*/
import './plugins';
import './hooks';
import registerEditSiteStore from './store';
import './store';
import Editor from './components/editor';

const fetchLinkSuggestions = ( search, { perPage = 20 } = {} ) =>
@@ -54,14 +54,15 @@ export function initialize( id, settings ) {
settings.__experimentalFetchLinkSuggestions = fetchLinkSuggestions;
settings.__experimentalSpotlightEntityBlocks = [ 'core/template-part' ];

registerEditSiteStore( { settings } );

registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks( true );
}

render( <Editor />, document.getElementById( id ) );
render(
<Editor initialSettings={ settings } />,
document.getElementById( id )
);
}

export { default as __experimentalMainDashboardButton } from './components/main-dashboard-button';
28 changes: 9 additions & 19 deletions packages/edit-site/src/store/index.js
Original file line number Diff line number Diff line change
@@ -12,24 +12,14 @@ import * as actions from './actions';
import * as selectors from './selectors';
import { STORE_NAME } from './constants';

export let store = null;
export const storeConfig = {
reducer,
actions,
selectors,
controls,
persist: [ 'preferences' ],
};

export default function registerEditSiteStore( initialState ) {
if ( store !== null ) {
return;
}
export const store = createReduxStore( STORE_NAME, storeConfig );

const _store = createReduxStore( STORE_NAME, {
reducer,
actions,
selectors,
controls,
persist: [ 'preferences' ],
initialState,
} );
register( _store );

store = _store;

return _store;
}
register( store );

0 comments on commit 938d27e

Please sign in to comment.