2020-01-06 19:32:35 +01:00
|
|
|
// @flow
|
2021-04-14 17:40:36 +02:00
|
|
|
import { SIMPLE_SITE } from 'config';
|
|
|
|
import React from 'react';
|
2020-01-06 19:32:35 +01:00
|
|
|
import HelpLink from 'component/common/help-link';
|
|
|
|
|
|
|
|
type Props = {
|
2020-12-11 20:46:59 +01:00
|
|
|
claim: ?StreamClaim,
|
2021-04-14 17:40:36 +02:00
|
|
|
fetchViewCount: (string) => void,
|
2021-06-17 20:55:23 +02:00
|
|
|
fetchingViewCount: boolean,
|
2020-04-01 20:43:50 +02:00
|
|
|
uri: string,
|
2020-01-06 19:32:35 +01:00
|
|
|
viewCount: string,
|
2021-04-14 17:40:36 +02:00
|
|
|
livestream?: boolean,
|
|
|
|
activeViewers?: number,
|
|
|
|
isLive?: boolean,
|
|
|
|
doAnalyticsView: (string) => void,
|
2020-01-06 19:32:35 +01:00
|
|
|
};
|
|
|
|
|
2020-01-06 21:57:49 +01:00
|
|
|
function FileViewCount(props: Props) {
|
2021-04-14 17:40:36 +02:00
|
|
|
const { claim, uri, fetchViewCount, viewCount, livestream, activeViewers, isLive = false, doAnalyticsView } = props;
|
2020-12-11 20:46:59 +01:00
|
|
|
const claimId = claim && claim.claim_id;
|
2020-04-01 20:43:50 +02:00
|
|
|
|
2021-04-14 17:40:36 +02:00
|
|
|
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(() => {
|
2020-12-11 20:46:59 +01:00
|
|
|
if (claimId) {
|
|
|
|
fetchViewCount(claimId);
|
2020-04-01 20:43:50 +02:00
|
|
|
}
|
2020-12-11 20:46:59 +01:00
|
|
|
}, [fetchViewCount, uri, claimId]);
|
2020-01-06 19:32:35 +01:00
|
|
|
|
2020-05-25 18:19:15 +02:00
|
|
|
const formattedViewCount = Number(viewCount).toLocaleString();
|
|
|
|
|
2020-01-06 19:32:35 +01:00
|
|
|
return (
|
2020-09-30 22:46:20 +02:00
|
|
|
<span className="media__subtitle--centered">
|
2021-07-18 19:06:52 +02:00
|
|
|
{livestream &&
|
2021-06-17 20:55:23 +02:00
|
|
|
__('%viewer_count% currently %viewer_state%', {
|
|
|
|
viewer_count: activeViewers === undefined ? '...' : activeViewers,
|
|
|
|
viewer_state: isLive ? __('watching') : __('waiting'),
|
|
|
|
})}
|
2021-07-18 19:06:52 +02:00
|
|
|
{!livestream &&
|
2021-06-17 20:55:23 +02:00
|
|
|
activeViewers === undefined &&
|
|
|
|
(viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view'))}
|
2021-10-21 22:21:51 +02:00
|
|
|
{!SIMPLE_SITE && <HelpLink href="https://odysee.com/@OdyseeHelp:b/OdyseeBasics:c" />}
|
2020-01-06 19:32:35 +01:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:57:49 +01:00
|
|
|
export default FileViewCount;
|