Skip to content

Commit

Permalink
Refactor latest content selectors in 'CopyContentMenuItem' components (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Aug 21, 2023
1 parent f273695 commit 70ccdef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
10 changes: 5 additions & 5 deletions packages/edit-post/src/plugins/copy-content-menu-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { store as editorStore } from '@wordpress/editor';

export default function CopyContentMenuItem() {
const { createNotice } = useDispatch( noticesStore );
const getText = useSelect(
( select ) => () =>
select( editorStore ).getEditedPostAttribute( 'content' ),
[]
);
const { getEditedPostAttribute } = useSelect( editorStore );

function getText() {
return getEditedPostAttribute( 'content' );
}

function onSuccess() {
createNotice( 'info', __( 'All content copied.' ), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@ import { store as editSiteStore } from '../../../store';

export default function CopyContentMenuItem() {
const { createNotice } = useDispatch( noticesStore );
const getText = useSelect( ( select ) => {
return () => {
const { getEditedPostId, getEditedPostType } =
select( editSiteStore );
const { getEditedEntityRecord } = select( coreStore );
const record = getEditedEntityRecord(
'postType',
getEditedPostType(),
getEditedPostId()
);
if ( record ) {
if ( typeof record.content === 'function' ) {
return record.content( record );
} else if ( record.blocks ) {
return __unstableSerializeAndClean( record.blocks );
} else if ( record.content ) {
return record.content;
}
}
const { getEditedPostId, getEditedPostType } = useSelect( editSiteStore );
const { getEditedEntityRecord } = useSelect( coreStore );

function getText() {
const record = getEditedEntityRecord(
'postType',
getEditedPostType(),
getEditedPostId()
);
if ( ! record ) {
return '';
};
}, [] );
}

if ( typeof record.content === 'function' ) {
return record.content( record );
} else if ( record.blocks ) {
return __unstableSerializeAndClean( record.blocks );
} else if ( record.content ) {
return record.content;
}
}

function onSuccess() {
createNotice( 'info', __( 'All content copied.' ), {
Expand Down

0 comments on commit 70ccdef

Please sign in to comment.