}
>
}
export function ChannelEditPage(props) {
return ;
}
export function ChannelNewPage(props) {
useTitle('New Channel');
return
}
function ChannelRow({channel}) {
const {SingleTag} = React.useContext(TagsContext);
const videosTo = `/videos/channel/${channel.id}/video`;
const {inverted} = React.useContext(ThemeContext);
const editTo = `/videos/channel/${channel.id}/edit`;
const buttonClass = `ui button secondary ${inverted}`;
return
{channel.name}
{channel.tag_name ? : null}
{channel.video_count}
{channel.url && channel.minimum_frequency ? secondsToFrequency(channel.minimum_frequency) : null}
{channel.size ? humanFileSize(channel.size) : null}
Edit
;
}
function MobileChannelRow({channel}) {
const {SingleTag} = React.useContext(TagsContext);
const editTo = `/videos/channel/${channel.id}/edit`;
const videosTo = `/videos/channel/${channel.id}/video`;
return
{channel.name}
{channel.tag_name ? : null}
Videos: {channel.video_count}
Edit
;
}
export function ChannelsPage() {
useTitle('Channels');
const {channels} = useChannels();
const [searchStr, setSearchStr] = useOneQuery('name');
// Hides Channels with few videos.
const [hideSmall, setHideSmall] = React.useState(true);
const enoughChannelsToHideSmall = channels && channels.length > 20;
const header =
setSearchStr('')}
onChange={setSearchStr}
onSubmit={null}
/>
;
const headers = [
{key: 'name', text: 'Name', sortBy: [i => i['name'].toLowerCase()], width: 8},
{key: 'tag', text: 'Tag', sortBy: [i => i['tag_name'], i => i['name'].toLowerCase()], width: 2},
{key: 'video_count', text: 'Videos', sortBy: [i => i['video_count'], i => i['name'].toLowerCase()], width: 2},
{
key: 'download_frequency',
text: 'Download Frequency',
sortBy: [i => i['minimum_frequency'], i => i['name'].toLowerCase()],
width: 2
},
{key: 'size', text: 'Size', sortBy: [i => i['size'], i => i['name'].toLowerCase()], width: 2},
{key: 'manage', text: 'Manage', width: 2},
];
const mobileHeaders = [
{key: 'name', text: 'Name', sortBy: [i => i['name'].toLowerCase()]},
{key: 'video_count', text: 'Videos', sortBy: [i => i['video_count'], i => i['name'].toLowerCase()]},
{key: 'manage', text: 'Manage'},
];
if (channels && channels.length === 0) {
return <>
{header}
No channels exist yet!
Create one.
>
} else if (channels === undefined) {
return <>
{header}
Could not fetch Channels
>
}
let filteredChannels = channels;
if (searchStr && Array.isArray(channels)) {
const re = new RegExp(_.escapeRegExp(searchStr), 'i');
filteredChannels = channels.filter(i => re.test(i['name']));
} else if (channels && hideSmall && enoughChannelsToHideSmall) {
// 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 <>
{header}
}
/>
}
/>
>
}