Rename fileInfo.fileInfos to fileInfo.byOutpoint #284
2 changed files with 29 additions and 30 deletions
|
@ -13,16 +13,16 @@ reducers[types.FILE_LIST_STARTED] = function(state, action) {
|
||||||
reducers[types.FILE_LIST_COMPLETED] = function(state, action) {
|
reducers[types.FILE_LIST_COMPLETED] = function(state, action) {
|
||||||
const { fileInfos } = action.data;
|
const { fileInfos } = action.data;
|
||||||
|
|
||||||
const newFileInfos = Object.assign({}, state.fileInfos);
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
||||||
fileInfos.forEach(fileInfo => {
|
fileInfos.forEach(fileInfo => {
|
||||||
const { outpoint } = fileInfo;
|
const { outpoint } = fileInfo;
|
||||||
|
|
||||||
if (outpoint) newFileInfos[fileInfo.outpoint] = fileInfo;
|
if (outpoint) newByOutpoint[fileInfo.outpoint] = fileInfo;
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
isFileListPending: false,
|
isFileListPending: false,
|
||||||
fileInfos: newFileInfos,
|
byOutpoint: newByOutpoint,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ reducers[types.FETCH_FILE_INFO_STARTED] = function(state, action) {
|
||||||
reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) {
|
reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) {
|
||||||
const { fileInfo, outpoint } = action.data;
|
const { fileInfo, outpoint } = action.data;
|
||||||
|
|
||||||
const newFileInfos = Object.assign({}, state.fileInfos);
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
||||||
const newFetching = Object.assign({}, state.fetching);
|
const newFetching = Object.assign({}, state.fetching);
|
||||||
|
|
||||||
newFileInfos[outpoint] = fileInfo;
|
newByOutpoint[outpoint] = fileInfo;
|
||||||
delete newFetching[outpoint];
|
delete newFetching[outpoint];
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fileInfos: newFileInfos,
|
byOutpoint: newByOutpoint,
|
||||||
fetching: newFetching,
|
fetching: newFetching,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -55,32 +55,32 @@ reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) {
|
||||||
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
|
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
|
||||||
const { uri, outpoint, fileInfo } = action.data;
|
const { uri, outpoint, fileInfo } = action.data;
|
||||||
|
|
||||||
const newFileInfos = Object.assign({}, state.fileInfos);
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
||||||
const newDownloading = Object.assign({}, state.urisDownloading);
|
const newDownloading = Object.assign({}, state.urisDownloading);
|
||||||
const newLoading = Object.assign({}, state.urisLoading);
|
const newLoading = Object.assign({}, state.urisLoading);
|
||||||
|
|
||||||
newDownloading[uri] = true;
|
newDownloading[uri] = true;
|
||||||
newFileInfos[outpoint] = fileInfo;
|
newByOutpoint[outpoint] = fileInfo;
|
||||||
delete newLoading[uri];
|
delete newLoading[uri];
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
urisDownloading: newDownloading,
|
urisDownloading: newDownloading,
|
||||||
urisLoading: newLoading,
|
urisLoading: newLoading,
|
||||||
fileInfos: newFileInfos,
|
byOutpoint: newByOutpoint,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[types.DOWNLOADING_PROGRESSED] = function(state, action) {
|
reducers[types.DOWNLOADING_PROGRESSED] = function(state, action) {
|
||||||
const { uri, outpoint, fileInfo } = action.data;
|
const { uri, outpoint, fileInfo } = action.data;
|
||||||
|
|
||||||
const newFileInfos = Object.assign({}, state.fileInfos);
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
||||||
const newDownloading = Object.assign({}, state.urisDownloading);
|
const newDownloading = Object.assign({}, state.urisDownloading);
|
||||||
|
|
||||||
newFileInfos[outpoint] = fileInfo;
|
byOutpoint[outpoint] = fileInfo;
|
||||||
newDownloading[uri] = true;
|
newDownloading[uri] = true;
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fileInfos: newFileInfos,
|
byOutpoint: newByOutpoint,
|
||||||
urisDownloading: newDownloading,
|
urisDownloading: newDownloading,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -88,14 +88,14 @@ reducers[types.DOWNLOADING_PROGRESSED] = function(state, action) {
|
||||||
reducers[types.DOWNLOADING_COMPLETED] = function(state, action) {
|
reducers[types.DOWNLOADING_COMPLETED] = function(state, action) {
|
||||||
const { uri, outpoint, fileInfo } = action.data;
|
const { uri, outpoint, fileInfo } = action.data;
|
||||||
|
|
||||||
const newFileInfos = Object.assign({}, state.fileInfos);
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
||||||
const newDownloading = Object.assign({}, state.urisDownloading);
|
const newDownloading = Object.assign({}, state.urisDownloading);
|
||||||
|
|
||||||
newFileInfos[outpoint] = fileInfo;
|
newByOutpoint[outpoint] = fileInfo;
|
||||||
delete newDownloading[uri];
|
delete newDownloading[uri];
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fileInfos: newFileInfos,
|
byOutpoint: newByOutpoint,
|
||||||
urisDownloading: newDownloading,
|
urisDownloading: newDownloading,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -103,12 +103,12 @@ reducers[types.DOWNLOADING_COMPLETED] = function(state, action) {
|
||||||
reducers[types.FILE_DELETE] = function(state, action) {
|
reducers[types.FILE_DELETE] = function(state, action) {
|
||||||
const { outpoint } = action.data;
|
const { outpoint } = action.data;
|
||||||
|
|
||||||
const newFileInfos = Object.assign({}, state.fileInfos);
|
const newByOutpoint = Object.assign({}, state.byOutpoint);
|
||||||
|
|
||||||
delete newFileInfos[outpoint];
|
delete newByOutpoint[outpoint];
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fileInfos: newFileInfos,
|
byOutpoint: newByOutpoint,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ import {
|
||||||
|
|
||||||
export const _selectState = state => state.fileInfo || {};
|
export const _selectState = state => state.fileInfo || {};
|
||||||
|
|
||||||
export const selectAllFileInfos = createSelector(
|
export const selectFileInfosByOutpoint = createSelector(
|
||||||
_selectState,
|
_selectState,
|
||||||
state => state.fileInfos || {}
|
state => state.byOutpoint || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectFileListIsPending = createSelector(
|
export const selectFileListIsPending = createSelector(
|
||||||
|
@ -28,10 +28,10 @@ export const selectFileListDownloadedOrPublishedIsPending = createSelector(
|
||||||
export const selectFileInfoForUri = (state, props) => {
|
export const selectFileInfoForUri = (state, props) => {
|
||||||
const claims = selectClaimsByUri(state),
|
const claims = selectClaimsByUri(state),
|
||||||
claim = claims[props.uri],
|
claim = claims[props.uri],
|
||||||
fileInfos = selectAllFileInfos(state),
|
byOutpoint = selectFileInfosByOutpoint(state),
|
||||||
outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined;
|
outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined;
|
||||||
|
|
||||||
return outpoint && fileInfos ? fileInfos[outpoint] : undefined;
|
return outpoint ? byOutpoint[outpoint] : undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const makeSelectFileInfoForUri = () => {
|
export const makeSelectFileInfoForUri = () => {
|
||||||
|
@ -70,11 +70,11 @@ export const makeSelectLoadingForUri = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selectFileInfosDownloaded = createSelector(
|
export const selectFileInfosDownloaded = createSelector(
|
||||||
selectAllFileInfos,
|
selectFileInfosByOutpoint,
|
||||||
selectMyClaimsOutpoints,
|
selectMyClaimsOutpoints,
|
||||||
(fileInfos, myClaimOutpoints) => {
|
(byOutpoint, myClaimOutpoints) => {
|
||||||
const fileInfoList = [];
|
const fileInfoList = [];
|
||||||
Object.values(fileInfos).forEach(fileInfo => {
|
Object.values(byOutpoint).forEach(fileInfo => {
|
||||||
if (
|
if (
|
||||||
fileInfo &&
|
fileInfo &&
|
||||||
myClaimOutpoints.indexOf(fileInfo.outpoint) === -1 &&
|
myClaimOutpoints.indexOf(fileInfo.outpoint) === -1 &&
|
||||||
|
@ -95,15 +95,14 @@ export const selectFileInfosPendingPublish = createSelector(
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectFileInfosPublished = createSelector(
|
export const selectFileInfosPublished = createSelector(
|
||||||
selectAllFileInfos,
|
selectFileInfosByOutpoint,
|
||||||
selectFileInfosPendingPublish,
|
selectFileInfosPendingPublish,
|
||||||
selectMyClaimsOutpoints,
|
selectMyClaimsOutpoints,
|
||||||
(allFileInfos, pendingFileInfos, outpoints) => {
|
(byOutpoint, pendingFileInfos, outpoints) => {
|
||||||
const fileInfos = [];
|
const fileInfos = [];
|
||||||
outpoints.forEach(outpoint => {
|
outpoints.forEach(outpoint => {
|
||||||
if (allFileInfos[outpoint]) {
|
const fileInfo = byOutpoint[outpoint];
|
||||||
fileInfos.push(allFileInfos[outpoint]);
|
if (fileInfo) fileInfos.push(fileInfo);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return [...fileInfos, ...pendingFileInfos];
|
return [...fileInfos, ...pendingFileInfos];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue