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

Site Editor: Expose edit-site store #28722

Merged
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
14 changes: 12 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const interfaceLabels = {
drawer: __( 'Navigation Sidebar' ),
};

function Editor() {
function Editor( { initialSettings } ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate a sanity check from someone familiar with the edit site's editor initialization.

const {
isFullscreenActive,
isInserterOpen,
Expand Down Expand Up @@ -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 );
}, [] );

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

// Don't render the Editor until the settings are set and loaded
if ( ! settings?.siteUrl ) {
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

return (
<>
<URLQueryController />
Expand Down
9 changes: 5 additions & 4 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {} ) =>
Expand Down Expand Up @@ -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';
Expand Down
28 changes: 9 additions & 19 deletions packages/edit-site/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
3 changes: 0 additions & 3 deletions packages/edit-site/src/store/test/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Internal dependencies
*/
import registerEditSiteStore from '..';
import {
toggleFeature,
setTemplate,
Expand All @@ -13,8 +12,6 @@ import {
setHomeTemplateId,
} from '../actions';

registerEditSiteStore();

describe( 'actions', () => {
describe( 'toggleFeature', () => {
it( 'should return TOGGLE_FEATURE action', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import {
setIsNavigationPanelOpened,
setIsInserterOpened,
} from '../actions';
import registerEditSiteStore from '..';

registerEditSiteStore();

describe( 'state', () => {
describe( 'preferences()', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/store/test/selectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Internal dependencies
*/
import registerEditSiteStore from '..';
import {
isFeatureActive,
getCanUserCreateMedia,
Expand All @@ -15,8 +14,6 @@ import {
isInserterOpened,
} from '../selectors';

registerEditSiteStore();

describe( 'selectors', () => {
const canUser = jest.fn( () => true );
getCanUserCreateMedia.registry = {
Expand Down