Redux #115
2 changed files with 19 additions and 8 deletions
|
@ -223,11 +223,14 @@ export function doDownloadFile(uri, streamInfo) {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
|
|
||||||
dispatch({
|
lbry.file_list({ outpoint: streamInfo.outpoint, full_status: true }).then(([fileInfo]) => {
|
||||||
type: types.DOWNLOADING_STARTED,
|
dispatch({
|
||||||
data: {
|
type: types.DOWNLOADING_STARTED,
|
||||||
uri,
|
data: {
|
||||||
}
|
uri,
|
||||||
|
fileInfo,
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
lbryio.call('file', 'view', {
|
lbryio.call('file', 'view', {
|
||||||
|
@ -281,11 +284,13 @@ export function doWatchVideo() {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cost <= 0.01 || fileInfo.download_directory) {
|
||||||
|
dispatch(doLoadVideo())
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
if (cost > balance) {
|
if (cost > balance) {
|
||||||
dispatch(doOpenModal('notEnoughCredits'))
|
dispatch(doOpenModal('notEnoughCredits'))
|
||||||
}
|
|
||||||
else if (cost <= 0.01 || fileInfo.written_bytes > 0) {
|
|
||||||
dispatch(doLoadVideo())
|
|
||||||
} else {
|
} else {
|
||||||
dispatch(doOpenModal('affirmPurchase'))
|
dispatch(doOpenModal('affirmPurchase'))
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,20 +211,26 @@ reducers[types.LOADING_VIDEO_FAILED] = function(state, action) {
|
||||||
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
|
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
|
||||||
const {
|
const {
|
||||||
uri,
|
uri,
|
||||||
|
fileInfo,
|
||||||
} = action.data
|
} = action.data
|
||||||
const newDownloading = Object.assign({}, state.downloading)
|
const newDownloading = Object.assign({}, state.downloading)
|
||||||
const newByUri = Object.assign({}, newDownloading.byUri)
|
const newByUri = Object.assign({}, newDownloading.byUri)
|
||||||
const newLoading = Object.assign({}, state.loading)
|
const newLoading = Object.assign({}, state.loading)
|
||||||
const newLoadingByUri = Object.assign({}, newLoading.byUri)
|
const newLoadingByUri = Object.assign({}, newLoading.byUri)
|
||||||
|
const newFileInfos = Object.assign({}, state.fileInfos)
|
||||||
|
const newFileInfosByUri = Object.assign({}, newFileInfos.byUri)
|
||||||
|
|
||||||
newByUri[uri] = true
|
newByUri[uri] = true
|
||||||
newDownloading.byUri = newByUri
|
newDownloading.byUri = newByUri
|
||||||
delete newLoadingByUri[uri]
|
delete newLoadingByUri[uri]
|
||||||
newLoading.byUri = newLoadingByUri
|
newLoading.byUri = newLoadingByUri
|
||||||
|
newFileInfosByUri[uri] = fileInfo
|
||||||
|
newFileInfos.byUri = newFileInfosByUri
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
downloading: newDownloading,
|
downloading: newDownloading,
|
||||||
loading: newLoading,
|
loading: newLoading,
|
||||||
|
fileInfos: newFileInfos,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue