Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React Native] request cancel image upload #14391

Merged
merged 7 commits into from
Mar 19, 2019
6 changes: 6 additions & 0 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
} from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';
import { doAction, hasAction } from '@wordpress/hooks';


/**
* Internal dependencies
Expand Down Expand Up @@ -87,6 +89,10 @@ class ImageEdit extends React.Component {
}

componentWillUnmount() {
// this action will only exist if the user pressed the trash button on the block holder
if ( hasAction( 'blocks.onRemoveBlockCheckUpload' ) && this.state.isUploadInProgress ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to put the action name in some constant so that we can reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following with comment here wordpress-mobile/gutenberg-mobile#736 (comment)

Another thing I just noticed is that the constant would need to be defined in gutenberg-mobile and be imported in Gutenberg native file (as those are the 2 places where it's used, for adding in the Gutenberg-mobile level and removing at the Gutenberg component level) - I don't think there's much gain as there's 2 places only, been thinking of doing it through props as well, but it makes the code a small bit harder to follow. Would it be ok to leave it as is ? wdyt?

doAction( 'blocks.onRemoveBlockCheckUpload', this.props.attributes.id )
}
this.removeMediaUploadListener();
}

Expand Down