Skip to content

Commit

Permalink
Audio: Display upload error notices using snackbars (#43891)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Sep 6, 2022
1 parent 5be0ec4 commit f510544
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
SelectControl,
Spinner,
ToggleControl,
withNotices,
} from '@wordpress/components';
import {
BlockControls,
Expand All @@ -28,9 +27,10 @@ import {
} from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { audio as icon } from '@wordpress/icons';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
Expand All @@ -42,11 +42,9 @@ const ALLOWED_MEDIA_TYPES = [ 'audio' ];
function AudioEdit( {
attributes,
className,
noticeOperations,
setAttributes,
onReplace,
isSelected,
noticeUI,
insertBlocksAfter,
} ) {
const { id, autoplay, caption, loop, preload, src } = attributes;
Expand Down Expand Up @@ -93,9 +91,9 @@ function AudioEdit( {
}
}

const { createErrorNotice } = useDispatch( noticesStore );
function onUploadError( message ) {
noticeOperations.removeAllNotices();
noticeOperations.createErrorNotice( message );
createErrorNotice( message, { type: 'snackbar' } );
}

function getAutoplayHelp( checked ) {
Expand Down Expand Up @@ -134,7 +132,6 @@ function AudioEdit( {
accept="audio/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
notices={ noticeUI }
onError={ onUploadError }
/>
</div>
Expand Down Expand Up @@ -222,4 +219,5 @@ function AudioEdit( {
</>
);
}
export default withNotices( AudioEdit );

export default AudioEdit;

0 comments on commit f510544

Please sign in to comment.