From 213c4c074638d55925f5f04f6c356b4819dc2854 Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 18 May 2024 18:36:20 -0600 Subject: [PATCH] Showing top 80% of Channels. --- app/src/components/Channels.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/components/Channels.js b/app/src/components/Channels.js index c02e064c..eaf5cc75 100644 --- a/app/src/components/Channels.js +++ b/app/src/components/Channels.js @@ -504,7 +504,7 @@ export function ChannelsPage() { const [searchStr, setSearchStr] = useOneQuery('name'); // Hides Channels with few videos. const [hideSmall, setHideSmall] = React.useState(true); - const enoughChannelsToHideSmall = channels && channels.length > 10; + const enoughChannelsToHideSmall = channels && channels.length > 20; const header =
@@ -562,10 +562,17 @@ export function ChannelsPage() { const re = new RegExp(_.escapeRegExp(searchStr), 'i'); filteredChannels = channels.filter(i => re.test(i['name'])); } else if (channels && hideSmall && enoughChannelsToHideSmall) { - filteredChannels = channels.filter(i => - i['video_count'] > 5 // Channels need to have at least 5 videos. - || i['name'].toLowerCase() === 'wrolpi' // Always show the WROLPi channel so users can find tutorials. - ); + // Get the top 80% of Channels. + let index80 = Math.floor(channels.length * 0.8); + const sortedChannels = channels.sort((a, b) => b.video_count - a.video_count); + let percentile = sortedChannels[index80].video_count; + filteredChannels = channels.filter(i => { + return i.video_count > percentile || i.name.toLowerCase() === 'wrolpi' + }); + if (filteredChannels.length < 21) { + // Filtering hid too many Channels, show them all. + filteredChannels = channels; + } } return <>