2018-04-05 03:57:29 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
|
|
|
|
const reducers = {};
|
2018-10-17 14:22:17 -04:00
|
|
|
const defaultState = {
|
|
|
|
downloadListSort: '',
|
|
|
|
publishListSort: '',
|
|
|
|
};
|
2018-04-05 03:57:29 +01:00
|
|
|
|
|
|
|
reducers[ACTIONS.FILE_LIST_STARTED] = state =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
isFetchingFileList: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
reducers[ACTIONS.FILE_LIST_SUCCEEDED] = (state, action) => {
|
|
|
|
const { fileInfos } = action.data;
|
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
|
|
|
const pendingByOutpoint = Object.assign({}, state.pendingByOutpoint);
|
|
|
|
|
|
|
|
fileInfos.forEach(fileInfo => {
|
|
|
|
const { outpoint } = fileInfo;
|
|
|
|
|
|
|
|
if (outpoint) newByOutpoint[fileInfo.outpoint] = fileInfo;
|
|
|
|
});
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
isFetchingFileList: false,
|
|
|
|
byOutpoint: newByOutpoint,
|
|
|
|
pendingByOutpoint,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.FETCH_FILE_INFO_STARTED] = (state, action) => {
|
|
|
|
const { outpoint } = action.data;
|
|
|
|
const newFetching = Object.assign({}, state.fetching);
|
|
|
|
|
|
|
|
newFetching[outpoint] = true;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
fetching: newFetching,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.FETCH_FILE_INFO_COMPLETED] = (state, action) => {
|
|
|
|
const { fileInfo, outpoint } = action.data;
|
|
|
|
|
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
|
|
|
const newFetching = Object.assign({}, state.fetching);
|
|
|
|
|
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
|
|
|
delete newFetching[outpoint];
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
byOutpoint: newByOutpoint,
|
|
|
|
fetching: newFetching,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.DOWNLOADING_STARTED] = (state, action) => {
|
|
|
|
const { uri, outpoint, fileInfo } = action.data;
|
|
|
|
|
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
|
|
|
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
|
|
|
|
|
|
|
newDownloading[outpoint] = true;
|
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
|
|
|
delete newLoading[uri];
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
downloadingByOutpoint: newDownloading,
|
|
|
|
urisLoading: newLoading,
|
|
|
|
byOutpoint: newByOutpoint,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.DOWNLOADING_PROGRESSED] = (state, action) => {
|
|
|
|
const { outpoint, fileInfo } = action.data;
|
|
|
|
|
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
|
|
|
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
|
|
|
|
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
|
|
|
newDownloading[outpoint] = true;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
byOutpoint: newByOutpoint,
|
|
|
|
downloadingByOutpoint: newDownloading,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.DOWNLOADING_COMPLETED] = (state, action) => {
|
|
|
|
const { outpoint, fileInfo } = action.data;
|
|
|
|
|
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
|
|
|
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
|
|
|
|
|
|
|
newByOutpoint[outpoint] = fileInfo;
|
|
|
|
delete newDownloading[outpoint];
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
byOutpoint: newByOutpoint,
|
|
|
|
downloadingByOutpoint: newDownloading,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.FILE_DELETE] = (state, action) => {
|
|
|
|
const { outpoint } = action.data;
|
|
|
|
|
|
|
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
|
|
|
const downloadingByOutpoint = Object.assign({}, state.downloadingByOutpoint);
|
|
|
|
|
|
|
|
delete newByOutpoint[outpoint];
|
|
|
|
delete downloadingByOutpoint[outpoint];
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
byOutpoint: newByOutpoint,
|
|
|
|
downloadingByOutpoint,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.LOADING_VIDEO_STARTED] = (state, action) => {
|
|
|
|
const { uri } = action.data;
|
|
|
|
|
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
|
|
|
newLoading[uri] = true;
|
|
|
|
|
2018-07-13 12:14:26 -04:00
|
|
|
const newErrors = { ...state.errors };
|
|
|
|
if (uri in newErrors) delete newErrors[uri];
|
|
|
|
|
2018-04-05 03:57:29 +01:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
urisLoading: newLoading,
|
2018-07-13 12:14:26 -04:00
|
|
|
errors: { ...newErrors },
|
2018-04-05 03:57:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.LOADING_VIDEO_FAILED] = (state, action) => {
|
|
|
|
const { uri } = action.data;
|
|
|
|
|
|
|
|
const newLoading = Object.assign({}, state.urisLoading);
|
|
|
|
delete newLoading[uri];
|
|
|
|
|
2018-07-13 12:14:26 -04:00
|
|
|
const newErrors = { ...state.errors };
|
|
|
|
newErrors[uri] = true;
|
|
|
|
|
2018-04-05 03:57:29 +01:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
urisLoading: newLoading,
|
2018-07-13 12:14:26 -04:00
|
|
|
errors: { ...newErrors },
|
2018-04-05 03:57:29 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[ACTIONS.FETCH_DATE] = (state, action) => {
|
|
|
|
const { time } = action.data;
|
|
|
|
if (time) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
publishedDate: time,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2018-10-17 14:22:17 -04:00
|
|
|
reducers[ACTIONS.SET_PUBLISH_LIST_SORT] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
publishListSort: action.data,
|
|
|
|
});
|
|
|
|
|
|
|
|
reducers[ACTIONS.SET_DOWNLOAD_LIST_SORT] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
downloadListSort: action.data,
|
|
|
|
});
|
|
|
|
|
2018-04-05 03:57:29 +01:00
|
|
|
export function fileInfoReducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|