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

34 lines
828 B
React
Raw Normal View History

2020-01-06 19:32:35 +01:00
// @flow
import React from 'react';
2020-01-06 19:32:35 +01:00
import HelpLink from 'component/common/help-link';
type Props = {
claim: ?StreamClaim,
fetchViewCount: (string) => void,
2021-06-17 20:55:23 +02:00
fetchingViewCount: boolean,
uri: string,
2020-01-06 19:32:35 +01:00
viewCount: string,
};
2020-01-06 21:57:49 +01:00
function FileViewCount(props: Props) {
2021-10-19 06:49:51 +02:00
const { claim, uri, fetchViewCount, viewCount } = props;
const claimId = claim && claim.claim_id;
React.useEffect(() => {
if (claimId) {
fetchViewCount(claimId);
}
}, [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-10-19 06:49:51 +02:00
{viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view')}
2021-10-19 01:37:58 +02:00
{<HelpLink href="https://lbry.com/faq/views" />}
2020-01-06 19:32:35 +01:00
</span>
);
}
2020-01-06 21:57:49 +01:00
export default FileViewCount;