From b22314d36d90dc69002362e5e7a79a9b04e6508c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Gomes?= Date: Wed, 28 Aug 2024 10:21:43 +0100 Subject: [PATCH] Post publish upload media dialog: handle upload errors (#64823) * Post publish upload media dialog: handle upload errors * Change text color * Drop unused classname * Add catch-all for any errors during upload * Remove redundant setHadUploadError call --- .../src/components/post-publish-panel/maybe-upload-media.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 d3e861ee7c29d3..b090e25cd4dbff 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 @@ -61,6 +61,7 @@ function Image( block ) { export default function PostFormatPanel() { const [ isUploading, setIsUploading ] = useState( false ); const [ isAnimating, setIsAnimating ] = useState( false ); + const [ hadUploadError, setHadUploadError ] = useState( false ); const { editorBlocks, mediaUpload } = useSelect( ( select ) => ( { editorBlocks: select( blockEditorStore ).getBlocks(), @@ -89,6 +90,7 @@ export default function PostFormatPanel() { function uploadImages() { setIsUploading( true ); + setHadUploadError( false ); Promise.all( externalImages.map( ( image ) => window @@ -119,6 +121,9 @@ export default function PostFormatPanel() { } ); } ).then( () => setIsAnimating( true ) ) ) + .catch( () => { + setHadUploadError( true ); + } ) ) ).finally( () => { setIsUploading( false ); @@ -159,6 +164,7 @@ export default function PostFormatPanel() { ) } + { hadUploadError &&

{ __( 'Upload failed, try again.' ) }

} ); }