Skip to content

Commit

Permalink
Post publish upload media dialog: handle upload errors (#64823)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sgomes authored Aug 28, 2024
1 parent bf48535 commit b22314d
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function PostFormatPanel() {

function uploadImages() {
setIsUploading( true );
setHadUploadError( false );
Promise.all(
externalImages.map( ( image ) =>
window
Expand Down Expand Up @@ -119,6 +121,9 @@ export default function PostFormatPanel() {
} );
} ).then( () => setIsAnimating( true ) )
)
.catch( () => {
setHadUploadError( true );
} )
)
).finally( () => {
setIsUploading( false );
Expand Down Expand Up @@ -159,6 +164,7 @@ export default function PostFormatPanel() {
</Button>
) }
</div>
{ hadUploadError && <p>{ __( 'Upload failed, try again.' ) }</p> }
</PanelBody>
);
}

0 comments on commit b22314d

Please sign in to comment.