fix error message displayed repeatedly for content with fileInfo

This commit is contained in:
Akinwale Ariwodola 2020-01-06 21:49:22 +01:00
parent 4ed3809ffd
commit 91eb18ec9b

View file

@ -145,6 +145,7 @@ class FilePage extends React.PureComponent {
failedPurchaseUris: prevFailedPurchaseUris,
fetchViewCount,
purchasedUris: prevPurchasedUris,
purchaseUriErrorMessage: prevPurchaseUriErrorMessage,
navigation,
contentType,
notify,
@ -166,7 +167,11 @@ class FilePage extends React.PureComponent {
this.onComponentFocused();
}
if (failedPurchaseUris.includes(uri) && !purchasedUris.includes(uri)) {
if (
failedPurchaseUris.includes(uri) &&
!purchasedUris.includes(uri) &&
prevPurchaseUriErrorMessage !== purchaseUriErrorMessage
) {
if (purchaseUriErrorMessage && purchaseUriErrorMessage.trim().length > 0) {
notify({ message: purchaseUriErrorMessage, isError: true });
}
@ -222,17 +227,7 @@ class FilePage extends React.PureComponent {
}
componentDidUpdate(prevProps, prevState) {
const {
claim,
contentType,
costInfo,
fileInfo,
isResolvingUri,
resolveUri,
navigation,
purchaseUri,
title,
} = this.props;
const { claim, contentType, costInfo, fileInfo, isResolvingUri, resolveUri, navigation, title } = this.props;
const { uri } = this.state;
if (!isResolvingUri && claim === undefined && uri) {
resolveUri(uri);
@ -259,6 +254,24 @@ class FilePage extends React.PureComponent {
if (((costInfo && costInfo.cost > 0) || !isPlayable) && !this.state.showRecommended) {
this.setState({ showRecommended: true });
}
if (
!fileInfo &&
!this.state.autoDownloadStarted &&
claim &&
costInfo &&
costInfo.cost === 0 &&
(isPlayable || (this.state.uriVars && this.state.uriVars.download === 'true'))
) {
this.setState({ autoDownloadStarted: true }, () => {
if (!isPlayable) {
this.checkStoragePermissionForDownload();
} else {
this.confirmPurchaseUri(claim.permanent_url, costInfo, !isPlayable);
}
NativeModules.UtilityModule.checkDownloads();
});
}
}
fetchFileInfo(uri, props) {
@ -878,22 +891,6 @@ class FilePage extends React.PureComponent {
const localFileUri = this.localUriForFileInfo(fileInfo);
const unsupported = !isPlayable && !canOpen;
if (
!this.state.autoDownloadStarted &&
claim &&
costInfo &&
((isPlayable && costInfo.cost === 0) || (this.state.uriVars && this.state.uriVars.download === 'true'))
) {
this.setState({ autoDownloadStarted: true }, () => {
if (!isPlayable) {
this.checkStoragePermissionForDownload();
} else {
this.confirmPurchaseUri(claim.permanent_url, costInfo, !isPlayable);
}
NativeModules.UtilityModule.checkDownloads();
});
}
if (this.state.downloadPressed && canOpen && !this.state.autoOpened) {
// automatically open a web viewable or image file after the download button is pressed
this.setState({ autoOpened: true }, () => this.openFile(localFileUri, mediaType));