From 3fd48810f13abfe82ae241f79a1be938c79c6c86 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Thu, 27 Apr 2017 22:10:39 +0700 Subject: [PATCH] Add fileinfo to action data when download starts --- ui/js/actions/content.js | 21 +++++++++++++-------- ui/js/reducers/content.js | 6 ++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index f8854b5ae..ad69d9d22 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -223,11 +223,14 @@ export function doDownloadFile(uri, streamInfo) { return function(dispatch, getState) { const state = getState() - dispatch({ - type: types.DOWNLOADING_STARTED, - data: { - uri, - } + lbry.file_list({ outpoint: streamInfo.outpoint, full_status: true }).then(([fileInfo]) => { + dispatch({ + type: types.DOWNLOADING_STARTED, + data: { + uri, + fileInfo, + } + }) }) lbryio.call('file', 'view', { @@ -281,11 +284,13 @@ export function doWatchVideo() { return Promise.resolve() } + if (cost <= 0.01 || fileInfo.download_directory) { + dispatch(doLoadVideo()) + return Promise.resolve() + } + if (cost > balance) { dispatch(doOpenModal('notEnoughCredits')) - } - else if (cost <= 0.01 || fileInfo.written_bytes > 0) { - dispatch(doLoadVideo()) } else { dispatch(doOpenModal('affirmPurchase')) } diff --git a/ui/js/reducers/content.js b/ui/js/reducers/content.js index 9d70bd438..f3de01f28 100644 --- a/ui/js/reducers/content.js +++ b/ui/js/reducers/content.js @@ -211,20 +211,26 @@ reducers[types.LOADING_VIDEO_FAILED] = function(state, action) { reducers[types.DOWNLOADING_STARTED] = function(state, action) { const { uri, + fileInfo, } = action.data const newDownloading = Object.assign({}, state.downloading) const newByUri = Object.assign({}, newDownloading.byUri) const newLoading = Object.assign({}, state.loading) const newLoadingByUri = Object.assign({}, newLoading.byUri) + const newFileInfos = Object.assign({}, state.fileInfos) + const newFileInfosByUri = Object.assign({}, newFileInfos.byUri) newByUri[uri] = true newDownloading.byUri = newByUri delete newLoadingByUri[uri] newLoading.byUri = newLoadingByUri + newFileInfosByUri[uri] = fileInfo + newFileInfos.byUri = newFileInfosByUri return Object.assign({}, state, { downloading: newDownloading, loading: newLoading, + fileInfos: newFileInfos, }) }