Skip to content

Commit

Permalink
Don't forcefully cancel media upload on img/video unmount
Browse files Browse the repository at this point in the history
Manually reverts d554ba3
  • Loading branch information
hypest committed Jun 28, 2019
1 parent 5d62ed6 commit 3fc8ba6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ export default compose(
order: getBlockIndex( clientId ),
};
} ),
withDispatch( ( dispatch, { clientId, rootClientId, onDelete } ) => {
withDispatch( ( dispatch, { clientId, rootClientId } ) => {
const { removeBlock } = dispatch( 'core/block-editor' );
return {
onDelete() {
onDelete: () => {
Keyboard.dismiss();
removeBlock( clientId, rootClientId );
if ( onDelete ) {
onDelete( clientId );
}
},
};
} ),
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
mediaUploadSync,
requestImageFailedRetryDialog,
requestImageUploadCancelDialog,
requestImageUploadCancel,
} from 'react-native-gutenberg-bridge';
import { isEmpty } from 'lodash';

Expand All @@ -31,6 +30,7 @@ import {
} from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';
import { doAction, hasAction } from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -92,8 +92,9 @@ class ImageEdit extends React.Component {
}

componentWillUnmount() {
if ( this.state.isUploadInProgress ) {
requestImageUploadCancel( this.props.attributes.id );
// this action will only exist if the user pressed the trash button on the block holder
if ( hasAction( 'blocks.onRemoveBlockCheckUpload' ) && this.state.isUploadInProgress ) {
doAction( 'blocks.onRemoveBlockCheckUpload', this.props.attributes.id );
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/video/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
mediaUploadSync,
requestImageFailedRetryDialog,
requestImageUploadCancelDialog,
requestImageUploadCancel,
} from 'react-native-gutenberg-bridge';

/**
Expand All @@ -32,6 +31,7 @@ import {
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';
import { doAction, hasAction } from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -70,8 +70,9 @@ class VideoEdit extends React.Component {
}

componentWillUnmount() {
if ( this.state.isUploadInProgress ) {
requestImageUploadCancel( this.props.attributes.id );
// this action will only exist if the user pressed the trash button on the block holder
if ( hasAction( 'blocks.onRemoveBlockCheckUpload' ) && this.state.isUploadInProgress ) {
doAction( 'blocks.onRemoveBlockCheckUpload', this.props.attributes.id );
}
}

Expand Down

0 comments on commit 3fc8ba6

Please sign in to comment.