From cbedc4b933caeb06186653efe51c1f2c915d0897 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Thu, 28 Oct 2021 11:39:30 +0800 Subject: [PATCH] ClaimPreviewSubtitle: fetch sub count only for channels --- ui/component/claimPreviewSubtitle/index.js | 19 ++++++++++++------- ui/component/claimPreviewSubtitle/view.jsx | 15 +++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ui/component/claimPreviewSubtitle/index.js b/ui/component/claimPreviewSubtitle/index.js index a2f83e2f7..4961b4cb3 100644 --- a/ui/component/claimPreviewSubtitle/index.js +++ b/ui/component/claimPreviewSubtitle/index.js @@ -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) => { diff --git a/ui/component/claimPreviewSubtitle/view.jsx b/ui/component/claimPreviewSubtitle/view.jsx index 959c75baa..2cf346031 100644 --- a/ui/component/claimPreviewSubtitle/view.jsx +++ b/ui/component/claimPreviewSubtitle/view.jsx @@ -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' && ( <> - {formattedSubCount} {subCount !== 1 ? __('Followers') : __('Follower')} + {subCount === 1 ? __('1 Follower') : __('%formattedSubCount% Followers', { formattedSubCount })}  • {claimsInChannel} {claimsInChannel === 1 ? __('upload') : __('uploads')}