Merge pull request #152 from 6ea86b96/file-actions-cost-info

Stop blowing up if user attempts to download before cost info fetched
This commit is contained in:
Jeremy Kauffman 2017-05-28 11:27:35 -04:00 committed by GitHub
commit fd093f0a95
2 changed files with 12 additions and 3 deletions

View file

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

View file

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