Skip to content

Commit

Permalink
Check previewId aka deviceType directly in child component
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed May 24, 2021
1 parent 5a93322 commit d7c329e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
9 changes: 1 addition & 8 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function Layout( { styles } ) {
showIconLabels,
hasReducedUI,
showBlockBreadcrumbs,
previewId,
} = useSelect( ( select ) => {
const editorSettings = select( editorStore ).getEditorSettings();
return {
Expand Down Expand Up @@ -122,9 +121,6 @@ function Layout( { styles } ) {
showBlockBreadcrumbs: select( editPostStore ).isFeatureActive(
'showBlockBreadcrumbs'
),
previewId: select(
editPostStore
).__experimentalGetPreviewDeviceType(),
};
}, [] );
const className = classnames( 'edit-post-layout', 'is-mode-' + mode, {
Expand Down Expand Up @@ -229,10 +225,7 @@ function Layout( { styles } ) {
<TextEditor />
) }
{ isRichEditingEnabled && mode === 'visual' && (
<VisualEditorOrPluginPreview
styles={ styles }
previewId={ previewId }
/>
<VisualEditorOrPluginPreview styles={ styles } />
) }
<div className="edit-post-layout__metaboxes">
<MetaBoxes location="normal" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@
* WordPress dependencies
*/
import { __experimentalUseSlot as useSlot, Slot } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import VisualEditor from './index';
import { store as editPostStore } from '../../store';

/**
* Component that renders a preview slot fill if found or a VisualEditor instead.
*
* @param {Object} props Component properties.
* @param {string} props.previewId The internal name of this custom preview.
* @param {Object} props Component properties.
*/
function VisualEditorOrPluginPreview( { previewId, ...props } ) {
function VisualEditorOrPluginPreview( props ) {
const previewId = useSelect(
( select ) =>
select( editPostStore ).__experimentalGetPreviewDeviceType(),
[]
);
const slotName = `core/block-editor/plugin-preview/${ previewId }`;
const slot = useSlot( slotName );

if ( slot?.fills?.length === 0 ) {
return <VisualEditor { ...props } />;
if ( slot?.fills?.length > 0 ) {
return <Slot name={ slotName } fillProps={ props } />;
}

return <Slot name={ slotName } fillProps={ props } />;
return <VisualEditor { ...props } />;
}
export default VisualEditorOrPluginPreview;

0 comments on commit d7c329e

Please sign in to comment.