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

[Mobile]Fix video upload #16331

Merged
merged 11 commits into from
Jul 9, 2019
27 changes: 12 additions & 15 deletions packages/block-library/src/video/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class VideoEdit extends React.Component {

this.state = {
showSettings: false,
isMediaRequested: false,
videoContainerHeight: 0,
};

Expand All @@ -64,7 +63,7 @@ class VideoEdit extends React.Component {

componentDidMount() {
const { attributes } = this.props;
if ( attributes.id && attributes.url && ! isURL( attributes.src ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember like attributes.url was not becoming undefined when we close/open a post during the upload. but now it is, so it is now useless and preventing the block from calling mediaUploadSync. maybe sth changed in the infrastructure that is causing this but I think removing this altogether should be fine.

if ( attributes.id && ! isURL( attributes.src ) ) {
mediaUploadSync();
}
}
Expand All @@ -91,7 +90,6 @@ class VideoEdit extends React.Component {
if ( payload.mediaUrl ) {
setAttributes( { url: payload.mediaUrl } );
}

if ( ! this.state.isUploadInProgress ) {
this.setState( { isUploadInProgress: true } );
}
Expand All @@ -100,25 +98,24 @@ class VideoEdit extends React.Component {
finishMediaUploadWithSuccess( payload ) {
const { setAttributes } = this.props;
setAttributes( { src: payload.mediaUrl, id: payload.mediaServerId } );
this.setState( { isMediaRequested: false, isUploadInProgress: false } );
this.setState( { isUploadInProgress: false } );
}

finishMediaUploadWithFailure( payload ) {
const { setAttributes } = this.props;
setAttributes( { id: payload.mediaId } );
this.setState( { isMediaRequested: false, isUploadInProgress: false } );
this.setState( { isUploadInProgress: false } );
}

mediaUploadStateReset() {
const { setAttributes } = this.props;
setAttributes( { id: null, src: null } );
this.setState( { isMediaRequested: false, isUploadInProgress: false } );
this.setState( { isUploadInProgress: false } );
}

onSelectMediaUploadOption( mediaId, mediaUrl ) {
const { setAttributes } = this.props;
setAttributes( { id: mediaId, src: mediaUrl } );
this.setState( { isMediaRequested: true } );
}

onVideoContanerLayout( event ) {
Expand All @@ -129,18 +126,18 @@ class VideoEdit extends React.Component {
}
}

getIcon( isRetryIcon, isUploadInProgress ) {
getIcon( isRetryIcon, isMediaPlaceholder ) {
if ( isRetryIcon ) {
return <Icon icon={ SvgIconRetry } { ...style.icon } />;
}

return <Icon icon={ SvgIcon } { ...( isUploadInProgress ? style.iconUploading : style.icon ) } />;
return <Icon icon={ SvgIcon } { ...( ! isMediaPlaceholder ? style.iconUploading : style.icon ) } />;
}

render() {
const { attributes, isSelected, setAttributes } = this.props;
const { caption, id, src } = attributes;
const { isMediaRequested, videoContainerHeight } = this.state;
const { videoContainerHeight } = this.state;

const toolbarEditButton = (
<MediaUpload mediaType={ MEDIA_TYPE_VIDEO }
Expand All @@ -160,13 +157,13 @@ class VideoEdit extends React.Component {
</MediaUpload>
);

if ( ! isMediaRequested && ! src ) {
if ( ! id ) {
return (
<View style={ { flex: 1 } } >
<MediaPlaceholder
mediaType={ MEDIA_TYPE_VIDEO }
onSelectURL={ this.onSelectMediaUploadOption }
icon={ this.getIcon( false ) }
icon={ this.getIcon( false, true ) }
onFocus={ this.props.onFocus }
/>
</View>
Expand All @@ -193,8 +190,8 @@ class VideoEdit extends React.Component {
onUpdateMediaProgress={ this.updateMediaProgress }
onMediaUploadStateReset={ this.mediaUploadStateReset }
renderContent={ ( { isUploadInProgress, isUploadFailed, retryMessage } ) => {
const showVideo = src && ! isUploadInProgress && ! isUploadFailed;
const icon = this.getIcon( isUploadFailed, isUploadInProgress );
const showVideo = isURL( src ) && ! isUploadInProgress && ! isUploadFailed;
const icon = this.getIcon( isUploadFailed, false );
const styleIconContainer = isUploadFailed ? style.modalIconRetry : style.modalIcon;

const iconContainer = (
Expand All @@ -212,7 +209,7 @@ class VideoEdit extends React.Component {

return (
<View onLayout={ this.onVideoContanerLayout } style={ containerStyle }>
{ showVideo && isURL( src ) &&
{ showVideo &&
<View style={ style.videoContainer }>
<Video
isSelected={ isSelected }
Expand Down