Skip to content

Commit

Permalink
Image: Display upload error notices using snackbars (#43767)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Sep 2, 2022
1 parent 95f71ed commit 72b1681
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { get, isEmpty, pick } from 'lodash';
* WordPress dependencies
*/
import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';
import { withNotices, Placeholder } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Placeholder } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import {
BlockAlignmentControl,
BlockControls,
Expand All @@ -22,6 +22,7 @@ import {
import { useEffect, useRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { image as icon } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
Expand Down Expand Up @@ -108,9 +109,7 @@ export function ImageEdit( {
setAttributes,
isSelected,
className,
noticeUI,
insertBlocksAfter,
noticeOperations,
onReplace,
context,
clientId,
Expand Down Expand Up @@ -143,9 +142,9 @@ export function ImageEdit( {
return pick( getSettings(), [ 'imageDefaultSize', 'mediaUpload' ] );
}, [] );

const { createErrorNotice } = useDispatch( noticesStore );
function onUploadError( message ) {
noticeOperations.removeAllNotices();
noticeOperations.createErrorNotice( message );
createErrorNotice( message, { type: 'snackbar' } );
setAttributes( {
src: undefined,
id: undefined,
Expand Down Expand Up @@ -361,7 +360,6 @@ export function ImageEdit( {
icon={ <BlockIcon icon={ icon } /> }
onSelect={ onSelectImage }
onSelectURL={ onSelectURL }
notices={ noticeUI }
onError={ onUploadError }
placeholder={ placeholder }
accept="image/*"
Expand All @@ -374,4 +372,4 @@ export function ImageEdit( {
);
}

export default withNotices( ImageEdit );
export default ImageEdit;

0 comments on commit 72b1681

Please sign in to comment.