2017-06-06 23:19:12 +02:00
|
|
|
import * as types from "constants/action_types";
|
|
|
|
import lbryuri from "lbryuri";
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
|
|
|
const defaultState = {};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-05-18 19:58:28 +02:00
|
|
|
reducers[types.FILE_LIST_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
2017-07-04 13:05:35 +02:00
|
|
|
isFetchingFileList: true,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-07-11 09:44:45 +02:00
|
|
|
reducers[types.FILE_LIST_SUCCEEDED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { fileInfos } = action.data;
|
2017-06-25 09:24:45 +02:00
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
2017-06-17 19:59:18 +02:00
|
|
|
const pendingByOutpoint = Object.assign({}, state.pendingByOutpoint);
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
fileInfos.forEach(fileInfo => {
|
|
|
|
const { outpoint } = fileInfo;
|
2017-05-28 15:01:11 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
if (outpoint) newByOutpoint[fileInfo.outpoint] = fileInfo;
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-18 19:58:28 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-07-04 13:05:35 +02:00
|
|
|
isFetchingFileList: false,
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-06-17 19:59:18 +02:00
|
|
|
pendingByOutpoint,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-04-28 17:14:44 +02:00
|
|
|
reducers[types.FETCH_FILE_INFO_STARTED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { outpoint } = action.data;
|
|
|
|
const newFetching = Object.assign({}, state.fetching);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
newFetching[outpoint] = true;
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
fetching: newFetching,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { fileInfo, outpoint } = action.data;
|
2017-05-15 05:50:59 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
2017-06-06 23:19:12 +02:00
|
|
|
const newFetching = Object.assign({}, state.fetching);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
2017-06-06 23:19:12 +02:00
|
|
|
delete newFetching[outpoint];
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-04-28 17:14:44 +02:00
|
|
|
fetching: newFetching,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { uri, outpoint, fileInfo } = action.data;
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
2017-07-21 10:02:29 +02:00
|
|
|
const newDownloading = Object.assign({}, state.downloadingByOutpoin);
|
2017-06-06 23:19:12 +02:00
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-07-21 10:02:29 +02:00
|
|
|
newDownloading[outpoint] = true;
|
2017-06-25 09:24:45 +02:00
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
2017-06-06 23:19:12 +02:00
|
|
|
delete newLoading[uri];
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-07-21 10:02:29 +02:00
|
|
|
downloadingByOutpoint: newDownloading,
|
2017-05-19 01:14:26 +02:00
|
|
|
urisLoading: newLoading,
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
reducers[types.DOWNLOADING_PROGRESSED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { uri, outpoint, fileInfo } = action.data;
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
2017-07-21 10:02:29 +02:00
|
|
|
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-27 10:23:03 +02:00
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
2017-07-21 10:02:29 +02:00
|
|
|
newDownloading[outpoint] = true;
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-07-21 10:02:29 +02:00
|
|
|
downloadingByOutpoint: newDownloading,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
reducers[types.DOWNLOADING_COMPLETED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { uri, outpoint, fileInfo } = action.data;
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
2017-07-21 10:02:29 +02:00
|
|
|
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
2017-07-21 10:02:29 +02:00
|
|
|
delete newDownloading[outpoint];
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-07-21 10:02:29 +02:00
|
|
|
downloadingByOutpoint: newDownloading,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
reducers[types.FILE_DELETE] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { outpoint } = action.data;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
2017-07-21 10:13:45 +02:00
|
|
|
const downloadingByOutpoint = Object.assign({}, state.downloadingByOutpoint);
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
delete newByOutpoint[outpoint];
|
2017-07-21 10:13:45 +02:00
|
|
|
delete downloadingByOutpoint[outpoint];
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-07-21 10:13:45 +02:00
|
|
|
downloadingByOutpoint,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
reducers[types.LOADING_VIDEO_STARTED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { uri } = action.data;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
newLoading[uri] = true;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-05-19 01:14:26 +02:00
|
|
|
urisLoading: newLoading,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
reducers[types.LOADING_VIDEO_FAILED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { uri } = action.data;
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
delete newLoading[uri];
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-05-18 19:58:28 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-05-19 01:14:26 +02:00
|
|
|
urisLoading: newLoading,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-18 19:58:28 +02:00
|
|
|
|
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;
|
|
|
|
}
|