Skip to content

Commit

Permalink
Avoid hardcoding the post type
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jan 11, 2021
1 parent 71ccafb commit e36f1b3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/core-data/src/entity-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) {
const { content, blocks } = useSelect(
( select ) => {
const { getEditedEntityRecord } = select( 'core' );
const editedEntity = getEditedEntityRecord( 'postType', type, id );
const editedEntity = getEditedEntityRecord( kind, type, id );
return {
blocks: editedEntity.blocks,
content: editedEntity.content,
};
},
[ type, id ]
[ kind, type, id ]
);
const { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(
'core'
Expand Down Expand Up @@ -176,7 +176,7 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) {
const edits = { blocks: newBlocks, selectionStart, selectionEnd };
const noChange = blocks === edits.blocks;
if ( noChange ) {
return __unstableCreateUndoLevel( 'postType', type, id );
return __unstableCreateUndoLevel( kind, type, id );
}

// We create a new function here on every persistent edit
Expand All @@ -185,20 +185,20 @@ export function useEntityBlockEditor( kind, type, { id: _id } = {} ) {
edits.content = ( { blocks: blocksForSerialization = [] } ) =>
__unstableSerializeAndClean( blocksForSerialization );

editEntityRecord( 'postType', type, id, edits );
editEntityRecord( kind, type, id, edits );
},
[ blocks, id, type ]
[ blocks, id, type, kind ]
);

const onInput = useCallback(
( newBlocks, options ) => {
const { selectionStart, selectionEnd } = options;
const edits = { blocks: newBlocks, selectionStart, selectionEnd };
editEntityRecord( 'postType', type, id, edits, {
editEntityRecord( kind, type, id, edits, {
undoIgnore: true,
} );
},
[ type, id ]
[ kind, type, id ]
);

return [ blocks ?? EMPTY_ARRAY, onInput, onChange ];
Expand Down

0 comments on commit e36f1b3

Please sign in to comment.