Skip to content

Commit

Permalink
Revert "Openverse: prevent multiple insertions during upload (WordPre…
Browse files Browse the repository at this point in the history
…ss#65719)"

This reverts commit bd4297c.
  • Loading branch information
huubl authored Oct 2, 2024
1 parent 23ad7e7 commit 653003d
Showing 1 changed file with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ export function MediaPreview( { media, onClick, category } ) {
);
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const { getSettings, getBlock } = useSelect( blockEditorStore );
const { updateBlockAttributes } = useDispatch( blockEditorStore );
const { getSettings } = useSelect( blockEditorStore );

const onMediaInsert = useCallback(
( previewBlock ) => {
Expand Down Expand Up @@ -181,31 +180,18 @@ export function MediaPreview( { media, onClick, category } ) {
if ( isBlobURL( img.url ) ) {
return;
}

if ( ! getBlock( clonedBlock.clientId ) ) {
// Ensure the block is only inserted once.
onClick( {
...clonedBlock,
attributes: {
...clonedBlock.attributes,
id: img.id,
url: img.url,
},
} );

createSuccessNotice(
__( 'Image uploaded and inserted.' ),
{ type: 'snackbar', id: 'inserter-notice' }
);
} else {
// For subsequent calls, update the existing block.
updateBlockAttributes( clonedBlock.clientId, {
onClick( {
...clonedBlock,
attributes: {
...clonedBlock.attributes,
id: img.id,
url: img.url,
} );
}

},
} );
createSuccessNotice(
__( 'Image uploaded and inserted.' ),
{ type: 'snackbar', id: 'inserter-notice' }
);
setIsInserting( false );
},
allowedTypes: ALLOWED_MEDIA_TYPES,
Expand All @@ -228,9 +214,7 @@ export function MediaPreview( { media, onClick, category } ) {
getSettings,
onClick,
createSuccessNotice,
updateBlockAttributes,
createErrorNotice,
getBlock,
]
);

Expand Down

0 comments on commit 653003d

Please sign in to comment.