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

Show Template: Refactor rendering mode management in editor provider and store to persist it #68257

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
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
Loading