display the play / download button again upon a failure condition #285

Merged
akinwale merged 1 commit from download-failed-callback into master 2018-09-08 11:40:54 +02:00
4 changed files with 27 additions and 8 deletions

View file

@ -17,7 +17,7 @@ const select = (state, props) => ({
});
const perform = dispatch => ({
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
purchaseUri: (uri, failureCallback) => dispatch(doPurchaseUri(uri, null, failureCallback)),
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
});

View file

@ -43,7 +43,8 @@ class FileDownloadButton extends React.PureComponent {
doPause,
style,
openFile,
onButtonLayout
onButtonLayout,
onStartDownloadFailed
} = this.props;
if (loading || downloading) {
@ -73,7 +74,7 @@ class FileDownloadButton extends React.PureComponent {
if (NativeModules.Mixpanel) {
NativeModules.Mixpanel.track('Purchase Uri', { Uri: uri });
}
purchaseUri(uri);
purchaseUri(uri, onStartDownloadFailed);
if (isPlayable && onPlay) {
this.props.onPlay();
}

View file

@ -397,7 +397,13 @@ class FilePage extends React.PureComponent {
this.startTime = Date.now();
this.setState({ downloadPressed: true, autoPlayMedia: true });
}}
onButtonLayout={() => this.setState({ downloadButtonShown: true })} />}
onButtonLayout={() => this.setState({ downloadButtonShown: true })}
onStartDownloadFailed={() => {
this.startTime = null;
setTimeout(() => {
this.setState({ downloadPressed: false, fileViewLogged: false, mediaLoaded: false });
}, 500);
}} />}
{!fileInfo && <FilePrice uri={uri} style={filePageStyle.filePriceContainer} textStyle={filePageStyle.filePriceText} />}
</View>
{canLoadMedia && fileInfo && <View style={playerBgStyle}

View file

@ -163,7 +163,7 @@ export function doSetPlayingUri(uri) {
};
}
export function doLoadVideo(uri) {
export function doLoadVideo(uri, failureCallback) {
return dispatch => {
dispatch({
type: ACTIONS.LOADING_VIDEO_STARTED,
@ -188,6 +188,10 @@ export function doLoadVideo(uri) {
message: `File timeout for uri ${uri}`,
displayType: ['toast']
}));
if (failureCallback) {
failureCallback();
}
} else {
dispatch(doDownloadFile(uri, streamInfo));
}
@ -203,11 +207,15 @@ export function doLoadVideo(uri) {
message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`,
displayType: ['toast']
}));
if (failureCallback) {
failureCallback();
}
});
};
}
export function doPurchaseUri(uri, specificCostInfo) {
export function doPurchaseUri(uri, specificCostInfo, failureCallback) {
return (dispatch, getState) => {
const state = getState();
const balance = selectBalance(state);
@ -226,11 +234,11 @@ export function doPurchaseUri(uri, specificCostInfo) {
`This will purchase "${title}" for ${formattedCost} ${unit}`,
[
{ text: 'OK', onPress: () => dispatch(doLoadVideo(uri)) },
{ text: 'Cancel', style: 'cancel' }
{ text: 'Cancel', style: 'cancel', onPress: () => failureCallback && failureCallback() }
],
{ cancelable: true });
} else {
dispatch(doLoadVideo(uri));
dispatch(doLoadVideo(uri, failureCallback));
}
}
@ -260,6 +268,10 @@ export function doPurchaseUri(uri, specificCostInfo) {
message: 'Insufficient credits',
displayType: ['toast']
}));
if (failureCallback) {
failureCallback();
}
Promise.resolve();
return;
}