Skip to content

Commit

Permalink
Post publish upload media dialog: fix silent failure (WordPress#64741)
Browse files Browse the repository at this point in the history
* Post publish upload media dialog: fix silent failure

* Wait until animation ends before activating button
  • Loading branch information
sgomes authored Aug 27, 2024
1 parent 9c52776 commit fb15df1
Showing 1 changed file with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
import { useState } from '@wordpress/element';
import { isBlobURL } from '@wordpress/blob';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';

function flattenBlocks( blocks ) {
const result = [];

Expand Down Expand Up @@ -65,9 +60,10 @@ function Image( block ) {

export default function PostFormatPanel() {
const [ isUploading, setIsUploading ] = useState( false );
const [ isAnimating, setIsAnimating ] = useState( false );
const { editorBlocks, mediaUpload } = useSelect(
( select ) => ( {
editorBlocks: select( editorStore ).getEditorBlocks(),
editorBlocks: select( blockEditorStore ).getBlocks(),
mediaUpload: select( blockEditorStore ).getSettings().mediaUpload,
} ),
[]
Expand Down Expand Up @@ -102,27 +98,26 @@ export default function PostFormatPanel() {
: image.attributes.url + '?'
)
.then( ( response ) => response.blob() )
.then(
( blob ) =>
new Promise( ( resolve, reject ) => {
mediaUpload( {
filesList: [ blob ],
onFileChange: ( [ media ] ) => {
if ( isBlobURL( media.url ) ) {
return;
}
.then( ( blob ) =>
new Promise( ( resolve, reject ) => {
mediaUpload( {
filesList: [ blob ],
onFileChange: ( [ media ] ) => {
if ( isBlobURL( media.url ) ) {
return;
}

updateBlockAttributes( image.clientId, {
id: media.id,
url: media.url,
} );
resolve();
},
onError() {
reject();
},
} );
} )
updateBlockAttributes( image.clientId, {
id: media.id,
url: media.url,
} );
resolve();
},
onError() {
reject();
},
} );
} ).then( () => setIsAnimating( true ) )
)
)
).finally( () => {
Expand All @@ -144,12 +139,14 @@ export default function PostFormatPanel() {
gap: '8px',
} }
>
<AnimatePresence>
<AnimatePresence
onExitComplete={ () => setIsAnimating( false ) }
>
{ externalImages.map( ( image ) => {
return <Image key={ image.clientId } { ...image } />;
} ) }
</AnimatePresence>
{ isUploading ? (
{ isUploading || isAnimating ? (
<Spinner />
) : (
<Button variant="primary" onClick={ uploadImages }>
Expand Down

0 comments on commit fb15df1

Please sign in to comment.