From fb15df10badb69e8a5a2630fac548517ba4ef91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Gomes?= Date: Tue, 27 Aug 2024 10:19:45 +0100 Subject: [PATCH] Post publish upload media dialog: fix silent failure (#64741) * Post publish upload media dialog: fix silent failure * Wait until animation ends before activating button --- .../post-publish-panel/maybe-upload-media.js | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/packages/editor/src/components/post-publish-panel/maybe-upload-media.js b/packages/editor/src/components/post-publish-panel/maybe-upload-media.js index 7061ab9c387ee..609864e01716a 100644 --- a/packages/editor/src/components/post-publish-panel/maybe-upload-media.js +++ b/packages/editor/src/components/post-publish-panel/maybe-upload-media.js @@ -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 = []; @@ -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, } ), [] @@ -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( () => { @@ -144,12 +139,14 @@ export default function PostFormatPanel() { gap: '8px', } } > - + setIsAnimating( false ) } + > { externalImages.map( ( image ) => { return ; } ) } - { isUploading ? ( + { isUploading || isAnimating ? ( ) : (