Refactor claimAuthor
- channelUrl to cached selector also using claimForUri cached selector
This commit is contained in:
parent
7b89db17bc
commit
6443af34a0
3 changed files with 30 additions and 9 deletions
|
@ -1,9 +1,13 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { makeSelectChannelForClaimUri } from 'redux/selectors/claims';
|
||||
import { selectChannelForClaimUri } from 'redux/selectors/claims';
|
||||
import ClaimAuthor from './view';
|
||||
|
||||
const select = (state, props) => ({
|
||||
channelUri: makeSelectChannelForClaimUri(props.uri)(state),
|
||||
});
|
||||
const select = (state, props) => {
|
||||
const { uri } = props;
|
||||
|
||||
return {
|
||||
channelUri: selectChannelForClaimUri(state, uri),
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(select)(ClaimAuthor);
|
||||
|
|
|
@ -3,12 +3,13 @@ import * as React from 'react';
|
|||
import ClaimPreview from 'component/claimPreview';
|
||||
|
||||
type Props = {
|
||||
channelUri: string,
|
||||
hideActions?: boolean,
|
||||
channelSubCount?: number,
|
||||
// redux
|
||||
channelUri: string,
|
||||
};
|
||||
|
||||
function ClaimAuthor(props: Props) {
|
||||
export default function ClaimAuthor(props: Props) {
|
||||
const { channelUri, hideActions, channelSubCount } = props;
|
||||
|
||||
return channelUri ? (
|
||||
|
@ -21,8 +22,6 @@ function ClaimAuthor(props: Props) {
|
|||
channelSubCount={channelSubCount}
|
||||
/>
|
||||
) : (
|
||||
<div className="claim-preview--inline claim-preview__title">{__('Anonymous')}</div>
|
||||
<span className="claim-preview--inline claim-preview__title">{__('Anonymous')}</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default ClaimAuthor;
|
||||
|
|
|
@ -576,6 +576,24 @@ export const selectClaimIsNsfwForUri = createCachedSelector(
|
|||
}
|
||||
)((state, uri) => String(uri));
|
||||
|
||||
export const selectChannelForClaimUri = createCachedSelector(
|
||||
(state, uri, includePrefix) => includePrefix,
|
||||
selectClaimForUri,
|
||||
(includePrefix?: boolean, claim: Claim) => {
|
||||
if (!claim || !claim.signing_channel || !claim.is_channel_signature_valid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { canonical_url: canonicalUrl, permanent_url: permanentUrl } = claim.signing_channel;
|
||||
|
||||
if (canonicalUrl) {
|
||||
return includePrefix ? canonicalUrl : canonicalUrl.slice('lbry://'.length);
|
||||
} else {
|
||||
return includePrefix ? permanentUrl : permanentUrl.slice('lbry://'.length);
|
||||
}
|
||||
}
|
||||
)((state, uri) => String(uri));
|
||||
|
||||
// Returns the associated channel uri for a given claim uri
|
||||
// accepts a regular claim uri lbry://something
|
||||
// returns the channel uri that created this claim lbry://@channel
|
||||
|
|
Loading…
Reference in a new issue