Redux #115

Merged
6ea86b96 merged 57 commits from redux into redux 2017-05-05 22:55:12 +02:00
2 changed files with 19 additions and 8 deletions
Showing only changes of commit 0419b0eb24 - Show all commits

View file

@ -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'))
}

View file

@ -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,
})
}