Livestream tile/list: show viewer count if data is available

As of this commit, only the Channel Page is fetching the data through the new API, which has the viewer count correctly populated.

For both "0" and "undefined", continue to show as "LIVE".
This commit is contained in:
infinite-persistence 2022-04-15 19:02:51 +08:00 committed by Thomas Zarebczan
parent 5cb94ace84
commit 6e34282cdc
4 changed files with 31 additions and 5 deletions

View file

@ -15,7 +15,7 @@ import { makeSelectCollectionIsMine } from 'redux/selectors/collections';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { doFileGet } from 'redux/actions/file'; import { doFileGet } from 'redux/actions/file';
import { selectBanStateForUri } from 'lbryinc'; import { selectBanStateForUri } from 'lbryinc';
import { selectIsActiveLivestreamForUri } from 'redux/selectors/livestream'; import { selectIsActiveLivestreamForUri, selectViewersForId } from 'redux/selectors/livestream';
import { selectLanguage, selectShowMatureContent } from 'redux/selectors/settings'; import { selectLanguage, selectShowMatureContent } from 'redux/selectors/settings';
import { makeSelectHasVisitedUri } from 'redux/selectors/content'; import { makeSelectHasVisitedUri } from 'redux/selectors/content';
import { selectIsSubscribedForUri } from 'redux/selectors/subscriptions'; import { selectIsSubscribedForUri } from 'redux/selectors/subscriptions';
@ -48,6 +48,7 @@ const select = (state, props) => {
wasPurchased: props.uri && makeSelectClaimWasPurchased(props.uri)(state), wasPurchased: props.uri && makeSelectClaimWasPurchased(props.uri)(state),
isLivestream, isLivestream,
isLivestreamActive: isLivestream && selectIsActiveLivestreamForUri(state, props.uri), isLivestreamActive: isLivestream && selectIsActiveLivestreamForUri(state, props.uri),
livestreamViewerCount: isLivestream && claim ? selectViewersForId(state, claim.claim_id) : undefined,
isCollectionMine: makeSelectCollectionIsMine(props.collectionId)(state), isCollectionMine: makeSelectCollectionIsMine(props.collectionId)(state),
lang: selectLanguage(state), lang: selectLanguage(state),
}; };

View file

