2021-09-09 09:02:31 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2021-09-29 21:04:43 +02:00
|
|
|
import 'scss/component/_view_count.scss';
|
2022-01-04 21:40:42 +01:00
|
|
|
import { useHistory } from 'react-router';
|
2022-01-26 00:16:28 +01:00
|
|
|
import { toCompactNotation } from 'util/string';
|
2021-09-09 09:02:31 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
// --- select ---
|
|
|
|
claim: ?StreamClaim,
|
|
|
|
viewCount: string,
|
2021-09-16 11:01:14 +02:00
|
|
|
lang: ?string,
|
2021-09-09 09:02:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function FileViewCountInline(props: Props) {
|
2021-10-19 06:49:51 +02:00
|
|
|
const { claim, viewCount, lang } = props;
|
2022-01-04 21:40:42 +01:00
|
|
|
const {
|
|
|
|
location: { pathname },
|
|
|
|
} = useHistory();
|
2022-01-26 00:16:28 +01:00
|
|
|
const formattedViewCount = toCompactNotation(viewCount, lang);
|
2021-09-09 09:02:31 +02:00
|
|
|
|
2021-09-20 03:23:04 +02:00
|
|
|
// Limit the view-count visibility to Channel Pages for now. I believe we'll
|
|
|
|
// eventually show it everywhere, so this band-aid would be the easiest to
|
|
|
|
// clean up (only one place edit/remove).
|
2022-01-04 21:40:42 +01:00
|
|
|
const isChannelPage = pathname.startsWith('/@');
|
2021-09-20 03:23:04 +02:00
|
|
|
|
2021-10-19 06:49:51 +02:00
|
|
|
// dont show if no view count, if it's a repost or isn't a channel page
|
|
|
|
if (!viewCount || (claim && claim.repost_url) || !isChannelPage) {
|
2021-09-09 09:02:31 +02:00
|
|
|
// (1) Currently, makeSelectViewCountForUri doesn't differentiate between
|
2021-09-16 11:01:14 +02:00
|
|
|
// un-fetched view-count vs zero view-count. But since it's probably not
|
2021-09-09 09:02:31 +02:00
|
|
|
// ideal to highlight that a view has 0 count, let's just not show anything.
|
2021-09-16 11:01:14 +02:00
|
|
|
// (2) No idea how to get the repost source's claim ID from the repost claim,
|
2021-09-09 09:02:31 +02:00
|
|
|
// so hiding it for now.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className="view_count">
|
|
|
|
{viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view')}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|