Skip to content

Commit

Permalink
Block Editor: Add success notices for image editing (#67312)
Browse files Browse the repository at this point in the history
* Block Editor: Add success notices for image editing
* Fix translators comment

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: ajlende <[email protected]>
  • Loading branch information
4 people authored Nov 26, 2024
1 parent d2c2ed8 commit 9407107
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';

const messages = {
crop: __( 'Image cropped.' ),
rotate: __( 'Image rotated.' ),
cropAndRotate: __( 'Image cropped and rotated.' ),
};

export default function useSaveImage( {
crop,
rotation,
Expand All @@ -18,7 +24,8 @@ export default function useSaveImage( {
onSaveImage,
onFinishEditing,
} ) {
const { createErrorNotice } = useDispatch( noticesStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const [ isInProgress, setIsInProgress ] = useState( false );

const cancel = useCallback( () => {
Expand Down Expand Up @@ -61,6 +68,9 @@ export default function useSaveImage( {
return;
}

const modifierType =
modifiers.length === 1 ? modifiers[ 0 ].type : 'cropAndRotate';

apiFetch( {
path: `/wp/v2/media/${ id }/edit`,
method: 'POST',
Expand All @@ -71,11 +81,14 @@ export default function useSaveImage( {
id: response.id,
url: response.source_url,
} );
createSuccessNotice( messages[ modifierType ], {
type: 'snackbar',
} );
} )
.catch( ( error ) => {
createErrorNotice(
sprintf(
/* translators: 1. Error message */
/* translators: %s: Error message. */
__( 'Could not edit image. %s' ),
stripHTML( error.message )
),
Expand All @@ -96,6 +109,7 @@ export default function useSaveImage( {
url,
onSaveImage,
createErrorNotice,
createSuccessNotice,
onFinishEditing,
] );

Expand Down

0 comments on commit 9407107

Please sign in to comment.