Stop blowing up if user attempts to download before cost info fetched

This commit is contained in:
6ea86b96 2017-05-28 18:24:10 +04:00
parent 89c4402d67
commit 37344b3517
No known key found for this signature in database
GPG key ID: B282D183E4931E8F
2 changed files with 12 additions and 3 deletions

View file

@ -16,6 +16,9 @@ import {
import {
selectCurrentModal,
} from 'selectors/app'
import {
makeSelectCostInfoForUri,
} from 'selectors/cost_info'
import {
doCloseModal,
doOpenModal,
@ -39,6 +42,7 @@ const makeSelect = () => {
const selectFileInfoForUri = makeSelectFileInfoForUri()
const selectIsAvailableForUri = makeSelectIsAvailableForUri()
const selectDownloadingForUri = makeSelectDownloadingForUri()
const selectCostInfoForUri = makeSelectCostInfoForUri()
const select = (state, props) => ({
fileInfo: selectFileInfoForUri(state, props),
@ -46,6 +50,7 @@ const makeSelect = () => {
platform: selectPlatform(state),
modal: selectCurrentModal(state),
downloading: selectDownloadingForUri(state, props),
costInfo: selectCostInfoForUri(state, props),
})
return select
@ -62,7 +67,7 @@ const perform = (dispatch) => ({
},
openModal: (modal) => dispatch(doOpenModal(modal)),
startDownload: (uri) => dispatch(doPurchaseUri(uri)),
loadVideo: (uri) => dispatch(doLoadVideo(uri))
loadVideo: (uri) => dispatch(doLoadVideo(uri)),
})
export default connect(makeSelect, perform)(FileActions)

View file

@ -62,6 +62,7 @@ class FileActions extends React.Component {
openModal,
closeModal,
startDownload,
costInfo,
} = this.props
const deleteChecked = this.state.deleteChecked,
@ -99,8 +100,11 @@ class FileActions extends React.Component {
</div>
} else if (fileInfo === null && !downloading) {
content = <Link button="text" label="Download" icon="icon-download" onClick={() => { startDownload(uri) } } />;
if (!costInfo) {
content = <BusyMessage message="Fetching cost info" />
} else {
content = <Link button="text" label="Download" icon="icon-download" onClick={() => { startDownload(uri) } } />;
}
} else if (fileInfo && fileInfo.download_path) {
content = <Link label="Open" button="text" icon="icon-folder-open" onClick={() => openInShell(fileInfo)} />;