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

37 lines
1 KiB
React
Raw Normal View History

2020-01-06 13:32:35 -05:00
// @flow
import React from 'react';
2020-01-06 13:32:35 -05:00
import HelpLink from 'component/common/help-link';
import Tooltip from 'component/common/tooltip';
2022-04-26 12:28:23 -03:00
import { formatNumber } from 'util/number';
2020-01-06 13:32:35 -05:00
type Props = {
claimId: ?string, // this
fetchViewCount: (string) => void,
2021-06-17 14:55:23 -04:00
fetchingViewCount: boolean,
uri: string,
2020-01-06 13:32:35 -05:00
viewCount: string,
};
2020-01-06 15:57:49 -05:00
function FileViewCount(props: Props) {
const { claimId, uri, fetchViewCount, viewCount } = props; // claimId
2022-04-26 12:28:23 -03:00
const countCompact = formatNumber(Number(viewCount), 2, true);
const countFullResolution = formatNumber(Number(viewCount), 2, false);
React.useEffect(() => {
if (claimId) {
fetchViewCount(claimId);
}
}, [fetchViewCount, uri, claimId]);
2020-01-06 13:32:35 -05:00
return (
2022-04-26 12:28:23 -03:00
<Tooltip title={`${countFullResolution}`}>
<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 13:32:35 -05:00
);
}
2020-01-06 15:57:49 -05:00
export default FileViewCount;