Skip to content

Commit

Permalink
Edit Site: Use useEntityBlockEditor.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Jan 15, 2020
1 parent 063f663 commit 0335169
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import { useSelect } from '@wordpress/data';
import { useMemo, useCallback } from '@wordpress/element';
import { uploadMedia } from '@wordpress/media-utils';
import { useEntityProp } from '@wordpress/core-data';
import { parse, serialize } from '@wordpress/blocks';
import { useEntityBlockEditor } from '@wordpress/core-data';
import {
BlockEditorProvider,
BlockEditorKeyboardShortcuts,
Expand Down Expand Up @@ -45,28 +44,9 @@ export default function BlockEditor() {
},
};
}, [ canUserCreateMedia, _settings ] );
const [ content, _setContent ] = useEntityProp(
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'postType',
settings.templateType,
'content'
);
const initialBlocks = useMemo( () => {
if ( typeof content !== 'function' ) {
const parsedContent = parse( content );
return parsedContent.length ? parsedContent : [];
}
}, [ settings.templateId ] );
const [ blocks = initialBlocks, setBlocks ] = useEntityProp(
'postType',
settings.templateType,
'blocks'
);
const setContent = useCallback(
( nextBlocks ) => {
setBlocks( nextBlocks );
_setContent( serialize( nextBlocks ) );
},
[ setBlocks, _setContent ]
settings.templateType
);
const setActiveTemplateId = useCallback(
( newTemplateId ) =>
Expand All @@ -81,8 +61,8 @@ export default function BlockEditor() {
<BlockEditorProvider
settings={ settings }
value={ blocks }
onInput={ setBlocks }
onChange={ setContent }
onInput={ onInput }
onChange={ onChange }
useSubRegistry={ false }
>
<BlockEditorKeyboardShortcuts />
Expand Down

0 comments on commit 0335169

Please sign in to comment.