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-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 selectIsFileListPending = createSelector(
|
2017-04-28 17:14:44 +02:00
|
|
|
_selectState,
|
2017-05-18 19:58:28 +02:00
|
|
|
(state) => state.isFileListPending
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectAllFileInfos = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.fileInfos || {}
|
2017-04-28 17:14:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloading = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.downloading || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloadingByUri = createSelector(
|
|
|
|
selectDownloading,
|
|
|
|
(downloading) => downloading.byUri || {}
|
|
|
|
)
|
|
|
|
|
2017-05-18 19:58:28 +02:00
|
|
|
export const selectFetchingDownloadedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => !!state.fetchingDownloadedContent
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloadedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.downloadedContent || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectDownloadedContentFileInfos = createSelector(
|
|
|
|
selectDownloadedContent,
|
|
|
|
(downloadedContent) => downloadedContent.fileInfos || []
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectFetchingPublishedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => !!state.fetchingPublishedContent
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectPublishedContent = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.publishedContent || {}
|
|
|
|
)
|
|
|
|
|
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],
|
|
|
|
outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined
|
|
|
|
|
|
|
|
console.log('select file info')
|
|
|
|
console.log(claims)
|
|
|
|
console.log(claim)
|
|
|
|
console.log(outpoint)
|
|
|
|
console.log(selectAllFileInfos(state))
|
|
|
|
return outpoint ? selectAllFileInfos(state)[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
|
|
|
|
|
|
|
const selectDownloadingForUri = (state, props) => {
|
|
|
|
const byUri = selectDownloadingByUri(state)
|
|
|
|
return byUri[props.uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectDownloadingForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectDownloadingForUri,
|
|
|
|
(downloadingForUri) => !!downloadingForUri
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const selectLoading = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.loading || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectLoadingByUri = createSelector(
|
|
|
|
selectLoading,
|
|
|
|
(loading) => loading.byUri || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
const selectLoadingForUri = (state, props) => {
|
|
|
|
const byUri = selectLoadingByUri(state)
|
|
|
|
return byUri[props.uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectLoadingForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectLoadingForUri,
|
|
|
|
(loading) => !!loading
|
|
|
|
)
|
|
|
|
}
|
2017-04-30 18:01:43 +02:00
|
|
|
|
|
|
|
export const selectDownloadedFileInfo = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
selectAllFileInfos,
|
|
|
|
(fileInfos) => {
|
2017-04-30 18:01:43 +02:00
|
|
|
const fileInfoList = []
|
2017-05-18 19:58:28 +02:00
|
|
|
Object.keys(fileInfos).forEach(outpoint => {
|
|
|
|
const fileInfo = fileInfos[outpoint]
|
2017-04-30 18:01:43 +02:00
|
|
|
if (fileInfo.completed || fileInfo.written_bytes) {
|
|
|
|
fileInfoList.push(fileInfo)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return fileInfoList
|
|
|
|
}
|
|
|
|
)
|
2017-05-01 08:26:09 +02:00
|
|
|
|
|
|
|
export const selectPublishedFileInfo = createSelector(
|
2017-05-18 19:58:28 +02:00
|
|
|
selectAllFileInfos,
|
2017-05-01 08:26:09 +02:00
|
|
|
selectMyClaimsOutpoints,
|
|
|
|
(byUri, outpoints) => {
|
|
|
|
const fileInfos = []
|
|
|
|
outpoints.forEach(outpoint => {
|
|
|
|
Object.keys(byUri).forEach(key => {
|
|
|
|
const fileInfo = byUri[key]
|
|
|
|
if (fileInfo.outpoint == outpoint) {
|
|
|
|
fileInfos.push(fileInfo)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return fileInfos
|
|
|
|
}
|
|
|
|
)
|