Make it easier for the next person to add View Count in specific pages.
This commit is contained in:
parent
f8f9b86cb4
commit
6b39fc1bbb
1 changed files with 11 additions and 7 deletions
|
@ -2,6 +2,15 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import 'scss/component/_view_count.scss';
|
import 'scss/component/_view_count.scss';
|
||||||
|
|
||||||
|
// 1. 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).
|
||||||
|
// 2. The page would need to call `useFetchViewCount` as well.
|
||||||
|
const ALLOWED_PAGES = [
|
||||||
|
'/@',
|
||||||
|
// `/$/${PAGES.SEARCH}`,
|
||||||
|
];
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
isLivestream?: boolean,
|
isLivestream?: boolean,
|
||||||
|
@ -16,7 +25,6 @@ export default function FileViewCountInline(props: Props) {
|
||||||
let formattedViewCount;
|
let formattedViewCount;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// SI notation that changes 1234 to 1.2K, look up Intl.NumberFormat() for docs
|
|
||||||
formattedViewCount = Number(viewCount).toLocaleString(lang || 'en', {
|
formattedViewCount = Number(viewCount).toLocaleString(lang || 'en', {
|
||||||
compactDisplay: 'short',
|
compactDisplay: 'short',
|
||||||
notation: 'compact',
|
notation: 'compact',
|
||||||
|
@ -25,13 +33,9 @@ export default function FileViewCountInline(props: Props) {
|
||||||
formattedViewCount = Number(viewCount).toLocaleString();
|
formattedViewCount = Number(viewCount).toLocaleString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the view-count visibility to Channel Pages for now. I believe we'll
|
const isInAllowedPages = ALLOWED_PAGES.some((x) => window.location.pathname.startsWith(x));
|
||||||
// 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('/@');
|
|
||||||
|
|
||||||
// dont show if no view count, if it's a repost, a livestream or isn't a channel page
|
if (!viewCount || (claim && claim.repost_url) || isLivestream || !isInAllowedPages) {
|
||||||
if (!viewCount || (claim && claim.repost_url) || isLivestream || !isChannelPage) {
|
|
||||||
// (1) Currently, makeSelectViewCountForUri doesn't differentiate between
|
// (1) Currently, makeSelectViewCountForUri doesn't differentiate between
|
||||||
// un-fetched view-count vs zero view-count. But since it's probably not
|
// 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.
|
// ideal to highlight that a view has 0 count, let's just not show anything.
|
||||||
|
|
Loading…
Reference in a new issue