Skip to content

Commit

Permalink
Update MediaUploadProgress to use withIsConnected HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
derekblank authored and dcalhoun committed Dec 13, 2023
1 parent 7f6e24c commit 7c79d2a
Showing 1 changed file with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import { View } from 'react-native';
import { Component } from '@wordpress/element';
import { Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
subscribeMediaUpload,
subscribeConnectionStatus,
} from '@wordpress/react-native-bridge';
import { subscribeMediaUpload } from '@wordpress/react-native-bridge';
import { withIsConnected } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -35,22 +33,15 @@ export class MediaUploadProgress extends Component {
};

this.mediaUpload = this.mediaUpload.bind( this );
this.getRetryMessage = this.getRetryMessage.bind( this );
}

componentDidMount() {
this.addMediaUploadListener();

this.subscription = subscribeConnectionStatus(
this.handleConnectionStatusChange
);
}

componentWillUnmount() {
this.removeMediaUploadListener();

if ( this.subscription ) {
this.subscription.remove();
}
}

mediaUpload( payload ) {
Expand Down Expand Up @@ -126,24 +117,26 @@ export class MediaUploadProgress extends Component {
}
}

handleConnectionStatusChange = ( { isConnected } ) => {
// eslint-disable-next-line no-console
console.log( 'isConnected:', isConnected );
};
getRetryMessage() {
if ( this.props.isConnected === true ) {
// eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace
return __( 'Failed to insert media.\nTap for more info.' );
}
return __( 'You are currently offline.' );
}

render() {
const { renderContent = () => null } = this.props;
const { isUploadInProgress, isUploadFailed } = this.state;
const showSpinner = this.state.isUploadInProgress;
const progress = this.state.progress * 100;
// eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace
const retryMessage = __(
'Failed to insert media.\nTap for more info.'
);
const retryMessage = this.getRetryMessage();

const progressBarStyle = [
styles.progressBar,
showSpinner || styles.progressBarHidden,
showSpinner && this.props.isConnected
? styles.progressBarHidden
: null,
this.props.progressBarStyle,
];

Expand Down Expand Up @@ -174,4 +167,4 @@ export class MediaUploadProgress extends Component {
}
}

export default MediaUploadProgress;
export default withIsConnected( MediaUploadProgress );

0 comments on commit 7c79d2a

Please sign in to comment.