2017-05-19 01:14:26 +02:00
|
|
|
import lbry from 'lbry'
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
|
|
|
createSelector,
|
|
|
|
} from 'reselect'
|
2017-05-01 08:26:09 +02:00
|
|
|
import {
|
2017-05-18 19:58:28 +02:00
|
|
|
selectClaimsByUri,
|
2017-05-19 01:14:26 +02:00
|
|
|
selectClaimListMineIsPending,
|
2017-05-01 08:26:09 +02:00
|
|
|
selectMyClaimsOutpoints,
|
|
|
|
} from 'selectors/claims'
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
export const _selectState = state => state.fileInfo || {}
|
|
|
|
|
2017-05-18 19:58:28 +02:00
|
|
|
export const selectAllFileInfos = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.fileInfos || {}
|
2017-04-28 17:14:44 +02:00
|
|
|
)
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectFileListIsPending = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
_selectState,
|
2017-05-19 01:14:26 +02:00
|
|
|
(state) => state.isFileListPending
|
2017-05-18 19:58:28 +02:00
|
|
|
)
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectFileListDownloadedOrPublishedIsPending = createSelector(
|
|
|
|
selectFileListIsPending,
|
|
|
|
selectClaimListMineIsPending,
|
|
|
|
(isFileListPending, isClaimListMinePending) => isFileListPending || isClaimListMinePending
|
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),
|
|
|
|
claim = claims[props.uri],
|
2017-05-19 01:14:26 +02:00
|
|
|
fileInfos = selectAllFileInfos(state),
|
2017-05-18 19:58:28 +02:00
|
|
|
outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
return outpoint && fileInfos ? fileInfos[outpoint] : undefined
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectFileInfoForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectFileInfoForUri,
|
|
|
|
(fileInfo) => fileInfo
|
|
|
|
)
|
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectUrisDownloading = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.urisDownloading || {}
|
|
|
|
)
|
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
const selectDownloadingForUri = (state, props) => {
|
2017-05-19 01:14:26 +02:00
|
|
|
const byUri = selectUrisDownloading(state)
|
2017-04-29 19:02:25 +02:00
|
|
|
return byUri[props.uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectDownloadingForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectDownloadingForUri,
|
|
|
|
(downloadingForUri) => !!downloadingForUri
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectUrisLoading = createSelector(
|
2017-04-29 19:02:25 +02:00
|
|
|
_selectState,
|
2017-05-19 01:14:26 +02:00
|
|
|
(state) => state.urisLoading || {}
|
2017-04-29 19:02:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const selectLoadingForUri = (state, props) => {
|
2017-05-19 01:14:26 +02:00
|
|
|
const byUri = selectUrisLoading(state)
|
2017-04-29 19:02:25 +02:00
|
|
|
return byUri[props.uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectLoadingForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectLoadingForUri,
|
|
|
|
(loading) => !!loading
|
|
|
|
)
|
|
|
|
}
|
2017-04-30 18:01:43 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectFileInfosDownloaded = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
selectAllFileInfos,
|
2017-05-19 01:14:26 +02:00
|
|
|
selectMyClaimsOutpoints,
|
|
|
|
(fileInfos, myClaimOutpoints) => {
|
2017-04-30 18:01:43 +02:00
|
|
|
const fileInfoList = []
|
2017-05-19 01:14:26 +02:00
|
|
|
Object.values(fileInfos).forEach(fileInfo => {
|
|
|
|
if (fileInfo && myClaimOutpoints.indexOf(fileInfo.outpoint) === -1 && (fileInfo.completed || fileInfo.written_bytes)) {
|
2017-04-30 18:01:43 +02:00
|
|
|
fileInfoList.push(fileInfo)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return fileInfoList
|
|
|
|
}
|
|
|
|
)
|
2017-05-01 08:26:09 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectFileInfosPendingPublish = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => {
|
|
|
|
return lbry.getPendingPublishes()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectFileInfosPublished = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
selectAllFileInfos,
|
2017-05-19 01:14:26 +02:00
|
|
|
selectFileInfosPendingPublish,
|
2017-05-01 08:26:09 +02:00
|
|
|
selectMyClaimsOutpoints,
|
2017-05-19 01:14:26 +02:00
|
|
|
(allFileInfos, pendingFileInfos, outpoints) => {
|
2017-05-01 08:26:09 +02:00
|
|
|
const fileInfos = []
|
|
|
|
outpoints.forEach(outpoint => {
|
2017-05-19 01:14:26 +02:00
|
|
|
if (allFileInfos[outpoint]) {
|
|
|
|
fileInfos.push(allFileInfos[outpoint])
|
|
|
|
}
|
2017-05-01 08:26:09 +02:00
|
|
|
})
|
2017-05-19 01:14:26 +02:00
|
|
|
return [...fileInfos, ...pendingFileInfos]
|
2017-05-01 08:26:09 +02:00
|
|
|
}
|
|
|
|
)
|