Skip to content

Commit

Permalink
Move legacy meta boxes to toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 21, 2024
1 parent c4b422a commit c5a425c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 32 deletions.
8 changes: 8 additions & 0 deletions docs/reference-guides/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ _Returns_

- `boolean`: Whether the metaboxes are being saved.

### showMetaBoxes

Undocumented declaration.

<!-- END TOKEN(Autogenerated selectors|../../../packages/edit-post/src/store/selectors.js) -->

## Actions
Expand Down Expand Up @@ -522,6 +526,10 @@ _Parameters_

- _feature_ `string`: Feature name.

### toggleMetaBoxes

Undocumented declaration.

### togglePinnedPluginItem

Triggers an action object used to toggle a plugin name flag.
Expand Down
17 changes: 15 additions & 2 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
privateApis as editorPrivateApis,
} from '@wordpress/editor';
import { useEffect, useRef, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { next, previous } from '@wordpress/icons';
import { next, previous, box } from '@wordpress/icons';
import { PinnedItems } from '@wordpress/interface';
import { useViewportMatch } from '@wordpress/compose';
import {
Expand Down Expand Up @@ -63,6 +63,7 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
isTextEditor,
hasBlockSelection,
hasActiveMetaboxes,
showMetaBoxes,
hasFixedToolbar,
isPublishSidebarOpened,
showIconLabels,
Expand All @@ -76,6 +77,7 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
hasBlockSelection:
!! select( blockEditorStore ).getBlockSelectionStart(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
showMetaBoxes: select( editPostStore ).showMetaBoxes(),
hasHistory:
!! select( editorStore ).getEditorSettings()
.onNavigateToPreviousEntityRecord,
Expand All @@ -85,6 +87,7 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
showIconLabels: getPreference( 'core', 'showIconLabels' ),
};
}, [] );
const { toggleMetaBoxes } = useDispatch( editPostStore );

const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] =
useState( true );
Expand Down Expand Up @@ -187,6 +190,16 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
setEntitiesSavedStatesCallback
}
/>
{ hasActiveMetaboxes && (
<Button
icon={ box }
onClick={ () => {
toggleMetaBoxes();
} }
label={ __( 'Show meta boxes' ) }
isPressed={ showMetaBoxes }
/>
) }
{ ( isWideViewport || ! showIconLabels ) && (
<PinnedItems.Slot scope="core/edit-post" />
) }
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ function Layout( { initialPost } ) {

return {
showMetaBoxes:
select( editorStore ).getRenderingMode() === 'post-only',
select( editorStore ).getRenderingMode() === 'post-only' &&
select( editPostStore ).showMetaBoxes(),
sidebarIsOpened: !! (
select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
Expand Down
9 changes: 9 additions & 0 deletions packages/edit-post/src/components/layout/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
.edit-post-layout__metaboxes {
flex-shrink: 0;
clear: both;
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
background: $white;
z-index: 100;
padding: 20px;
box-sizing: border-box;
}

// Adjust the position of the notices
Expand Down
32 changes: 3 additions & 29 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
store as editorStore,
privateApis as editorPrivateApis,
} from '@wordpress/editor';
import { useMemo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

Expand All @@ -27,7 +26,6 @@ const isGutenbergPlugin = process.env.IS_GUTENBERG_PLUGIN ? true : false;
export default function VisualEditor( { styles } ) {
const {
isWelcomeGuideVisible,
renderingMode,
isBlockBasedTheme,
hasV3BlocksOnly,
isEditingTemplate,
Expand All @@ -48,35 +46,11 @@ export default function VisualEditor( { styles } ) {
select( editorStore ).getCurrentPostType() === 'wp_template',
};
}, [] );
const hasMetaBoxes = useSelect(
( select ) => select( editPostStore ).hasMetaBoxes(),
[]
);

let paddingBottom;

// Add a constant padding for the typewritter effect. When typing at the
// bottom, there needs to be room to scroll up.
if ( ! hasMetaBoxes && renderingMode === 'post-only' ) {
paddingBottom = '40vh';
}

styles = useMemo(
() => [
...styles,
{
// We should move this in to future to the body.
css: paddingBottom
? `body{padding-bottom:${ paddingBottom }}`
: '',
},
],
[ styles, paddingBottom ]
);

const isToBeIframed =
( ( hasV3BlocksOnly || ( isGutenbergPlugin && isBlockBasedTheme ) ) &&
! hasMetaBoxes ) ||
hasV3BlocksOnly ||
isGutenbergPlugin ||
isBlockBasedTheme ||
isEditingTemplate;

return (
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ export const initializeMetaBoxes =
} );
};

export function toggleMetaBoxes() {
return { type: 'TOGGLE_META_BOXES' };
}

/**
* Action that toggles Distraction free mode.
* Distraction free mode expects there are no sidebars, as due to the
Expand Down
9 changes: 9 additions & 0 deletions packages/edit-post/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,19 @@ function metaBoxesInitialized( state = false, action ) {
return state;
}

function showMetaBoxes( state = false, action ) {
switch ( action.type ) {
case 'TOGGLE_META_BOXES':
return ! state;
}
return state;
}

const metaBoxes = combineReducers( {
isSaving: isSavingMetaBoxes,
locations: metaBoxLocations,
initialized: metaBoxesInitialized,
showMetaBoxes,
} );

export default combineReducers( {
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ export function areMetaBoxesInitialized( state ) {
return state.metaBoxes.initialized;
}

export function showMetaBoxes( state ) {
return state.metaBoxes.showMetaBoxes;
}

/**
* Retrieves the template of the currently edited post.
*
Expand Down

0 comments on commit c5a425c

Please sign in to comment.