lbry-desktop/ui/js/reducers/file_info.js

171 lines
3.6 KiB
JavaScript
Raw Normal View History

2017-04-28 17:14:44 +02:00
import * as types from 'constants/action_types'
import lbryuri from 'lbryuri'
2017-04-28 17:14:44 +02:00
const reducers = {}
const defaultState = {
}
reducers[types.FILE_LIST_STARTED] = function(state, action) {
return Object.assign({}, state, {
isFileListPending: true,
})
}
reducers[types.FILE_LIST_COMPLETED] = function(state, action) {
const {
fileInfos,
} = action.data
const newFileInfos = Object.assign({}, state.fileInfos)
fileInfos.forEach((fileInfo) => {
const { outpoint } = fileInfo
if (outpoint) newFileInfos[fileInfo.outpoint] = fileInfo
})
return Object.assign({}, state, {
isFileListPending: false,
fileInfos: newFileInfos
})
}
2017-04-28 17:14:44 +02:00
reducers[types.FETCH_FILE_INFO_STARTED] = function(state, action) {
const {
outpoint
2017-04-28 17:14:44 +02:00
} = action.data
const newFetching = Object.assign({}, state.fetching)
newFetching[outpoint] = true
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
fetching: newFetching,
})
}
reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) {
const {
fileInfo,
outpoint,
2017-04-28 17:14:44 +02:00
} = action.data
2017-05-15 05:50:59 +02:00
const newFileInfos = Object.assign({}, state.fileInfos)
2017-04-28 17:14:44 +02:00
const newFetching = Object.assign({}, state.fetching)
newFileInfos[outpoint] = fileInfo
delete newFetching[outpoint]
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
fileInfos: newFileInfos,
2017-04-28 17:14:44 +02:00
fetching: newFetching,
})
}
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
const {
uri,
outpoint,
2017-04-28 17:14:44 +02:00
fileInfo,
} = action.data
const newFileInfos = Object.assign({}, state.fileInfos)
const newDownloading = Object.assign({}, state.urisDownloading)
const newLoading = Object.assign({}, state.urisLoading)
2017-04-28 17:14:44 +02:00
newDownloading[uri] = true
newFileInfos[outpoint] = fileInfo
delete newLoading[uri]
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
urisDownloading: newDownloading,
urisLoading: newLoading,
fileInfos: newFileInfos,
2017-04-28 17:14:44 +02:00
})
}
reducers[types.DOWNLOADING_PROGRESSED] = function(state, action) {
const {
uri,
outpoint,
2017-04-28 17:14:44 +02:00
fileInfo,
} = action.data
const newFileInfos = Object.assign({}, state.fileInfos)
const newDownloading = Object.assign({}, state.urisDownloading)
2017-04-28 17:14:44 +02:00
newFileInfos[outpoint] = fileInfo
2017-04-28 17:14:44 +02:00
newDownloading[uri] = true
return Object.assign({}, state, {
fileInfos: newFileInfos,
urisDownloading: newDownloading
2017-04-28 17:14:44 +02:00
})
}
reducers[types.DOWNLOADING_COMPLETED] = function(state, action) {
const {
uri,
outpoint,
2017-04-28 17:14:44 +02:00
fileInfo,
} = action.data
const newFileInfos = Object.assign({}, state.fileInfos)
const newDownloading = Object.assign({}, state.urisDownloading)
2017-04-28 17:14:44 +02:00
newFileInfos[outpoint] = fileInfo
delete newDownloading[uri]
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
fileInfos: newFileInfos,
urisDownloading: newDownloading,
})
}
reducers[types.FILE_DELETE] = function(state, action) {
const {
outpoint,
} = action.data
const newFileInfos = Object.assign({}, state.fileInfos)
delete newFileInfos[outpoint]
return Object.assign({}, state, {
fileInfos: newFileInfos,
})
}
reducers[types.LOADING_VIDEO_STARTED] = function(state, action) {
const {
uri,
} = action.data
const newLoading = Object.assign({}, state.urisLoading)
newLoading[uri] = true
return Object.assign({}, state, {
urisLoading: newLoading,
})
}
reducers[types.LOADING_VIDEO_FAILED] = function(state, action) {
const {
uri,
} = action.data
const newLoading = Object.assign({}, state.urisLoading)
delete newLoading[uri]
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
urisLoading: newLoading,
})
}
2017-04-28 17:14:44 +02:00
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}