Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor latest content selectors in 'CopyContentMenuItem' components #53676

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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