2020-01-06 13:32:35 -05:00
|
|
|
// @flow
|
2021-04-14 11:40:36 -04:00
|
|
|
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 = {
|
2021-11-17 17:23:01 +08:00
|
|
|
livestream?: boolean,
|
|
|
|
isLive?: boolean,
|
|
|
|
// --- redux ---
|
|
|
|
claimId: ?string,
|
2021-04-14 11:40:36 -04:00
|
|
|
fetchViewCount: (string) => void,
|
2020-04-01 14:43:50 -04:00
|
|
|
uri: string,
|
2020-01-06 13:32:35 -05:00
|
|
|
viewCount: string,
|
2021-04-14 11:40:36 -04:00
|
|
|
activeViewers?: number,
|
2020-01-06 13:32:35 -05:00
|
|
|
};
|
|
|
|
|
2020-01-06 15:57:49 -05:00
|
|
|
function FileViewCount(props: Props) {
|
2021-12-16 15:59:13 -06:00
|
|
|
const { claimId, fetchViewCount, viewCount, livestream, activeViewers, isLive = false } = props;
|
2021-04-14 11:40:36 -04:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
2020-12-11 14:46:59 -05:00
|
|
|
if (claimId) {
|
|
|
|
fetchViewCount(claimId);
|
2020-04-01 14:43:50 -04:00
|
|
|
}
|
2022-01-04 12:40:31 -06:00
|
|
|
}, [claimId]); // eslint-disable-line react-hooks/exhaustive-deps
|
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-07-18 13:06:52 -04:00
|
|
|
{livestream &&
|
2021-06-17 14:55:23 -04:00
|
|
|
__('%viewer_count% currently %viewer_state%', {
|
|
|
|
viewer_count: activeViewers === undefined ? '...' : activeViewers,
|
|
|
|
viewer_state: isLive ? __('watching') : __('waiting'),
|
|
|
|
})}
|
2021-07-18 13:06:52 -04:00
|
|
|
{!livestream &&
|
2021-06-17 14:55:23 -04:00
|
|
|
activeViewers === undefined &&
|
|
|
|
(viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view'))}
|
2021-10-21 16:21:51 -04:00
|
|
|
{!SIMPLE_SITE && <HelpLink href="https://odysee.com/@OdyseeHelp:b/OdyseeBasics:c" />}
|
2020-01-06 13:32:35 -05:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-06 15:57:49 -05:00
|
|
|
export default FileViewCount;
|