@ -12,6 +12,7 @@ import { formatLbryUrlForWeb } from 'util/url';
import { formatClaimPreviewTitle } from 'util/formatAriaLabel'; import { formatClaimPreviewTitle } from 'util/formatAriaLabel';
import { toCompactNotation } from 'util/string'; import { toCompactNotation } from 'util/string';
import ClaimPreviewProgress from 'component/claimPreviewProgress'; import ClaimPreviewProgress from 'component/claimPreviewProgress';
import Icon from 'component/common/icon';
import Tooltip from 'component/common/tooltip'; import Tooltip from 'component/common/tooltip';
import FileThumbnail from 'component/fileThumbnail'; import FileThumbnail from 'component/fileThumbnail';
import UriIndicator from 'component/uriIndicator'; import UriIndicator from 'component/uriIndicator';
@ -34,6 +35,7 @@ import ClaimPreviewHidden from './claim-preview-no-mature';
import ClaimPreviewNoContent from './claim-preview-no-content'; import ClaimPreviewNoContent from './claim-preview-no-content';
import { ENABLE_NO_SOURCE_CLAIMS } from 'config'; import { ENABLE_NO_SOURCE_CLAIMS } from 'config';
import CollectionEditButtons from 'component/collectionEditButtons'; import CollectionEditButtons from 'component/collectionEditButtons';
import * as ICONS from 'constants/icons';
import { useIsMobile } from 'effects/use-screensize'; import { useIsMobile } from 'effects/use-screensize';
const AbandonedChannelPreview = lazyImport(() => const AbandonedChannelPreview = lazyImport(() =>
@ -80,6 +82,7 @@ type Props = {
hideMenu?: boolean, hideMenu?: boolean,
isLivestream?: boolean, isLivestream?: boolean,
isLivestreamActive: boolean, isLivestreamActive: boolean,
livestreamViewerCount: ?number,
collectionId?: string, collectionId?: string,
isCollectionMine: boolean, isCollectionMine: boolean,
disableNavigation?: boolean, // DEPRECATED - use 'nonClickable'. Remove this when channel-finder is consolidated (#810) disableNavigation?: boolean, // DEPRECATED - use 'nonClickable'. Remove this when channel-finder is consolidated (#810)
@ -146,6 +149,7 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
// repostUrl, // repostUrl,
isLivestream, isLivestream,
isLivestreamActive, isLivestreamActive,
livestreamViewerCount,
collectionId, collectionId,
isCollectionMine, isCollectionMine,
disableNavigation, disableNavigation,
@ -333,8 +337,16 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
let liveProperty = null; let liveProperty = null;
if (isLivestreamActive === true) { if (isLivestreamActive === true) {
if (livestreamViewerCount) {
liveProperty = (claim) => (
<span className="livestream__viewer-count">
{livestreamViewerCount} <Icon icon={ICONS.EYE} />
</span>
);
} else {
liveProperty = (claim) => <>LIVE</>; liveProperty = (claim) => <>LIVE</>;
} }
}
return ( return (
<WrapperElement <WrapperElement

View file

@ -8,7 +8,7 @@ import {
import { doFileGet } from 'redux/actions/file'; import { doFileGet } from 'redux/actions/file';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { selectViewCountForUri, selectBanStateForUri } from 'lbryinc'; import { selectViewCountForUri, selectBanStateForUri } from 'lbryinc';
import { selectIsActiveLivestreamForUri } from 'redux/selectors/livestream'; import { selectIsActiveLivestreamForUri, selectViewersForId } from 'redux/selectors/livestream';
import { selectShowMatureContent } from 'redux/selectors/settings'; import { selectShowMatureContent } from 'redux/selectors/settings';
import { isClaimNsfw, isStreamPlaceholderClaim, getThumbnailFromClaim } from 'util/claim'; import { isClaimNsfw, isStreamPlaceholderClaim, getThumbnailFromClaim } from 'util/claim';
import ClaimPreviewTile from './view'; import ClaimPreviewTile from './view';
@ -32,6 +32,7 @@ const select = (state, props) => {
isMature: claim ? isClaimNsfw(claim) : false, isMature: claim ? isClaimNsfw(claim) : false,
isLivestream, isLivestream,
isLivestreamActive: isLivestream && selectIsActiveLivestreamForUri(state, props.uri), isLivestreamActive: isLivestream && selectIsActiveLivestreamForUri(state, props.uri),
livestreamViewerCount: isLivestream && claim ? selectViewersForId(state, claim.claim_id) : undefined,
viewCount: selectViewCountForUri(state, props.uri), viewCount: selectViewCountForUri(state, props.uri),
}; };
}; };

View file

@ -5,6 +5,7 @@ import { NavLink, withRouter } from 'react-router-dom';
import ClaimPreviewProgress from 'component/claimPreviewProgress'; import ClaimPreviewProgress from 'component/claimPreviewProgress';
import FileThumbnail from 'component/fileThumbnail'; import FileThumbnail from 'component/fileThumbnail';
import UriIndicator from 'component/uriIndicator'; import UriIndicator from 'component/uriIndicator';
import Icon from 'component/common/icon';
import TruncatedText from 'component/common/truncated-text'; import TruncatedText from 'component/common/truncated-text';
import DateTime from 'component/dateTime'; import DateTime from 'component/dateTime';
import LivestreamDateTime from 'component/livestreamDateTime'; import LivestreamDateTime from 'component/livestreamDateTime';
@ -22,6 +23,7 @@ import FileWatchLaterLink from 'component/fileWatchLaterLink';
import ClaimRepostAuthor from 'component/claimRepostAuthor'; import ClaimRepostAuthor from 'component/claimRepostAuthor';
import ClaimMenuList from 'component/claimMenuList'; import ClaimMenuList from 'component/claimMenuList';
import CollectionPreviewOverlay from 'component/collectionPreviewOverlay'; import CollectionPreviewOverlay from 'component/collectionPreviewOverlay';
import * as ICONS from 'constants/icons';
import { FYP_ID } from 'constants/urlParams'; import { FYP_ID } from 'constants/urlParams';
// $FlowFixMe cannot resolve ... // $FlowFixMe cannot resolve ...
import PlaceholderTx from 'static/img/placeholderTx.gif'; import PlaceholderTx from 'static/img/placeholderTx.gif';
@ -50,6 +52,7 @@ type Props = {
isLivestream: boolean, isLivestream: boolean,
viewCount: string, viewCount: string,
isLivestreamActive: boolean, isLivestreamActive: boolean,
livestreamViewerCount: ?number,
swipeLayout: boolean, swipeLayout: boolean,
}; };
@ -75,6 +78,7 @@ function ClaimPreviewTile(props: Props) {
showNoSourceClaims, showNoSourceClaims,
isLivestream, isLivestream,
isLivestreamActive, isLivestreamActive,
livestreamViewerCount,
collectionId, collectionId,
fypId, fypId,
mediaDuration, mediaDuration,
@ -187,9 +191,17 @@ function ClaimPreviewTile(props: Props) {
} }
let liveProperty = null; let liveProperty = null;
if (isLivestream === true) { if (isLivestream) {
if (isLivestreamActive === true && livestreamViewerCount) {
liveProperty = (claim) => (
<span className="livestream__viewer-count">
{livestreamViewerCount} <Icon icon={ICONS.EYE} />
</span>
);
} else {
liveProperty = (claim) => <>LIVE</>; liveProperty = (claim) => <>LIVE</>;
} }
}
return ( return (
<li <li