Skip to content

Commit

Permalink
Migrate editor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Mar 3, 2022
1 parent 5225a66 commit b4ba612
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 45 deletions.
1 change: 1 addition & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function reinitializeEditor( target, settings ) {
// so that we won't trigger unnecessary re-renders with useEffect.
{
dispatch( preferencesStore ).setDefaults( 'core/edit-site', {
editorMode: 'visual',
fixedToolbar: false,
focusMode: false,
welcomeGuide: true,
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-site/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,10 @@ export const closeGeneralSidebar = () => ( { registry } ) => {
.disableComplementaryArea( editSiteStoreName );
};

export const switchEditorMode = ( mode ) => ( { dispatch, registry } ) => {
dispatch( { type: 'SWITCH_MODE', mode } );
export const switchEditorMode = ( mode ) => ( { registry } ) => {
registry
.dispatch( 'core/preferences' )
.set( 'core/edit-site', 'editorMode', mode );

// Unselect blocks when we switch to a non visual mode.
if ( mode !== 'visual' ) {
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/store/defaults.js

This file was deleted.

8 changes: 2 additions & 6 deletions packages/edit-site/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { createReduxStore, registerStore } from '@wordpress/data';
import { createReduxStore, register } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -15,11 +15,7 @@ export const storeConfig = {
reducer,
actions,
selectors,
persist: [ 'preferences' ],
};

export const store = createReduxStore( STORE_NAME, storeConfig );

// Once we build a more generic persistence plugin that works across types of stores
// we'd be able to replace this with a register call.
registerStore( STORE_NAME, storeConfig );
register( store );
30 changes: 0 additions & 30 deletions packages/edit-site/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,8 @@ import { combineReducers } from '@wordpress/data';
/**
* Internal dependencies
*/
import { PREFERENCES_DEFAULTS } from './defaults';
import { MENU_ROOT } from '../components/navigation-sidebar/navigation-panel/constants';

/**
* Reducer returning the user preferences.
*
* @param {Object} state Current state.
* @param {Object} action Dispatched action.
* @return {Object} Updated state.
*/
export const preferences = combineReducers( {
features( state = PREFERENCES_DEFAULTS.features, action ) {
switch ( action.type ) {
case 'TOGGLE_FEATURE': {
return {
...state,
[ action.feature ]: ! state[ action.feature ],
};
}
default:
return state;
}
},
editorMode( state = PREFERENCES_DEFAULTS.editorMode, action ) {
if ( action.type === 'SWITCH_MODE' ) {
return action.mode;
}
return state;
},
} );

/**
* Reducer returning the editing canvas device type.
*
Expand Down Expand Up @@ -213,7 +184,6 @@ export function listViewPanel( state = false, action ) {
}

export default combineReducers( {
preferences,
deviceType,
settings,
editedPost,
Expand Down
6 changes: 2 additions & 4 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,8 @@ export const getCurrentTemplateTemplateParts = createRegistrySelector(
/**
* Returns the current editing mode.
*
* @param {Object} state Global application state.
*
* @return {string} Editing mode.
*/
export function getEditorMode( state ) {
return state.preferences.editorMode || 'visual';
export function getEditorMode() {
return getPreference( 'editorMode' );
}

0 comments on commit b4ba612

Please sign in to comment.