Skip to content
Merged
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
56 changes: 38 additions & 18 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ import { unlock } from '../lock-unlock';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const ALLOWED_MEDIA_TYPES = [ 'image' ];
const { mediaEditKey } = unlock( blockEditorPrivateApis );
const { mediaEditKey, openMediaEditorModalKey } = unlock(
blockEditorPrivateApis
);

const SiteLogo = ( {
alt,
Expand All @@ -78,22 +80,26 @@ const SiteLogo = ( {
const blockEditingMode = useBlockEditingMode();
const isContentOnlyMode = blockEditingMode === 'contentOnly';

const { imageEditing, maxWidth, title, editMediaEntity } = useSelect(
( select ) => {
const settings = select( blockEditorStore ).getSettings();
const siteEntities = select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
);
return {
title: siteEntities?.name,
imageEditing: settings.imageEditing,
maxWidth: settings.maxWidth,
editMediaEntity: settings?.[ mediaEditKey ],
};
},
[]
);
const {
imageEditing,
maxWidth,
title,
editMediaEntity,
openMediaEditorModal,
} = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
const siteEntities = select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
);
return {
title: siteEntities?.name,
imageEditing: settings.imageEditing,
maxWidth: settings.maxWidth,
editMediaEntity: settings?.[ mediaEditKey ],
openMediaEditorModal: settings?.[ openMediaEditorModalKey ],
};
}, [] );

useEffect( () => {
// Turn the `Use as site icon` toggle off if it is on but the logo and icon have
Expand All @@ -110,6 +116,12 @@ const SiteLogo = ( {
}
}, [ isSelected ] );

const handleMediaUpdate = ( { id: newId } ) => {
if ( typeof newId === 'number' && newId !== logoId ) {
setLogo( newId );
}
};

function onResizeStart() {
toggleSelection( false );
}
Expand Down Expand Up @@ -388,7 +400,15 @@ const SiteLogo = ( {
shouldShowCropAndDimensions && (
<BlockControls group="block">
<ToolbarButton
onClick={ () => setIsEditingImage( true ) }
onClick={
openMediaEditorModal && logoId
? () =>
openMediaEditorModal( {
id: logoId,
onUpdate: handleMediaUpdate,
} )
: () => setIsEditingImage( true )
}
icon={ crop }
label={ __( 'Crop' ) }
/>
Expand Down
Loading