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