2017-06-06 23:19:12 +02:00
|
|
|
import lbry from "lbry";
|
|
|
|
import { createSelector } from "reselect";
|
2017-05-01 08:26:09 +02:00
|
|
|
import {
|
2017-05-18 19:58:28 +02:00
|
|
|
selectClaimsByUri,
|
2017-07-04 13:05:35 +02:00
|
|
|
selectIsFetchingClaimListMine,
|
2017-07-12 10:08:59 +02:00
|
|
|
selectMyClaims,
|
2017-05-01 08:26:09 +02:00
|
|
|
selectMyClaimsOutpoints,
|
2017-06-06 23:19:12 +02:00
|
|
|
} from "selectors/claims";
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export const _selectState = state => state.fileInfo || {};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
export const selectFileInfosByOutpoint = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
_selectState,
|
2017-06-25 09:24:45 +02:00
|
|
|
state => state.byOutpoint || {}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-07-04 13:05:35 +02:00
|
|
|
export const selectIsFetchingFileList = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
_selectState,
|
2017-07-04 13:05:35 +02:00
|
|
|
state => !!state.isFetchingFileList
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-07-04 13:05:35 +02:00
|
|
|
export const selectIsFetchingFileListDownloadedOrPublished = createSelector(
|
|
|
|
selectIsFetchingFileList,
|
|
|
|
selectIsFetchingClaimListMine,
|
|
|
|
(isFetchingFileList, isFetchingClaimListMine) =>
|
|
|
|
isFetchingFileList || isFetchingClaimListMine
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
export const selectFileInfoForUri = (state, props) => {
|
2017-05-18 19:58:28 +02:00
|
|
|
const claims = selectClaimsByUri(state),
|
2017-06-06 23:19:12 +02:00
|
|
|
claim = claims[props.uri],
|
2017-06-25 09:24:45 +02:00
|
|
|
byOutpoint = selectFileInfosByOutpoint(state),
|
2017-06-06 23:19:12 +02:00
|
|
|
outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined;
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-06-25 09:24:45 +02:00
|
|
|
return outpoint ? byOutpoint[outpoint] : undefined;
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
export const makeSelectFileInfoForUri = () => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return createSelector(selectFileInfoForUri, fileInfo => fileInfo);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-07-21 10:02:29 +02:00
|
|
|
export const selectDownloadingByOutpoint = createSelector(
|
2017-05-19 01:14:26 +02:00
|
|
|
_selectState,
|
2017-07-21 10:02:29 +02:00
|
|
|
state => state.downloadingByOutpoint || {}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
const selectDownloadingForUri = (state, props) => {
|
2017-07-21 10:02:29 +02:00
|
|
|
const byOutpoint = selectDownloadingByOutpoint(state);
|
|
|
|
const fileInfo = selectFileInfoForUri(state, props);
|
|
|
|
|
|
|
|
if (!fileInfo) return false;
|
|
|
|
|
|
|
|
return byOutpoint[fileInfo.outpoint];
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
export const makeSelectDownloadingForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectDownloadingForUri,
|
2017-06-06 23:19:12 +02:00
|
|
|
downloadingForUri => !!downloadingForUri
|
|
|
|
);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectUrisLoading = createSelector(
|
2017-04-29 19:02:25 +02:00
|
|
|
_selectState,
|
2017-06-06 23:19:12 +02:00
|
|
|
state => state.urisLoading || {}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
const selectLoadingForUri = (state, props) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const byUri = selectUrisLoading(state);
|
|
|
|
return byUri[props.uri];
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
|
|
|
|
export const makeSelectLoadingForUri = () => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return createSelector(selectLoadingForUri, loading => !!loading);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-30 18:01:43 +02:00
|
|
|
|
2017-06-17 19:59:18 +02:00
|
|
|
export const selectFileInfosPendingPublish = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => Object.values(state.pendingByOutpoint || {})
|
|
|
|
);
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectFileInfosDownloaded = createSelector(
|
2017-06-25 09:24:45 +02:00
|
|
|
selectFileInfosByOutpoint,
|
2017-07-12 10:08:59 +02:00
|
|
|
selectMyClaims,
|
|
|
|
(byOutpoint, myClaims) => {
|
|
|
|
return Object.values(byOutpoint).filter(fileInfo => {
|
|
|
|
const myClaimIds = myClaims.map(claim => claim.claim_id);
|
|
|
|
|
|
|
|
return (
|
2017-06-06 23:19:12 +02:00
|
|
|
fileInfo &&
|
2017-07-12 10:08:59 +02:00
|
|
|
myClaimIds.indexOf(fileInfo.claim_id) === -1 &&
|
2017-06-06 23:19:12 +02:00
|
|
|
(fileInfo.completed || fileInfo.written_bytes)
|
2017-07-12 10:08:59 +02:00
|
|
|
);
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-04-30 18:01:43 +02:00
|
|
|
}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-01 08:26:09 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectFileInfosPublished = createSelector(
|
2017-06-25 09:24:45 +02:00
|
|
|
selectFileInfosByOutpoint,
|
2017-05-01 08:26:09 +02:00
|
|
|
selectMyClaimsOutpoints,
|
2017-06-17 19:59:18 +02:00
|
|
|
selectFileInfosPendingPublish,
|
|
|
|
(byOutpoint, outpoints, pendingPublish) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const fileInfos = [];
|
2017-05-01 08:26:09 +02:00
|
|
|
outpoints.forEach(outpoint => {
|
2017-06-25 09:24:45 +02:00
|
|
|
const fileInfo = byOutpoint[outpoint];
|
|
|
|
if (fileInfo) fileInfos.push(fileInfo);
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-07-04 08:48:52 +02:00
|
|
|
return [...fileInfos, ...pendingPublish];
|
2017-05-01 08:26:09 +02:00
|
|
|
}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-06-24 10:57:37 +02:00
|
|
|
|
|
|
|
// export const selectFileInfoForUri = (state, props) => {
|
|
|
|
// const claims = selectClaimsByUri(state),
|
|
|
|
// claim = claims[props.uri],
|
|
|
|
// fileInfos = selectAllFileInfos(state),
|
|
|
|
// outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined;
|
|
|
|
|
|
|
|
// return outpoint && fileInfos ? fileInfos[outpoint] : undefined;
|
|
|
|
// };
|
|
|
|
|
|
|
|
export const selectFileInfosByUri = createSelector(
|
|
|
|
selectClaimsByUri,
|
2017-06-27 10:23:03 +02:00
|
|
|
selectFileInfosByOutpoint,
|
2017-06-24 10:57:37 +02:00
|
|
|
(claimsByUri, byOutpoint) => {
|
|
|
|
const fileInfos = {};
|
|
|
|
const uris = Object.keys(claimsByUri);
|
|
|
|
|
|
|
|
uris.forEach(uri => {
|
|
|
|
const claim = claimsByUri[uri];
|
|
|
|
if (claim) {
|
|
|
|
const outpoint = `${claim.txid}:${claim.nout}`;
|
|
|
|
const fileInfo = byOutpoint[outpoint];
|
|
|
|
|
|
|
|
if (fileInfo) fileInfos[uri] = fileInfo;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return fileInfos;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectDownloadingFileInfos = createSelector(
|
2017-07-21 10:02:29 +02:00
|
|
|
selectDownloadingByOutpoint,
|
|
|
|
selectFileInfosByOutpoint,
|
|
|
|
(downloadingByOutpoint, fileInfosByOutpoint) => {
|
|
|
|
const outpoints = Object.keys(downloadingByOutpoint);
|
2017-06-24 10:57:37 +02:00
|
|
|
const fileInfos = [];
|
|
|
|
|
2017-07-21 10:02:29 +02:00
|
|
|
outpoints.forEach(outpoint => {
|
|
|
|
const fileInfo = fileInfosByOutpoint[outpoint];
|
2017-06-24 10:57:37 +02:00
|
|
|
|
|
|
|
if (fileInfo) fileInfos.push(fileInfo);
|
|
|
|
});
|
|
|
|
|
|
|
|
return fileInfos;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectTotalDownloadProgress = createSelector(
|
|
|
|
selectDownloadingFileInfos,
|
|
|
|
fileInfos => {
|
|
|
|
const progress = [];
|
|
|
|
|
|
|
|
fileInfos.forEach(fileInfo => {
|
|
|
|
progress.push(fileInfo.written_bytes / fileInfo.total_bytes * 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
const totalProgress = progress.reduce((a, b) => a + b, 0);
|
|
|
|
|
|
|
|
if (fileInfos.length > 0) return totalProgress / fileInfos.length / 100.0;
|
|
|
|
else return -1;
|
|
|
|
}
|
|
|
|
);
|
2017-09-02 05:59:25 +02:00
|
|
|
|
|
|
|
export const selectPublishedDate = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.publishedDate || null
|
|
|
|
);
|