Skip to content

Commit

Permalink
Video: Display upload error notices using snackbars (#43892)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Sep 6, 2022
1 parent 659377e commit ca35924
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Disabled,
PanelBody,
Spinner,
withNotices,
} from '@wordpress/components';
import {
BlockControls,
Expand All @@ -31,9 +30,10 @@ import {
import { useRef, useEffect } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { useInstanceId } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { video as icon } from '@wordpress/icons';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
Expand All @@ -48,13 +48,11 @@ const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];

function VideoEdit( {
isSelected,
noticeUI,
attributes,
className,
setAttributes,
insertBlocksAfter,
onReplace,
noticeOperations,
} ) {
const instanceId = useInstanceId( VideoEdit );
const videoPlayer = useRef();
Expand All @@ -73,9 +71,7 @@ function VideoEdit( {
mediaUpload( {
filesList: [ file ],
onFileChange: ( [ media ] ) => onSelectVideo( media ),
onError: ( message ) => {
noticeOperations.createErrorNotice( message );
},
onError: onUploadError,
allowedTypes: ALLOWED_MEDIA_TYPES,
} );
}
Expand Down Expand Up @@ -126,9 +122,9 @@ function VideoEdit( {
}
}

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

const classes = classnames( className, {
Expand All @@ -149,7 +145,6 @@ function VideoEdit( {
accept="video/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
notices={ noticeUI }
onError={ onUploadError }
/>
</div>
Expand Down Expand Up @@ -289,4 +284,4 @@ function VideoEdit( {
);
}

export default withNotices( VideoEdit );
export default VideoEdit;

0 comments on commit ca35924

Please sign in to comment.