ClaimPreviewSubtitle: fetch sub count only for channels
This commit is contained in:
parent
6b39fc1bbb
commit
cbedc4b933
2 changed files with 21 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
import * as PAGES from 'constants/pages';
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
makeSelectClaimForUri,
|
||||
selectClaimForUri,
|
||||
makeSelectClaimIsPending,
|
||||
makeSelectClaimIsStreamPlaceholder,
|
||||
} from 'redux/selectors/claims';
|
||||
|
@ -10,12 +10,17 @@ import { push } from 'connected-react-router';
|
|||
import ClaimPreviewSubtitle from './view';
|
||||
import { doFetchSubCount, makeSelectSubCountForUri } from 'lbryinc';
|
||||
|
||||
const select = (state, props) => ({
|
||||
claim: makeSelectClaimForUri(props.uri)(state),
|
||||
pending: makeSelectClaimIsPending(props.uri)(state),
|
||||
isLivestream: makeSelectClaimIsStreamPlaceholder(props.uri)(state),
|
||||
subCount: makeSelectSubCountForUri(props.uri)(state),
|
||||
});
|
||||
const select = (state, props) => {
|
||||
const claim = selectClaimForUri(state, props.uri);
|
||||
const isChannel = claim && claim.value_type === 'channel';
|
||||
|
||||
return {
|
||||
claim,
|
||||
pending: makeSelectClaimIsPending(props.uri)(state),
|
||||
isLivestream: makeSelectClaimIsStreamPlaceholder(props.uri)(state),
|
||||
subCount: isChannel ? makeSelectSubCountForUri(props.uri)(state) : 0,
|
||||
};
|
||||
};
|
||||
|
||||
const perform = (dispatch) => ({
|
||||
beginPublish: (name) => {
|
||||
|
|
|
@ -21,18 +21,21 @@ type Props = {
|
|||
// previews used in channel overview and homepage (and other places?)
|
||||
function ClaimPreviewSubtitle(props: Props) {
|
||||
const { pending, uri, claim, type, beginPublish, isLivestream, fetchSubCount, subCount } = props;
|
||||
const isChannel = claim && claim.value_type === 'channel';
|
||||
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
|
||||
|
||||
const claimId = (claim && claim.claim_id) || '0';
|
||||
const formattedSubCount = Number(subCount).toLocaleString();
|
||||
React.useEffect(() => {
|
||||
fetchSubCount(claimId);
|
||||
}, [uri, fetchSubCount, claimId]);
|
||||
|
||||
let isChannel;
|
||||
React.useEffect(() => {
|
||||
if (isChannel) {
|
||||
fetchSubCount(claimId);
|
||||
}
|
||||
}, [isChannel, fetchSubCount, claimId]);
|
||||
|
||||
let name;
|
||||
try {
|
||||
({ streamName: name, isChannel } = parseURI(uri));
|
||||
({ streamName: name } = parseURI(uri));
|
||||
} catch (e) {}
|
||||
|
||||
return (
|
||||
|
@ -45,7 +48,7 @@ function ClaimPreviewSubtitle(props: Props) {
|
|||
{isChannel && type !== 'inline' && (
|
||||
<>
|
||||
<span className="claim-preview-metadata-sub-upload">
|
||||
{formattedSubCount} {subCount !== 1 ? __('Followers') : __('Follower')}
|
||||
{subCount === 1 ? __('1 Follower') : __('%formattedSubCount% Followers', { formattedSubCount })}
|
||||
• {claimsInChannel} {claimsInChannel === 1 ? __('upload') : __('uploads')}
|
||||
</span>
|
||||
</>
|
||||
|
|
Loading…
Reference in a new issue