a199432b5c
## Issue If you navigated to a Channel Page and returned to the homepage (or any page with ClaimPreview), the view-count is shown because we have that data. ## Fix Instead of passing props around through the long "list" component chain (`ChannelContent -> ClaimListDiscover -> ClaimList -> ClaimPreview`) to indicate whether we should display it , just check the pathname at the lowest component level; I believe eventually we would display it everywhere anyways, so this we'll be the easiest to clean up.
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
// @flow
|
|
import React from 'react';
|
|
|
|
type Props = {
|
|
uri: string,
|
|
isLivestream?: boolean,
|
|
// --- select ---
|
|
claim: ?StreamClaim,
|
|
viewCount: string,
|
|
lang: ?string,
|
|
};
|
|
|
|
export default function FileViewCountInline(props: Props) {
|
|
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();
|
|
}
|
|
|
|
// 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).
|
|
const isChannelPage = window.location.pathname.startsWith('/@');
|
|
|
|
if (!viewCount || (claim && claim.repost_url) || isLivestream || !isChannelPage) {
|
|
// (1) Currently, makeSelectViewCountForUri doesn't differentiate between
|
|
// un-fetched view-count vs zero view-count. But since it's probably not
|
|
// ideal to highlight that a view has 0 count, let's just not show anything.
|
|
// (2) No idea how to get the repost source's claim ID from the repost claim,
|
|
// so hiding it for now.
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<span className="view_count">
|
|
{viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view')}
|
|
</span>
|
|
);
|
|
}
|