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