ClaimPreviewSubtitle: fetch sub count only for channels

This commit is contained in:
infinite-persistence 2021-10-28 11:39:30 +08:00
parent 6b39fc1bbb
commit cbedc4b933
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 21 additions and 13 deletions

View file

@ -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),
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: makeSelectSubCountForUri(props.uri)(state),
});
subCount: isChannel ? makeSelectSubCountForUri(props.uri)(state) : 0,
};
};
const perform = (dispatch) => ({
beginPublish: (name) => {

View file

@ -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 })}
&nbsp;&bull; {claimsInChannel} {claimsInChannel === 1 ? __('upload') : __('uploads')}
</span>
</>