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';
|
2021-12-23 02:33:12 +01:00
|
|
|
import * as PAGES from 'constants/pages';
|
2021-09-09 09:02:31 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
isLivestream?: boolean,
|
2021-12-23 02:33:12 +01:00
|
|
|
// --- redux ---
|
2021-09-09 09:02:31 +02:00
|
|
|
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-09-16 11:01:14 +02:00
|
|
|
const { isLivestream, claim, viewCount, lang } = props;
|
|
|
|
let formattedViewCount;
|
|
|
|
|
|
|
|
try {
|
|
|
|
formattedViewCount = Number(viewCount).toLocaleString(lang || 'en', {
|
|
|
|
compactDisplay: 'short',
|
|
|
|
notation: 'compact',
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
formattedViewCount = Number(viewCount).toLocaleString();
|
|
|
|
}
|
2021-09-09 09:02:31 +02:00
|
|
|
|
2021-12-23 02:33:12 +01:00
|
|
|
// Limit the view-count visibility to specific pages for now. We'll eventually
|
2021-12-09 09:53:51 +01:00
|
|
|
// show it everywhere, so this band-aid would be the easiest to clean up
|
|
|
|
// (only one place edit/remove).
|
|
|
|
const pathname: string = window.location.pathname;
|
2021-12-23 02:33:12 +01:00
|
|
|
const isOnAllowedPage =
|
|
|
|
(pathname && pathname.startsWith('/@') && pathname.indexOf('/', 1) === -1) || // Channel Page
|
|
|
|
pathname === `/$/${PAGES.UPLOADS}`;
|
2021-09-20 03:23:04 +02:00
|
|
|
|
2021-12-23 02:33:12 +01:00
|
|
|
if (!viewCount || (claim && claim.repost_url) || isLivestream || !isOnAllowedPage) {
|
2021-12-09 09:53:51 +01:00
|
|
|
// (1) Currently, selectViewCountForUri doesn't differentiate between
|
|
|
|
// un-fetched vs zero view-count. But since it's probably not ideal to
|
2021-12-23 02:33:12 +01:00
|
|
|
// highlight that a claim has 0 view 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.
|
2021-10-28 03:30:17 +02:00
|
|
|
return null;
|
2021-09-09 09:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className="view_count">
|
|
|
|
{viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view')}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|