display the play / download button again upon a failure condition

This commit is contained in:
Akinwale Ariwodola 2018-09-08 10:11:52 +01:00
parent 0638b9f133
commit adc9550e58
4 changed files with 27 additions and 8 deletions

View file

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

View file

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

View file

@ -397,7 +397,13 @@ class FilePage extends React.PureComponent {
this.startTime = Date.now(); this.startTime = Date.now();
this.setState({ downloadPressed: true, autoPlayMedia: true }); 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} />} {!fileInfo && <FilePrice uri={uri} style={filePageStyle.filePriceContainer} textStyle={filePageStyle.filePriceText} />}
</View> </View>
{canLoadMedia && fileInfo && <View style={playerBgStyle} {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 => { return dispatch => {
dispatch({ dispatch({
type: ACTIONS.LOADING_VIDEO_STARTED, type: ACTIONS.LOADING_VIDEO_STARTED,
@ -188,6 +188,10 @@ export function doLoadVideo(uri) {
message: `File timeout for uri ${uri}`, message: `File timeout for uri ${uri}`,
displayType: ['toast'] displayType: ['toast']
})); }));
if (failureCallback) {
failureCallback();
}
} else { } else {
dispatch(doDownloadFile(uri, streamInfo)); 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.`, message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`,
displayType: ['toast'] displayType: ['toast']
})); }));
if (failureCallback) {
failureCallback();
}
}); });
}; };
} }
export function doPurchaseUri(uri, specificCostInfo) { export function doPurchaseUri(uri, specificCostInfo, failureCallback) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const balance = selectBalance(state); const balance = selectBalance(state);
@ -226,11 +234,11 @@ export function doPurchaseUri(uri, specificCostInfo) {
`This will purchase "${title}" for ${formattedCost} ${unit}`, `This will purchase "${title}" for ${formattedCost} ${unit}`,
[ [
{ text: 'OK', onPress: () => dispatch(doLoadVideo(uri)) }, { text: 'OK', onPress: () => dispatch(doLoadVideo(uri)) },
{ text: 'Cancel', style: 'cancel' } { text: 'Cancel', style: 'cancel', onPress: () => failureCallback && failureCallback() }
], ],
{ cancelable: true }); { cancelable: true });
} else { } else {
dispatch(doLoadVideo(uri)); dispatch(doLoadVideo(uri, failureCallback));
} }
} }
@ -260,6 +268,10 @@ export function doPurchaseUri(uri, specificCostInfo) {
message: 'Insufficient credits', message: 'Insufficient credits',
displayType: ['toast'] displayType: ['toast']
})); }));
if (failureCallback) {
failureCallback();
}
Promise.resolve(); Promise.resolve();
return; return;
} }