From 1d549ff25898a94a13f2a54792eef9205e3b974c Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Mon, 1 May 2017 11:51:19 +0700 Subject: [PATCH] Fix purchasing from file actions and allow content to be watched when being downloaded from file actions download link --- ui/js/actions/content.js | 8 ++++++++ ui/js/component/fileActions/index.js | 3 ++- ui/js/component/fileActions/view.jsx | 7 ++++++- ui/js/component/fileTileStream/view.jsx | 6 +++--- ui/js/page/fileListPublished/index.js | 20 +++++++++++++++++++- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index 0e5c28086..f1b756491 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -13,6 +13,7 @@ import { } from 'selectors/content' import { selectCurrentUriFileInfo, + selectDownloadingByUri, } from 'selectors/file_info' import { selectCurrentUriCostInfo, @@ -249,6 +250,8 @@ export function doWatchVideo() { const balance = selectBalance(state) const fileInfo = selectCurrentUriFileInfo(state) const costInfo = selectCurrentUriCostInfo(state) + const downloadingByUri = selectDownloadingByUri(state) + const alreadyDownloading = !!downloadingByUri[uri] const { cost } = costInfo // we already fully downloaded the file @@ -256,6 +259,11 @@ export function doWatchVideo() { return Promise.resolve() } + // we are already downloading the file + if (alreadyDownloading) { + return Promise.resolve() + } + // the file is free or we have partially downloaded it if (cost <= 0.01 || fileInfo.download_directory) { dispatch(doLoadVideo()) diff --git a/ui/js/component/fileActions/index.js b/ui/js/component/fileActions/index.js index 19e66dfdb..21a2c05d0 100644 --- a/ui/js/component/fileActions/index.js +++ b/ui/js/component/fileActions/index.js @@ -30,6 +30,7 @@ import { } from 'actions/file_info' import { doWatchVideo, + doLoadVideo, } from 'actions/content' import FileActions from './view' @@ -58,10 +59,10 @@ const perform = (dispatch) => ({ closeModal: () => dispatch(doCloseModal()), openInFolder: (fileInfo) => dispatch(doOpenFileInFolder(fileInfo)), openInShell: (fileInfo) => dispatch(doOpenFileInShell(fileInfo)), - affirmPurchase: () => console.log('affirm purchase'), deleteFile: (fileInfo, deleteFromComputer) => dispatch(doDeleteFile(fileInfo, deleteFromComputer)), openModal: (modal) => dispatch(doOpenModal(modal)), downloadClick: () => dispatch(doWatchVideo()), + loadVideo: () => dispatch(doLoadVideo()) }) export default connect(makeSelect, perform)(FileActions) diff --git a/ui/js/component/fileActions/view.jsx b/ui/js/component/fileActions/view.jsx index 8b880502d..5fe6a2dea 100644 --- a/ui/js/component/fileActions/view.jsx +++ b/ui/js/component/fileActions/view.jsx @@ -23,6 +23,11 @@ class FileActionsRow extends React.Component { }) } + onAffirmPurchase() { + this.props.closeModal() + this.props.loadVideo() + } + render() { const { fileInfo, @@ -85,7 +90,7 @@ class FileActionsRow extends React.Component { openModal('confirmRemove')} label="Remove..." /> : '' } + contentLabel="Confirm Purchase" onConfirmed={this.onAffirmPurchase.bind(this)} onAborted={closeModal}> Are you sure you'd like to buy {title} for credits? : null} -
{uri}
+
navigate(`show=${uri}`)}>{uri}

- + navigate(`show=${uri}`)} title={title}> {title} @@ -114,7 +114,7 @@ class FileTileStream extends React.Component { ?

This content is Not Safe For Work. - To view adult content, please change your . + To view adult content, please change your navigate('settings')} label="Settings" />.

: null} diff --git a/ui/js/page/fileListPublished/index.js b/ui/js/page/fileListPublished/index.js index 3bf2724cf..f2b5c78f5 100644 --- a/ui/js/page/fileListPublished/index.js +++ b/ui/js/page/fileListPublished/index.js @@ -2,6 +2,24 @@ import React from 'react' import { connect } from 'react-redux' +import { + selectFetchingPublishedContent, +} from 'selectors/content' +import { + selectPublishedFileInfo, +} from 'selectors/file_info' +import { + doNavigate, +} from 'actions/app' import FileListPublished from './view' -export default connect()(FileListPublished) +const select = (state) => ({ + publishedContent: selectPublishedFileInfo(state), + fetching: selectFetchingPublishedContent(state), +}) + +const perform = (dispatch) => ({ + navigate: (path) => dispatch(doNavigate(path)), +}) + +export default connect(select, perform)(FileListPublished)