2021-09-09 09:02:31 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
isLivestream?: boolean,
|
|
|
|
// --- 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-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) {
|
|
|
|
// No soup for you!
|
|
|
|
formattedViewCount = Number(viewCount).toLocaleString();
|
|
|
|
}
|
2021-09-09 09:02:31 +02:00
|
|
|
|
|
|
|
if (!viewCount || (claim && claim.repost_url) || isLivestream) {
|
|
|
|
// (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>
|
|
|
|
);
|
|
|
|
}
|