From f884657c492af84770249720a41173b0eee0cdd0 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 8 Sep 2022 10:14:28 +0400 Subject: [PATCH] Gallery: Display upload error notices using snackbars (#43946) --- packages/block-library/src/gallery/edit.js | 23 ++++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index 41240ac6c48be..6d1a4ac5fc404 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -13,7 +13,6 @@ import { PanelBody, SelectControl, ToggleControl, - withNotices, RangeControl, Spinner, } from '@wordpress/components'; @@ -80,9 +79,7 @@ function GalleryEdit( props ) { attributes, className, clientId, - noticeOperations, isSelected, - noticeUI, insertBlocksAfter, } = props; @@ -95,7 +92,8 @@ function GalleryEdit( props ) { selectBlock, clearSelectedBlock, } = useDispatch( blockEditorStore ); - const { createSuccessNotice } = useDispatch( noticesStore ); + const { createSuccessNotice, createErrorNotice } = + useDispatch( noticesStore ); const { getBlock, getSettings, preferredStyle } = useSelect( ( select ) => { const settings = select( blockEditorStore ).getSettings(); @@ -244,12 +242,11 @@ function GalleryEdit( props ) { : selectedImages; if ( ! imageArray.every( isValidFileType ) ) { - noticeOperations.removeAllNotices(); - noticeOperations.createErrorNotice( + createErrorNotice( __( 'If uploading to a gallery all files need to be image formats' ), - { id: 'gallery-upload-invalid-file' } + { id: 'gallery-upload-invalid-file', type: 'snackbar' } ); } @@ -316,8 +313,7 @@ function GalleryEdit( props ) { } function onUploadError( message ) { - noticeOperations.removeAllNotices(); - noticeOperations.createErrorNotice( message ); + createErrorNotice( message, { type: 'snackbar' } ); } function setLinkTo( value ) { @@ -470,7 +466,6 @@ function GalleryEdit( props ) { allowedTypes={ ALLOWED_MEDIA_TYPES } multiple onError={ onUploadError } - notices={ noticeUI } { ...mediaPlaceholderProps } /> ); @@ -560,7 +555,6 @@ function GalleryEdit( props ) { addToGallery={ hasImageIds } /> - { noticeUI } { Platform.isWeb && ( ); } -export default compose( [ - withNotices, - withViewportMatch( { isNarrow: '< small' } ), -] )( GalleryEdit ); +export default compose( [ withViewportMatch( { isNarrow: '< small' } ) ] )( + GalleryEdit +);