Skip to content

Commit

Permalink
Image editing: use snackbar notifications (#23029)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Jun 10, 2020
1 parent 4e0a8e7 commit e9e3027
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/block-library/src/rich-image/rich-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
MenuItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -158,10 +159,9 @@ function RichImage( props ) {
isSelected,
attributes: { id, url },
originalBlock: OriginalBlock,
noticeUI,
setAttributes,
noticeOperations,
} = props;
const { createErrorNotice } = useDispatch( 'core/notices' );
const [ isCropping, setIsCropping ] = useState( false );
const [ inProgress, setIsProgress ] = useState( null );
const [ imageSize, setImageSize ] = useState( {
Expand All @@ -183,7 +183,6 @@ function RichImage( props ) {

function adjustImage( action, attrs ) {
setIsProgress( action );
noticeOperations.removeAllNotices();

richImageRequest( id, action, attrs )
.then( ( response ) => {
Expand All @@ -198,10 +197,14 @@ function RichImage( props ) {
}
} )
.catch( () => {
noticeOperations.createErrorNotice(
createErrorNotice(
__(
'Unable to perform the image modification. Please check your media storage.'
)
),
{
id: 'image-editing-error',
type: 'snackbar',
}
);
setIsProgress( null );
setIsCropping( false );
Expand All @@ -224,7 +227,6 @@ function RichImage( props ) {

return (
<>
{ noticeUI }
<div className={ classes }>
{ inProgress && (
<div className="richimage__working-spinner">
Expand Down

0 comments on commit e9e3027

Please sign in to comment.