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

Block Editor: Combine selectors in the 'BackgroundImagePanelItem' component #57159

Merged
merged 1 commit into from Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/block-editor/src/hooks/background.js
Expand Up @@ -144,21 +144,22 @@ function InspectorImagePreview( { label, filename, url: imgUrl } ) {
}

function BackgroundImagePanelItem( { clientId, setAttributes } ) {
const style = useSelect(
( select ) =>
select( blockEditorStore ).getBlockAttributes( clientId )?.style,
const { style, mediaUpload } = useSelect(
( select ) => {
const { getBlockAttributes, getSettings } =
select( blockEditorStore );

return {
style: getBlockAttributes( clientId )?.style,
mediaUpload: getSettings().mediaUpload,
};
},
[ clientId ]
);
const { id, title, url } = style?.background?.backgroundImage || {};

const replaceContainerRef = useRef();

const { mediaUpload } = useSelect( ( select ) => {
return {
mediaUpload: select( blockEditorStore ).getSettings().mediaUpload,
};
} );

const { createErrorNotice } = useDispatch( noticesStore );
const onUploadError = ( message ) => {
createErrorNotice( message, { type: 'snackbar' } );
Expand Down