lbry-desktop/ui/js/selectors/claims.js

98 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-04-28 17:14:44 +02:00
import {
createSelector,
} from 'reselect'
import lbryuri from 'lbryuri'
2017-04-28 17:14:44 +02:00
export const _selectState = state => state.claims || {}
export const selectClaimsByUri = createSelector(
_selectState,
2017-05-13 00:50:51 +02:00
(state) => state.claimsByUri || {}
2017-04-28 17:14:44 +02:00
)
2017-05-15 05:50:59 +02:00
export const selectAllClaimsByChannel = createSelector(
2017-05-13 00:50:51 +02:00
_selectState,
(state) => state.claimsByChannel || {}
)
const selectClaimForUri = (state, props) => {
const uri = lbryuri.normalize(props.uri)
return selectClaimsByUri(state)[uri]
2017-05-15 05:50:59 +02:00
}
export const makeSelectClaimForUri = () => {
2017-05-15 05:50:59 +02:00
return createSelector(
selectClaimForUri,
2017-05-15 05:50:59 +02:00
(claim) => claim
)
}
2017-05-13 00:50:51 +02:00
export const selectClaimsInChannelForUri = (state, props) => {
return selectAllClaimsByChannel(state)[props.uri]
}
export const makeSelectClaimsInChannelForUri = () => {
return createSelector(
selectClaimsInChannelForUri,
(claims) => claims
)
}
const selectMetadataForUri = (state, props) => {
const claim = selectClaimForUri(state, props)
const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata
2017-05-15 05:50:59 +02:00
return metadata ? metadata : (claim === undefined ? undefined : null)
}
export const makeSelectMetadataForUri = () => {
return createSelector(
selectMetadataForUri,
(metadata) => metadata
)
}
const selectSourceForUri = (state, props) => {
const claim = selectClaimForUri(state, props)
const source = claim && claim.value && claim.value.stream && claim.value.stream.source
2017-05-15 05:50:59 +02:00
return source ? source : (claim === undefined ? undefined : null)
}
export const makeSelectSourceForUri = () => {
return createSelector(
selectSourceForUri,
(source) => source
)
}
2017-05-01 08:26:09 +02:00
2017-05-15 05:50:59 +02:00
export const makeSelectContentTypeForUri = () => {
return createSelector(
selectSourceForUri,
(source) => source ? source.contentType : source
)
}
export const selectClaimListMineIsPending = createSelector(
2017-05-01 08:26:09 +02:00
_selectState,
(state) => state.isClaimListMinePending
2017-05-01 08:26:09 +02:00
)
export const selectMyClaims = createSelector(
_selectState,
(state) => state.myClaims || {}
2017-05-01 08:26:09 +02:00
)
export const selectMyClaimsOutpoints = createSelector(
selectMyClaims,
(claims) => {
if (!claims) {
return []
}
2017-05-01 08:26:09 +02:00
return Object.values(claims).map((claim) => {
return `${claim.txid}:${claim.nout}`
})
2017-05-01 08:26:09 +02:00
}
)