2022-08-06 05:22:07 +00:00
|
|
|
import React, {useState} from "react";
|
2024-11-02 15:14:02 -06:00
|
|
|
import {Grid, Input, StatisticLabel, StatisticValue, TableCell, TableRow,} from "semantic-ui-react";
|
|
|
|
|
import {createChannel, deleteChannel, refreshChannel, tagChannel, tagChannelInfo, updateChannel} from "../api";
|
2022-01-12 09:38:21 -07:00
|
|
|
import {
|
2023-07-21 15:14:09 -06:00
|
|
|
APIButton,
|
2022-11-30 19:31:18 -07:00
|
|
|
BackButton,
|
2023-09-07 20:13:36 -06:00
|
|
|
ErrorMessage,
|
2022-11-09 08:33:55 -07:00
|
|
|
humanFileSize,
|
2024-08-15 19:32:01 -06:00
|
|
|
humanNumber,
|
2025-02-19 14:52:50 -07:00
|
|
|
InfoPopup,
|
2023-11-02 10:45:35 -06:00
|
|
|
SearchInput,
|
|
|
|
|
secondsToFrequency,
|
|
|
|
|
secondsToFullDuration,
|
2024-11-02 15:14:02 -06:00
|
|
|
SimpleAccordion,
|
2022-08-06 05:22:07 +00:00
|
|
|
Toggle,
|
2022-10-25 15:57:44 -06:00
|
|
|
useTitle,
|
2022-01-12 09:38:21 -07:00
|
|
|
WROLModeMessage
|
|
|
|
|
} from "./Common";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {Link, useNavigate, useParams} from "react-router-dom";
|
2021-11-01 16:42:52 -06:00
|
|
|
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
2024-11-02 15:14:02 -06:00
|
|
|
import {useChannel, useChannels, useOneQuery} from "../hooks/customHooks";
|
2022-08-06 05:22:07 +00:00
|
|
|
import _ from "lodash";
|
2024-06-25 22:12:13 -06:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Form,
|
|
|
|
|
Header,
|
|
|
|
|
Loader,
|
|
|
|
|
Modal,
|
2024-08-06 18:13:21 -06:00
|
|
|
ModalActions,
|
2024-06-25 22:12:13 -06:00
|
|
|
ModalContent,
|
2024-08-06 18:13:21 -06:00
|
|
|
ModalHeader,
|
2024-06-25 22:12:13 -06:00
|
|
|
Segment,
|
|
|
|
|
Statistic
|
|
|
|
|
} from "./Theme";
|
2023-05-03 08:28:32 -06:00
|
|
|
import {Media, ThemeContext} from "../contexts/contexts";
|
2023-01-31 18:08:07 -07:00
|
|
|
import {SortableTable} from "./SortableTable";
|
|
|
|
|
import {toast} from "react-semantic-toasts-2";
|
2024-06-25 22:12:13 -06:00
|
|
|
import {RecurringDownloadsTable} from "./admin/Downloads";
|
2024-08-06 18:13:21 -06:00
|
|
|
import {TagsContext, TagsSelector} from "../Tags";
|
2025-02-19 14:52:50 -07:00
|
|
|
import {InputForm, ToggleForm} from "../hooks/useForm";
|
2024-11-02 15:14:02 -06:00
|
|
|
import {ChannelDownloadForm, DestinationForm, DownloadTagsSelector} from "./Download";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function ChannelStatistics({statistics}) {
|
|
|
|
|
if (!statistics) {
|
2021-12-24 15:31:15 -07:00
|
|
|
return <></>
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-17 16:09:24 -07:00
|
|
|
return <Segment>
|
|
|
|
|
<Header as='h1'>Statistics</Header>
|
|
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{statistics.video_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Videos</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{humanFileSize(statistics.size, true)}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Total Size</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{humanFileSize(statistics.largest_video, true)}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Largest Video</StatisticLabel>
|
|
|
|
|
</Statistic>
|
2023-11-02 10:28:00 -06:00
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{secondsToFullDuration(statistics.length)}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Total Duration</StatisticLabel>
|
|
|
|
|
</Statistic>
|
2024-08-15 19:32:01 -06:00
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{humanNumber(statistics.video_tags)}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Video Tags</StatisticLabel>
|
|
|
|
|
</Statistic>
|
2023-02-17 16:09:24 -07:00
|
|
|
</Segment>
|
2021-12-24 15:31:15 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
export function ChannelPage({create, header}) {
|
|
|
|
|
// Used to display messages to maintainer.
|
2022-08-06 05:22:07 +00:00
|
|
|
const [error, setError] = useState(false);
|
|
|
|
|
const [success, setSuccess] = useState(false);
|
|
|
|
|
const [messageHeader, setMessageHeader] = useState();
|
|
|
|
|
const [messageContent, setMessageContent] = useState();
|
2024-11-02 15:14:02 -06:00
|
|
|
|
2024-06-25 22:12:13 -06:00
|
|
|
const [downloadModalOpen, setDownloadModalOpen] = useState(false);
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const {channelId} = useParams();
|
2024-08-06 18:13:21 -06:00
|
|
|
const {SingleTag} = React.useContext(TagsContext);
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2024-10-04 16:32:48 -06:00
|
|
|
const [tagEditModalOpen, setTagEditModalOpen] = useState(false);
|
2024-10-05 14:06:13 -06:00
|
|
|
const [newTagName, setNewTagName] = useState(null);
|
2024-08-06 18:13:21 -06:00
|
|
|
const [moveToTagDirectory, setMoveToTagDirectory] = useState(true);
|
|
|
|
|
const [newTagDirectory, setNewTagDirectory] = useState('');
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
const {channel, form, fetchChannel} = useChannel(channelId);
|
|
|
|
|
|
2024-08-06 18:13:21 -06:00
|
|
|
useTitle(_.isEmpty(channel) ? null : `${channel.name} Channel`);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2024-11-02 15:14:02 -06:00
|
|
|
if (channel && channel.tag_name !== newTagName) {
|
|
|
|
|
setNewTagName(channel.tag_name);
|
|
|
|
|
}
|
|
|
|
|
}, [channel]);
|
2022-10-25 15:57:44 -06:00
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
if (!create && !form.ready) {
|
2024-10-05 14:06:13 -06:00
|
|
|
// Waiting for editing Channel to be fetched.
|
2022-08-06 05:22:07 +00:00
|
|
|
return <Loader active/>;
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const setErrorMessage = (header, message) => {
|
|
|
|
|
setError(true);
|
|
|
|
|
setSuccess(false);
|
|
|
|
|
setMessageHeader(header);
|
|
|
|
|
setMessageContent(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const setSuccessMessage = (header, message) => {
|
|
|
|
|
setError(false);
|
|
|
|
|
setSuccess(true);
|
|
|
|
|
setMessageHeader(header);
|
|
|
|
|
setMessageContent(message);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
const handleSubmit = async () => {
|
2022-08-06 05:22:07 +00:00
|
|
|
const body = {
|
|
|
|
|
name: channel.name,
|
|
|
|
|
directory: channel.directory,
|
|
|
|
|
url: channel.url,
|
2025-02-19 14:52:50 -07:00
|
|
|
download_missing_data: channel.download_missing_data,
|
2022-08-06 05:22:07 +00:00
|
|
|
};
|
2022-11-30 19:31:18 -07:00
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
let response = null;
|
|
|
|
|
try {
|
2022-08-06 05:22:07 +00:00
|
|
|
if (create !== undefined) {
|
2024-10-05 14:06:13 -06:00
|
|
|
// Can create a Channel with a Tag.
|
2024-12-11 11:52:33 -07:00
|
|
|
body.tag_name = _.isEmpty(channel.tag_name) ? null : channel.tag_name[0];
|
2022-08-06 05:22:07 +00:00
|
|
|
response = await createChannel(body);
|
2021-11-01 16:42:52 -06:00
|
|
|
} else {
|
2022-08-06 05:22:07 +00:00
|
|
|
response = await updateChannel(channelId, body);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unexpected server response',
|
|
|
|
|
description: 'Could not save channel',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2022-11-30 19:31:18 -07:00
|
|
|
return;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2024-10-05 14:06:13 -06:00
|
|
|
if (response && response.ok) {
|
2021-11-01 16:42:52 -06:00
|
|
|
let location = response.headers.get('Location');
|
|
|
|
|
let channelResponse = await fetch(location);
|
|
|
|
|
let data = await channelResponse.json();
|
|
|
|
|
let channel = data['channel'];
|
|
|
|
|
|
|
|
|
|
if (response.status === 201) {
|
2022-08-06 05:22:07 +00:00
|
|
|
setSuccessMessage(
|
2021-11-01 16:42:52 -06:00
|
|
|
'Channel created',
|
|
|
|
|
<span>
|
2022-04-08 09:57:04 -06:00
|
|
|
Your channel was created. View it <Link to={`/videos/channel/${channel.id}/edit`}>here</Link>
|
2021-11-01 16:42:52 -06:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2022-08-06 05:22:07 +00:00
|
|
|
await fetchChannel();
|
2023-07-21 15:14:09 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Channel updated',
|
|
|
|
|
description: 'The channel was updated',
|
|
|
|
|
})
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
} else if (response) {
|
2021-11-01 16:42:52 -06:00
|
|
|
// Some error occurred.
|
|
|
|
|
let error = await response.json();
|
|
|
|
|
let cause = error.cause;
|
2024-10-05 14:06:13 -06:00
|
|
|
if (cause && cause.code === 'CHANNEL_DIRECTORY_CONFLICT') {
|
2022-08-06 05:22:07 +00:00
|
|
|
setErrorMessage(
|
2021-11-01 16:42:52 -06:00
|
|
|
'Invalid directory',
|
|
|
|
|
'This directory is already used by another channel',
|
|
|
|
|
'directory',
|
|
|
|
|
);
|
2023-07-17 14:21:27 -06:00
|
|
|
} else if (cause && cause.code === 'CHANNEL_NAME_CONFLICT') {
|
2022-08-06 05:22:07 +00:00
|
|
|
setErrorMessage(
|
2021-11-01 16:42:52 -06:00
|
|
|
'Invalid name',
|
|
|
|
|
'This channel name is already taken',
|
|
|
|
|
'name',
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2025-02-19 14:52:50 -07:00
|
|
|
setErrorMessage('Invalid channel', error.message || error.error || 'Unable to save channel. See logs.');
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
} else {
|
|
|
|
|
console.error('Did not get a response for channel!');
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const handleRefreshChannel = async (e) => {
|
2023-07-21 15:14:09 -06:00
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
await refreshChannel(channelId);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2023-07-21 15:14:09 -06:00
|
|
|
const handleDelete = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let response = await deleteChannel(channelId);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
navigate('/videos/channel');
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
setErrorMessage('Failed to delete', 'Failed to delete this channel, check logs.');
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2024-07-20 15:35:16 -06:00
|
|
|
let downloads = channel && channel.downloads ? channel.downloads : null;
|
2024-06-25 22:12:13 -06:00
|
|
|
|
|
|
|
|
const afterNewDownloadSave = async () => {
|
2024-11-02 15:14:02 -06:00
|
|
|
setDownloadModalOpen(false);
|
|
|
|
|
await form.fetcher();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onDelete = async () => {
|
|
|
|
|
await form.fetcher();
|
2024-06-25 22:12:13 -06:00
|
|
|
setDownloadModalOpen(false);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 16:32:48 -06:00
|
|
|
const handleTagEditChannel = async () => {
|
2024-08-06 18:13:21 -06:00
|
|
|
try {
|
|
|
|
|
await tagChannel(channelId, newTagName, moveToTagDirectory ? newTagDirectory : null);
|
2024-10-04 16:32:48 -06:00
|
|
|
setTagEditModalOpen(false);
|
2024-08-06 18:13:21 -06:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to tag channel', e);
|
|
|
|
|
} finally {
|
2024-08-15 21:45:06 -06:00
|
|
|
setTimeout(async () => {
|
|
|
|
|
// Delay fetch because config needs to be written.
|
|
|
|
|
await fetchChannel();
|
|
|
|
|
}, 500);
|
2024-08-06 18:13:21 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 16:32:48 -06:00
|
|
|
const handleTagSelectMoveSuggestion = async (newTagName_) => {
|
2024-08-06 18:13:21 -06:00
|
|
|
setNewTagName(newTagName_);
|
|
|
|
|
try {
|
2024-10-04 16:32:48 -06:00
|
|
|
// Get suggested Tag directory for this Tag and Channel.
|
2024-08-06 18:13:21 -06:00
|
|
|
const videosDestination = await tagChannelInfo(channelId, newTagName_);
|
|
|
|
|
setNewTagDirectory(videosDestination);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to tag channel', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 16:32:48 -06:00
|
|
|
let tagEditModal;
|
|
|
|
|
if (!create) {
|
|
|
|
|
// User is editing the Tag of the Channel.
|
|
|
|
|
tagEditModal = <Modal
|
|
|
|
|
open={tagEditModalOpen}
|
|
|
|
|
onClose={() => setTagEditModalOpen(false)}
|
|
|
|
|
closeIcon
|
|
|
|
|
>
|
|
|
|
|
<ModalHeader>{channel.tag_name ? 'Modify Tag' : 'Add Tag'}</ModalHeader>
|
|
|
|
|
<ModalContent>
|
|
|
|
|
<Grid columns={1}>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<TagsSelector
|
|
|
|
|
limit={1}
|
|
|
|
|
selectedTagNames={newTagName ? [newTagName] : []}
|
|
|
|
|
onAdd={handleTagSelectMoveSuggestion}
|
|
|
|
|
onRemove={() => handleTagSelectMoveSuggestion(null)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Toggle
|
|
|
|
|
label='Move to directory: '
|
|
|
|
|
checked={moveToTagDirectory}
|
|
|
|
|
onChange={setMoveToTagDirectory}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Input fluid
|
|
|
|
|
value={newTagDirectory}
|
|
|
|
|
onChange={(e, {value}) => setNewTagDirectory(value)}
|
|
|
|
|
disabled={!moveToTagDirectory}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</ModalContent>
|
|
|
|
|
<ModalActions>
|
|
|
|
|
<Button onClick={() => setTagEditModalOpen(false)}>Cancel</Button>
|
|
|
|
|
<APIButton
|
|
|
|
|
color='violet'
|
|
|
|
|
onClick={handleTagEditChannel}
|
|
|
|
|
obeyWROLMode={true}
|
2025-01-04 10:51:14 -07:00
|
|
|
>{moveToTagDirectory ? 'Move' : 'Save'}</APIButton>
|
2024-10-04 16:32:48 -06:00
|
|
|
</ModalActions>
|
|
|
|
|
</Modal>;
|
|
|
|
|
}
|
2024-08-06 18:13:21 -06:00
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
let channelUrlRow;
|
|
|
|
|
if (channel && channel.url) {
|
|
|
|
|
channelUrlRow = <Grid.Row columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Header as='h4'>URL</Header>
|
|
|
|
|
<a href={channel.url}>{channel.url}</a>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let channelRssUrlRow;
|
|
|
|
|
if (channel && channel.rss_url) {
|
|
|
|
|
channelRssUrlRow = <Grid.Row columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Header as='h4'>RSS URL</Header>
|
|
|
|
|
<a href={channel.rss_url}>{channel.rss_url}</a>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let channelTagRow;
|
|
|
|
|
if (channel && channel.tag_name) {
|
|
|
|
|
channelTagRow = <Grid.Row columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
{channel.tag_name && !create && <SingleTag name={channel.tag_name}/>}
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-19 14:52:50 -07:00
|
|
|
const downloadMissingDataInfo = 'Automatically download missing comments, etc, in the background.';
|
|
|
|
|
const downloadMissingDataLabel = <>Download Missing Data<InfoPopup content={downloadMissingDataInfo}/></>;
|
|
|
|
|
const downloadMissingDataRow = <Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<ToggleForm
|
|
|
|
|
form={form}
|
|
|
|
|
label={downloadMissingDataLabel}
|
|
|
|
|
path='download_missing_data'
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>;
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
let messageRow;
|
|
|
|
|
if (error || success) {
|
|
|
|
|
messageRow = <Grid.Row columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
{error &&
|
|
|
|
|
<Message negative
|
|
|
|
|
header={messageHeader}
|
|
|
|
|
content={messageContent}
|
|
|
|
|
/>}
|
|
|
|
|
{success &&
|
|
|
|
|
<Message positive
|
|
|
|
|
header={messageHeader}
|
|
|
|
|
content={messageContent}
|
|
|
|
|
/>}
|
|
|
|
|
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 11:25:46 -07:00
|
|
|
return <>
|
2022-11-30 19:31:18 -07:00
|
|
|
<BackButton/>
|
|
|
|
|
{!create &&
|
|
|
|
|
<Link to={`/videos/channel/${channel.id}/video`}>
|
|
|
|
|
<Button>Videos</Button>
|
|
|
|
|
</Link>}
|
|
|
|
|
|
2022-12-02 11:23:05 -07:00
|
|
|
<Segment>
|
|
|
|
|
<Header as="h1">{header}</Header>
|
|
|
|
|
<WROLModeMessage content='Channel page is disabled while WROL Mode is enabled.'/>
|
|
|
|
|
<Form
|
|
|
|
|
id="editChannel"
|
|
|
|
|
error={error}
|
|
|
|
|
success={success}
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
>
|
|
|
|
|
<Grid stackable columns={2}>
|
2024-11-02 15:14:02 -06:00
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<InputForm
|
|
|
|
|
form={form}
|
|
|
|
|
label="Channel Name"
|
|
|
|
|
name="name"
|
|
|
|
|
placeholder="Short Channel Name"
|
|
|
|
|
required={true}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<DestinationForm
|
|
|
|
|
form={form}
|
|
|
|
|
label='Directory'
|
|
|
|
|
name='directory'
|
|
|
|
|
path='directory'
|
|
|
|
|
required={true}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
{channelTagRow}
|
2025-02-19 14:52:50 -07:00
|
|
|
{downloadMissingDataRow}
|
2024-11-02 15:14:02 -06:00
|
|
|
{!create && (channel.url || channel.rss_url) &&
|
|
|
|
|
<SimpleAccordion title='Details'>
|
|
|
|
|
<Grid>
|
|
|
|
|
{channelUrlRow}
|
|
|
|
|
{channelRssUrlRow}
|
|
|
|
|
</Grid>
|
|
|
|
|
</SimpleAccordion>}
|
|
|
|
|
{messageRow}
|
|
|
|
|
<Grid.Row>
|
2024-10-04 16:32:48 -06:00
|
|
|
<Grid.Column width={8}>
|
|
|
|
|
{!create ?
|
2022-12-02 11:23:05 -07:00
|
|
|
<>
|
2023-07-21 15:14:09 -06:00
|
|
|
<APIButton
|
|
|
|
|
color='red'
|
|
|
|
|
size='small'
|
|
|
|
|
confirmContent='Are you sure you want to delete this channel? No video files will be deleted.'
|
2022-12-02 11:23:05 -07:00
|
|
|
confirmButton='Delete'
|
2024-10-05 14:06:13 -06:00
|
|
|
confirmHeader='Delete Channel?'
|
2023-07-21 15:14:09 -06:00
|
|
|
onClick={handleDelete}
|
|
|
|
|
obeyWROLMode={true}
|
2024-06-25 22:12:13 -06:00
|
|
|
style={{marginTop: '1em'}}
|
2023-07-21 15:14:09 -06:00
|
|
|
>Delete</APIButton>
|
|
|
|
|
<APIButton
|
|
|
|
|
color='blue'
|
|
|
|
|
size='small'
|
|
|
|
|
onClick={handleRefreshChannel}
|
|
|
|
|
obeyWROLMode={true}
|
2024-06-25 22:12:13 -06:00
|
|
|
style={{marginTop: '1em'}}
|
2023-07-21 15:14:09 -06:00
|
|
|
>Refresh</APIButton>
|
2024-10-04 16:32:48 -06:00
|
|
|
<Button
|
|
|
|
|
size='small'
|
2024-10-05 14:06:13 -06:00
|
|
|
onClick={() => setTagEditModalOpen(true)}
|
2024-10-04 16:32:48 -06:00
|
|
|
color='green'
|
|
|
|
|
>Tag</Button>
|
|
|
|
|
{tagEditModal}
|
|
|
|
|
</>
|
2024-11-02 15:14:02 -06:00
|
|
|
: <DownloadTagsSelector
|
|
|
|
|
form={form}
|
|
|
|
|
limit={1}
|
|
|
|
|
path='tag_name'
|
|
|
|
|
name='tag_name'
|
|
|
|
|
/>
|
2022-12-02 11:23:05 -07:00
|
|
|
}
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column>
|
2023-07-21 15:14:09 -06:00
|
|
|
<APIButton
|
2023-04-05 10:18:52 -06:00
|
|
|
color='violet'
|
2022-12-02 11:23:05 -07:00
|
|
|
size='big'
|
|
|
|
|
floated='right'
|
2023-07-21 15:14:09 -06:00
|
|
|
onClick={handleSubmit}
|
2024-11-02 15:14:02 -06:00
|
|
|
disabled={form.disabled}
|
2023-07-21 15:14:09 -06:00
|
|
|
obeyWROLMode={true}
|
|
|
|
|
>Save</APIButton>
|
2022-12-02 11:23:05 -07:00
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
</Form>
|
|
|
|
|
</Segment>
|
2022-11-30 19:31:18 -07:00
|
|
|
|
2024-06-25 22:12:13 -06:00
|
|
|
{!create && <Segment>
|
|
|
|
|
<Grid columns={2}>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Header as='h1'>Downloads</Header>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Button floated='right'
|
|
|
|
|
onClick={() => setDownloadModalOpen(!downloadModalOpen)}
|
|
|
|
|
>
|
|
|
|
|
New Download
|
|
|
|
|
</Button>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Modal open={downloadModalOpen} closeIcon onClose={() => setDownloadModalOpen(false)}>
|
|
|
|
|
<ModalContent>
|
|
|
|
|
<Header as='h2'>New Channel Download</Header>
|
|
|
|
|
<ChannelDownloadForm
|
|
|
|
|
channel_id={channelId}
|
2024-11-02 15:14:02 -06:00
|
|
|
onSuccess={afterNewDownloadSave}
|
|
|
|
|
onCancel={() => setDownloadModalOpen(false)}
|
|
|
|
|
onDelete={onDelete}
|
2024-06-25 22:12:13 -06:00
|
|
|
/>
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</Modal>
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
<RecurringDownloadsTable downloads={downloads} fetchDownloads={fetchChannel} onDelete={onDelete}/>
|
2024-06-25 22:12:13 -06:00
|
|
|
</Segment>}
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
{channel && channel.statistics && <ChannelStatistics statistics={channel.statistics}/>}
|
2022-12-02 11:25:46 -07:00
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2023-11-04 15:57:13 -06:00
|
|
|
export function ChannelEditPage(props) {
|
2022-08-06 05:22:07 +00:00
|
|
|
return <ChannelPage header="Edit Channel" {...props}/>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2023-11-04 15:57:13 -06:00
|
|
|
export function ChannelNewPage(props) {
|
2022-10-25 15:57:44 -06:00
|
|
|
useTitle('New Channel');
|
2022-08-06 05:22:07 +00:00
|
|
|
return <ChannelPage header='New Channel' {...props} create/>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function ChannelRow({channel}) {
|
2024-08-06 18:13:21 -06:00
|
|
|
const {SingleTag} = React.useContext(TagsContext);
|
|
|
|
|
|
2023-05-03 08:28:32 -06:00
|
|
|
const videosTo = `/videos/channel/${channel.id}/video`;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-05-03 08:28:32 -06:00
|
|
|
const {inverted} = React.useContext(ThemeContext);
|
2022-08-06 05:22:07 +00:00
|
|
|
const editTo = `/videos/channel/${channel.id}/edit`;
|
2023-05-03 12:46:57 -06:00
|
|
|
const buttonClass = `ui button secondary ${inverted}`;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
return <TableRow>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<Link to={videosTo}>{channel.name}</Link>
|
|
|
|
|
</TableCell>
|
2024-08-06 18:13:21 -06:00
|
|
|
<TableCell>
|
|
|
|
|
{channel.tag_name ? <SingleTag name={channel.tag_name}/> : null}
|
|
|
|
|
</TableCell>
|
2022-08-06 05:22:07 +00:00
|
|
|
<TableCell>
|
|
|
|
|
{channel.video_count}
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
2024-06-25 22:12:13 -06:00
|
|
|
{channel.url && channel.minimum_frequency ? secondsToFrequency(channel.minimum_frequency) : null}
|
2022-08-06 05:22:07 +00:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
2023-05-10 22:59:16 -06:00
|
|
|
{channel.size ? humanFileSize(channel.size) : null}
|
2022-08-06 05:22:07 +00:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell textAlign='right'>
|
2023-05-03 08:28:32 -06:00
|
|
|
<Link className={buttonClass} to={editTo}>Edit</Link>
|
2022-08-06 05:22:07 +00:00
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>;
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function MobileChannelRow({channel}) {
|
2024-08-06 18:13:21 -06:00
|
|
|
const {SingleTag} = React.useContext(TagsContext);
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const editTo = `/videos/channel/${channel.id}/edit`;
|
|
|
|
|
const videosTo = `/videos/channel/${channel.id}/video`;
|
|
|
|
|
return <TableRow verticalAlign='top'>
|
|
|
|
|
<TableCell width={10} colSpan={2}>
|
|
|
|
|
<Link as='h3' to={videosTo}>
|
|
|
|
|
<h3>
|
|
|
|
|
{channel.name}
|
|
|
|
|
</h3>
|
2024-08-06 18:13:21 -06:00
|
|
|
{channel.tag_name ? <SingleTag name={channel.tag_name}/> : null}
|
2022-08-06 05:22:07 +00:00
|
|
|
</Link>
|
|
|
|
|
<p>
|
|
|
|
|
Videos: {channel.video_count}
|
|
|
|
|
</p>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell width={6} colSpan={2} textAlign='right'>
|
|
|
|
|
<p>
|
|
|
|
|
<Link className="ui button secondary" to={editTo}>Edit</Link>
|
|
|
|
|
</p>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-11-02 10:28:00 -06:00
|
|
|
export function ChannelsPage() {
|
2022-10-25 15:57:44 -06:00
|
|
|
useTitle('Channels');
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
const {channels} = useChannels();
|
2023-11-02 10:45:35 -06:00
|
|
|
const [searchStr, setSearchStr] = useOneQuery('name');
|
2023-11-02 16:04:36 -06:00
|
|
|
// Hides Channels with few videos.
|
|
|
|
|
const [hideSmall, setHideSmall] = React.useState(true);
|
2024-05-18 18:36:20 -06:00
|
|
|
const enoughChannelsToHideSmall = channels && channels.length > 20;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-11-02 10:45:35 -06:00
|
|
|
const header = <div style={{marginBottom: '1em'}}>
|
2022-11-30 19:31:18 -07:00
|
|
|
<Grid stackable columns={2}>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
2023-11-22 12:19:49 -07:00
|
|
|
<SearchInput
|
|
|
|
|
placeholder='Name filter...'
|
|
|
|
|
size='large'
|
|
|
|
|
searchStr={searchStr}
|
|
|
|
|
disabled={!Array.isArray(channels) || channels.length === 0}
|
|
|
|
|
onClear={() => setSearchStr('')}
|
|
|
|
|
onChange={setSearchStr}
|
|
|
|
|
onSubmit={null}
|
2023-11-02 15:24:07 -06:00
|
|
|
/>
|
2022-11-30 19:31:18 -07:00
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column textAlign='right'>
|
|
|
|
|
<Link to='/videos/channel/new'>
|
|
|
|
|
<Button secondary>New Channel</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</div>;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
const headers = [
|
2024-08-15 19:32:01 -06:00
|
|
|
{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},
|
2023-01-31 18:08:07 -07:00
|
|
|
{key: 'manage', text: 'Manage', width: 2},
|
|
|
|
|
];
|
|
|
|
|
const mobileHeaders = [
|
2024-08-15 19:32:01 -06:00
|
|
|
{key: 'name', text: 'Name', sortBy: [i => i['name'].toLowerCase()]},
|
|
|
|
|
{key: 'video_count', text: 'Videos', sortBy: [i => i['video_count'], i => i['name'].toLowerCase()]},
|
2023-01-31 18:08:07 -07:00
|
|
|
{key: 'manage', text: 'Manage'},
|
|
|
|
|
];
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-09-07 20:13:36 -06:00
|
|
|
if (channels && channels.length === 0) {
|
|
|
|
|
return <>
|
|
|
|
|
{header}
|
|
|
|
|
<Message>
|
|
|
|
|
<Message.Header>No channels exist yet!</Message.Header>
|
|
|
|
|
<Message.Content><Link to='/videos/channel/new'>Create one.</Link></Message.Content>
|
|
|
|
|
</Message>
|
|
|
|
|
</>
|
|
|
|
|
} else if (channels === undefined) {
|
2022-08-06 05:22:07 +00:00
|
|
|
return <>
|
|
|
|
|
{header}
|
2023-09-07 20:13:36 -06:00
|
|
|
<ErrorMessage>Could not fetch Channels</ErrorMessage>
|
2022-08-06 05:22:07 +00:00
|
|
|
</>
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
let filteredChannels = channels;
|
2023-11-02 10:28:00 -06:00
|
|
|
if (searchStr && Array.isArray(channels)) {
|
2022-08-06 05:22:07 +00:00
|
|
|
const re = new RegExp(_.escapeRegExp(searchStr), 'i');
|
|
|
|
|
filteredChannels = channels.filter(i => re.test(i['name']));
|
2023-11-02 16:04:36 -06:00
|
|
|
} else if (channels && hideSmall && enoughChannelsToHideSmall) {
|
2024-05-18 18:36:20 -06:00
|
|
|
// 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;
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
{header}
|
2023-01-07 18:31:39 -07:00
|
|
|
<Media at='mobile'>
|
2023-01-31 18:08:07 -07:00
|
|
|
<SortableTable
|
|
|
|
|
tableProps={{striped: true, size: 'small', unstackable: true}}
|
|
|
|
|
data={filteredChannels}
|
|
|
|
|
tableHeaders={mobileHeaders}
|
|
|
|
|
defaultSortColumn='name'
|
|
|
|
|
rowKey='id'
|
|
|
|
|
rowFunc={(i, sortData) => <MobileChannelRow key={i.id} channel={i} sortData={sortData}/>}
|
|
|
|
|
/>
|
2023-01-07 18:31:39 -07:00
|
|
|
</Media>
|
|
|
|
|
<Media greaterThanOrEqual='tablet'>
|
2023-01-31 18:08:07 -07:00
|
|
|
<SortableTable
|
|
|
|
|
tableProps={{striped: true, size: 'large', unstackable: true, compact: true}}
|
|
|
|
|
data={filteredChannels}
|
|
|
|
|
tableHeaders={headers}
|
|
|
|
|
defaultSortColumn='name'
|
|
|
|
|
rowKey='id'
|
|
|
|
|
rowFunc={(i, sortData) => <ChannelRow key={i.id} channel={i} sortData={sortData}/>}
|
|
|
|
|
/>
|
2023-01-07 18:31:39 -07:00
|
|
|
</Media>
|
2023-11-02 16:04:36 -06:00
|
|
|
<Grid textAlign='center'>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Button
|
|
|
|
|
style={{marginTop: '1em'}}
|
|
|
|
|
onClick={() => setHideSmall(!hideSmall)}
|
|
|
|
|
size='big'
|
|
|
|
|
disabled={!enoughChannelsToHideSmall}
|
|
|
|
|
>Show {hideSmall ? 'More' : 'Less'}</Button>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
2022-08-06 05:22:07 +00:00
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|