2020-01-06 19:32:35 +01:00
|
|
|
// @flow
|
2021-04-14 17:40:36 +02:00
|
|
|
import React from 'react';
|
2020-01-06 19:32:35 +01:00
|
|
|
import HelpLink from 'component/common/help-link';
|
2022-01-26 00:16:28 +01:00
|
|
|
import Tooltip from 'component/common/tooltip';
|
2022-04-26 17:28:23 +02:00
|
|
|
import { formatNumber } from 'util/number';
|
2020-01-06 19:32:35 +01:00
|
|
|
|
|
|
|
type Props = {
|
2022-01-26 00:16:28 +01:00
|
|
|
claimId: ?string, // this
|
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,
|
|
|
|
};
|
|
|
|
|
2020-01-06 21:57:49 +01:00
|
|
|
function FileViewCount(props: Props) {
|
2022-01-26 00:16:28 +01:00
|
|
|
const { claimId, uri, fetchViewCount, viewCount } = props; // claimId
|
2022-04-26 17:28:23 +02:00
|
|
|
const countCompact = formatNumber(Number(viewCount), 2, true);
|
|
|
|
const countFullResolution = formatNumber(Number(viewCount), 2, false);
|
2020-04-01 20:43:50 +02:00
|
|
|
|
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
|
|
|
}
|
2020-12-11 20:46:59 +01:00
|
|
|
}, [fetchViewCount, uri, claimId]);
|
2020-01-06 19:32:35 +01:00
|
|
|
|
|
|
|
return (
|
2022-04-26 17:28:23 +02:00
|
|
|
<Tooltip title={`${countFullResolution}`}>
|
2022-01-26 00:16:28 +01:00
|
|
|
<span className="media__subtitle--centered">
|
|
|
|
{viewCount !== 1 ? __('%view_count% views', { view_count: countCompact }) : __('1 view')}
|
|
|
|
{<HelpLink href="https://lbry.com/faq/views" />}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2020-01-06 19:32:35 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:57:49 +01:00
|
|
|
export default FileViewCount;
|