2017-06-06 23:19:12 +02:00
|
|
|
import { createSelector } from "reselect";
|
|
|
|
import lbryuri from "lbryuri";
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-04 13:53:26 +02:00
|
|
|
const _selectState = state => state.claims || {};
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-04 13:53:26 +02:00
|
|
|
export const selectClaimsById = createSelector(
|
2017-04-28 17:14:44 +02:00
|
|
|
_selectState,
|
2017-06-04 13:53:26 +02:00
|
|
|
(state) => state.byId || {}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-06-04 13:53:26 +02:00
|
|
|
export const selectClaimsByUri = createSelector(
|
|
|
|
_selectState,
|
|
|
|
selectClaimsById,
|
|
|
|
(state, byId) => {
|
|
|
|
const byUri = state.claimsByUri || {};
|
|
|
|
const claims = {};
|
|
|
|
|
|
|
|
Object.keys(byUri).forEach(uri => {
|
|
|
|
const claimId = byUri[uri];
|
|
|
|
|
2017-06-05 10:48:06 +02:00
|
|
|
// NOTE returning a null claim allows us to differentiate between an
|
|
|
|
// undefined (never fetched claim) and one which just doesn't exist. Not
|
|
|
|
// the cleanest solution but couldn't think of anything better right now
|
|
|
|
if (claimId === null) {
|
|
|
|
claims[uri] = null;
|
|
|
|
} else {
|
|
|
|
const claim = byId[claimId];
|
|
|
|
|
|
|
|
claims[uri] = claim;
|
|
|
|
}
|
2017-06-04 13:53:26 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return claims;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
export const selectAllClaimsByChannel = createSelector(
|
2017-05-13 00:50:51 +02:00
|
|
|
_selectState,
|
2017-06-06 23:19:12 +02:00
|
|
|
state => state.claimsByChannel || {}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
const selectClaimForUri = (state, props) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const uri = lbryuri.normalize(props.uri);
|
|
|
|
return selectClaimsByUri(state)[uri];
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-15 05:50:59 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const makeSelectClaimForUri = () => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return createSelector(selectClaimForUri, claim => claim);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectClaimsInChannelForUri = (state, props) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return selectAllClaimsByChannel(state)[props.uri];
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const makeSelectClaimsInChannelForUri = () => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return createSelector(selectClaimsInChannelForUri, claims => claims);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
const selectMetadataForUri = (state, props) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const claim = selectClaimForUri(state, props);
|
|
|
|
const metadata =
|
|
|
|
claim && claim.value && claim.value.stream && claim.value.stream.metadata;
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const value = metadata ? metadata : claim === undefined ? undefined : null;
|
|
|
|
return value;
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
export const makeSelectMetadataForUri = () => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return createSelector(selectMetadataForUri, metadata => metadata);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
const selectSourceForUri = (state, props) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const claim = selectClaimForUri(state, props);
|
|
|
|
const source =
|
|
|
|
claim && claim.value && claim.value.stream && claim.value.stream.source;
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
return source ? source : claim === undefined ? undefined : null;
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
export const makeSelectSourceForUri = () => {
|
2017-06-06 23:19:12 +02:00
|
|
|
return createSelector(selectSourceForUri, source => source);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-01 08:26:09 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
export const makeSelectContentTypeForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectSourceForUri,
|
2017-06-06 23:19:12 +02:00
|
|
|
source => (source ? source.contentType : source)
|
|
|
|
);
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-05-15 05:50:59 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export const selectClaimListMineIsPending = createSelector(
|
2017-05-01 08:26:09 +02:00
|
|
|
_selectState,
|
2017-06-06 23:19:12 +02:00
|
|
|
state => state.isClaimListMinePending
|
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 selectMyClaims = createSelector(
|
|
|
|
_selectState,
|
2017-06-06 23:19:12 +02:00
|
|
|
state => state.myClaims || new Set()
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|
2017-05-01 08:26:09 +02:00
|
|
|
|
|
|
|
export const selectMyClaimsOutpoints = createSelector(
|
2017-05-19 01:14:26 +02:00
|
|
|
selectMyClaims,
|
2017-06-04 13:53:26 +02:00
|
|
|
selectClaimsById,
|
|
|
|
(claimIds, byId) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const outpoints = [];
|
2017-05-01 08:26:09 +02:00
|
|
|
|
2017-05-28 15:01:11 +02:00
|
|
|
claimIds.forEach(claimId => {
|
2017-06-04 13:53:26 +02:00
|
|
|
const claim = byId[claimId];
|
2017-06-06 23:19:12 +02:00
|
|
|
if (claim) outpoints.push(`${claim.txid}:${claim.nout}`);
|
2017-06-04 13:53:26 +02:00
|
|
|
})
|
2017-05-28 15:01:11 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
return outpoints;
|
2017-05-01 08:26:09 +02:00
|
|
|
}
|
2017-06-06 06:21:55 +02:00
|
|
|
);
|