lbry-desktop/ui/component/fileViewCount/view.jsx

54 lines
1.6 KiB
React
Raw Normal View History

2020-01-06 13:32:35 -05:00
// @flow
import { SIMPLE_SITE } from 'config';
import React from 'react';
2020-01-06 13:32:35 -05:00
import HelpLink from 'component/common/help-link';
type Props = {
claim: ?StreamClaim,
fetchViewCount: (string) => void,
2021-06-17 14:55:23 -04:00
fetchingViewCount: boolean,
uri: string,
2020-01-06 13:32:35 -05:00
viewCount: string,
livestream?: boolean,
activeViewers?: number,
isLive?: boolean,
doAnalyticsView: (string) => void,
2020-01-06 13:32:35 -05:00
};
2020-01-06 15:57:49 -05:00
function FileViewCount(props: Props) {
const { claim, uri, fetchViewCount, viewCount, livestream, activeViewers, isLive = false, doAnalyticsView } = props;
const claimId = claim && claim.claim_id;
React.useEffect(() => {
if (livestream) {
// Regular claims will call the file/view event when a user actually watches the claim
// This can be removed when we get rid of the livestream iframe
doAnalyticsView(uri);
}
}, [livestream, doAnalyticsView, uri]);
React.useEffect(() => {
if (claimId) {
fetchViewCount(claimId);
}
}, [fetchViewCount, uri, claimId]);
2020-01-06 13:32:35 -05:00
2020-05-25 12:19:15 -04:00
const formattedViewCount = Number(viewCount).toLocaleString();
2020-01-06 13:32:35 -05:00
return (
2020-09-30 16:46:20 -04:00
<span className="media__subtitle--centered">
2021-06-17 14:55:23 -04:00
{isLive &&
__('%viewer_count% currently %viewer_state%', {
viewer_count: activeViewers === undefined ? '...' : activeViewers,
viewer_state: isLive ? __('watching') : __('waiting'),
})}
{!isLive &&
activeViewers === undefined &&
(viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view'))}
{!SIMPLE_SITE && <HelpLink href="https://lbry.com/faq/views" />}
2020-01-06 13:32:35 -05:00
</span>
);
}
2020-01-06 15:57:49 -05:00
export default FileViewCount;