Skip to content

Commit

Permalink
Refactor rendering mode management in editor provider and store and p…
Browse files Browse the repository at this point in the history
…ersist it
  • Loading branch information
yogeshbhutkar committed Dec 24, 2024
1 parent 0fb8403 commit 20e49de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
15 changes: 12 additions & 3 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,17 @@ export const ExperimentalEditorProvider = withRegistryProvider(
coreStore
).hasFinishedResolution( 'getPostType', [ post.type ] );

const renderingMode = getRenderingMode();

return {
hasLoadedPostObject: _hasLoadedPostObject,
editorSettings: getEditorSettings(),
isReady: __unstableIsEditorReady(),
mode: getRenderingMode(),
mode: renderingMode,
defaultMode:
postTypeObject?.default_rendering_mode ?? 'post-only',
renderingMode ??
postTypeObject?.default_rendering_mode ??
'post-only',
selection: getEditorSelection(),
postTypeEntities:
post.type === 'wp_template'
Expand Down Expand Up @@ -327,8 +331,13 @@ export const ExperimentalEditorProvider = withRegistryProvider(

// Sets the right rendering mode when loading the editor.
useEffect( () => {
// If mode equals default mode, rendering mode is already set appropriately.
if ( mode === defaultMode ) {
return;
}

setRenderingMode( defaultMode );
}, [ defaultMode, setRenderingMode ] );
}, [ mode, defaultMode, setRenderingMode ] );

useHideBlocksFromInserter( post.type, mode );

Expand Down
7 changes: 3 additions & 4 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,9 @@ export const setRenderingMode =
dispatch.editPost( { selection: undefined }, { undoIgnore: true } );
}

dispatch( {
type: 'SET_RENDERING_MODE',
mode,
} );
registry
.dispatch( preferencesStore )
.set( 'core', 'renderingMode', mode );
};

/**
Expand Down
10 changes: 0 additions & 10 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,6 @@ export function editorSettings( state = EDITOR_SETTINGS_DEFAULTS, action ) {
return state;
}

export function renderingMode( state = 'post-only', action ) {
switch ( action.type ) {
case 'SET_RENDERING_MODE':
return action.mode;
}

return state;
}

/**
* Reducer returning the editing canvas device type.
*
Expand Down Expand Up @@ -395,7 +386,6 @@ export default combineReducers( {
postSavingLock,
editorSettings,
postAutosavingLock,
renderingMode,
deviceType,
removedPanels,
blockInserterPanel,
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,9 @@ export function getEditorSettings( state ) {
*
* @return {string} Rendering mode.
*/
export function getRenderingMode( state ) {
return state.renderingMode;
}
export const getRenderingMode = createRegistrySelector( ( select ) => () => {
return select( preferencesStore ).get( 'core', 'renderingMode' );
} );

/**
* Returns the current editing canvas device type.
Expand Down

0 comments on commit 20e49de

Please sign in to comment.