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: Remove redundant memoization from 'ImageURLInputUI' #51658

Merged
merged 1 commit into from
Jun 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useRef, useState, useCallback } from '@wordpress/element';
import { useRef, useState } from '@wordpress/element';
import {
ToolbarButton,
Button,
Expand Down Expand Up @@ -50,34 +50,34 @@ const ImageURLInputUI = ( {
// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
const openLinkUI = useCallback( () => {
const openLinkUI = () => {
setIsOpen( true );
} );
};

const [ isEditingLink, setIsEditingLink ] = useState( false );
const [ urlInput, setUrlInput ] = useState( null );

const autocompleteRef = useRef( null );

const startEditLink = useCallback( () => {
const startEditLink = () => {
if (
linkDestination === LINK_DESTINATION_MEDIA ||
linkDestination === LINK_DESTINATION_ATTACHMENT
) {
setUrlInput( '' );
}
setIsEditingLink( true );
} );
};

const stopEditLink = useCallback( () => {
const stopEditLink = () => {
setIsEditingLink( false );
} );
};

const closeLinkUI = useCallback( () => {
const closeLinkUI = () => {
setUrlInput( null );
stopEditLink();
setIsOpen( false );
} );
};

const getUpdatedLinkTargetSettings = ( value ) => {
const newLinkTarget = value ? '_blank' : undefined;
Expand Down Expand Up @@ -106,7 +106,7 @@ const ImageURLInputUI = ( {
};
};

const onFocusOutside = useCallback( () => {
const onFocusOutside = () => {
return ( event ) => {
// The autocomplete suggestions list renders in a separate popover (in a portal),
// so onFocusOutside fails to detect that a click on a suggestion occurred in the
Expand All @@ -123,9 +123,9 @@ const ImageURLInputUI = ( {
setUrlInput( null );
stopEditLink();
};
} );
};

const onSubmitLinkChange = useCallback( () => {
const onSubmitLinkChange = () => {
return ( event ) => {
if ( urlInput ) {
// It is possible the entered URL actually matches a named link destination.
Expand All @@ -144,14 +144,14 @@ const ImageURLInputUI = ( {
setUrlInput( null );
event.preventDefault();
};
} );
};

const onLinkRemove = useCallback( () => {
const onLinkRemove = () => {
onChangeUrl( {
linkDestination: LINK_DESTINATION_NONE,
href: '',
} );
} );
};

const getLinkDestinations = () => {
const linkDestinations = [
Expand Down