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, {
|
|
|
|
isFileListPending: 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
|
|
|
|
|
|
|
reducers[types.FILE_LIST_COMPLETED] = 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, {
|
|
|
|
isFileListPending: 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-06-06 23:19:12 +02:00
|
|
|
const newDownloading = Object.assign({}, state.urisDownloading);
|
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
newDownloading[uri] = 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-05-19 01:14:26 +02:00
|
|
|
urisDownloading: newDownloading,
|
|
|
|
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-06-06 23:19:12 +02:00
|
|
|
const newDownloading = Object.assign({}, state.urisDownloading);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-27 10:23:03 +02:00
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
2017-06-06 23:19:12 +02:00
|
|
|
newDownloading[uri] = true;
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-06-06 23:19:12 +02:00
|
|
|
urisDownloading: newDownloading,
|
|
|
|
});
|
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-06-06 23:19:12 +02:00
|
|
|
const newDownloading = Object.assign({}, state.urisDownloading);
|
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 newDownloading[uri];
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint: newByOutpoint,
|
2017-05-19 01:14:26 +02:00
|
|
|
urisDownloading: 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-04-29 19:02:25 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
delete newByOutpoint[outpoint];
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
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-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-06-17 19:59:18 +02:00
|
|
|
reducers[types.PUBLISH_STARTED] = function(state, action) {
|
|
|
|
const { pendingPublish } = action.data;
|
|
|
|
const pendingByOutpoint = Object.assign({}, state.pendingByOutpoint);
|
|
|
|
|
|
|
|
pendingByOutpoint[pendingPublish.outpoint] = pendingPublish;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
pendingByOutpoint,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.PUBLISH_COMPLETED] = function(state, action) {
|
|
|
|
const { pendingPublish } = action.data;
|
|
|
|
const pendingByOutpoint = Object.assign({}, state.pendingByOutpoint);
|
|
|
|
|
|
|
|
delete pendingByOutpoint[pendingPublish.outpoint];
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
pendingByOutpoint,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.PUBLISH_FAILED] = function(state, action) {
|
|
|
|
const { pendingPublish } = action.data;
|
|
|
|
const pendingByOutpoint = Object.assign({}, state.pendingByOutpoint);
|
|
|
|
|
|
|
|
delete pendingByOutpoint[pendingPublish.outpoint];
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
pendingByOutpoint,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// reducers[types.PUBLISH_COMPLETED] = function(state, action) {
|
|
|
|
// const { claim } = action.data;
|
|
|
|
// const uri = lbryuri.build({
|
|
|
|
// txid: claim.txId
|
|
|
|
// })
|
|
|
|
// const newPendingPublish = {
|
|
|
|
// name,
|
|
|
|
// channel_name,
|
|
|
|
// claim_id: "pending_claim_" + uri,
|
|
|
|
// txid: "pending_" + uri,
|
|
|
|
// nout: 0,
|
|
|
|
// outpoint: "pending_" + uri + ":0",
|
|
|
|
// time: Date.now(),
|
|
|
|
// };
|
|
|
|
// const fileInfos = Object.assign({}, state.fileInfos)
|
|
|
|
// fileInfos[newPendingPublish.outpoint] = newPendingPublish
|
|
|
|
|
|
|
|
// return Object.assign({}, state, {
|
|
|
|
// fileInfos,
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
|
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;
|
|
|
|
}
|