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,12 +223,15 @@ export function doDownloadFile(uri, streamInfo) {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState() const state = getState()
lbry.file_list({ outpoint: streamInfo.outpoint, full_status: true }).then(([fileInfo]) => {
dispatch({ dispatch({
type: types.DOWNLOADING_STARTED, type: types.DOWNLOADING_STARTED,
data: { data: {
uri, uri,
fileInfo,
} }
}) })
})
lbryio.call('file', 'view', { lbryio.call('file', 'view', {
uri: uri, uri: uri,
@ -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'))
} }

View file

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