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';
|
2022-01-10 03:43:10 +01:00
|
|
|
import Tooltip from 'component/common/tooltip';
|
|
|
|
import { toCompactNotation } from 'util/string';
|
2020-01-06 19:32:35 +01:00
|
|
|
|
|
|
|
type Props = {
|
2021-11-17 10:23:01 +01:00
|
|
|
livestream?: boolean,
|
|
|
|
isLive?: boolean,
|
|
|
|
// --- redux ---
|
|
|
|
claimId: ?string,
|
2021-04-14 17:40:36 +02:00
|
|
|
fetchViewCount: (string) => void,
|
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
|
|
|
activeViewers?: number,
|
2022-01-11 17:42:12 +01:00
|
|
|
lang: string,
|
2020-01-06 19:32:35 +01:00
|
|
|
};
|
|
|
|
|
2020-01-06 21:57:49 +01:00
|
|
|
function FileViewCount(props: Props) {
|
2022-01-11 17:42:12 +01:00
|
|
|
const { claimId, fetchViewCount, viewCount, livestream, activeViewers, isLive = false, lang } = props;
|
2022-01-10 03:43:10 +01:00
|
|
|
const count = livestream ? activeViewers || 0 : viewCount;
|
2022-01-11 17:42:12 +01:00
|
|
|
const countCompact = toCompactNotation(count, lang, 10000);
|
2022-01-10 03:43:10 +01:00
|
|
|
const countFullResolution = Number(count).toLocaleString();
|
2021-04-14 17:40:36 +02:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
2020-12-11 20:46:59 +01:00
|
|
|
if (claimId) {
|
|
|
|
fetchViewCount(claimId);
|
2020-04-01 20:43:50 +02:00
|
|
|
}
|
2022-01-04 19:40:31 +01:00
|
|
|
}, [claimId]); // eslint-disable-line react-hooks/exhaustive-deps
|
2020-01-06 19:32:35 +01:00
|
|
|
|
|
|
|
return (
|
2022-01-11 17:42:12 +01:00
|
|
|
<Tooltip title={countFullResolution} followCursor placement="top">
|
2022-01-10 03:43:10 +01:00
|
|
|
<span className="media__subtitle--centered">
|
|
|
|
{livestream &&
|
|
|
|
__('%viewer_count% currently %viewer_state%', {
|
|
|
|
viewer_count: activeViewers === undefined ? '...' : countCompact,
|
|
|
|
viewer_state: isLive ? __('watching') : __('waiting'),
|
|
|
|
})}
|
|
|
|
{!livestream &&
|
|
|
|
activeViewers === undefined &&
|
|
|
|
(viewCount !== 1 ? __('%view_count% views', { view_count: countCompact }) : __('1 view'))}
|
|
|
|
{!SIMPLE_SITE && <HelpLink href="https://odysee.com/@OdyseeHelp:b/OdyseeBasics:c" />}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2020-01-06 19:32:35 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:57:49 +01:00
|
|
|
export default FileViewCount;
|