}
}
{/* Tag Modal */}
setTagEditModalOpen(false)}
currentTagName={channel.tag_name}
originalDirectory={channel.directory}
getTagInfo={handleGetTagInfo}
onSave={handleTagSave}
collectionName="Channel"
hasDirectory={!!channel.directory}
/>
{/* Reorganize Modal */}
setReorganizeModalOpen(false)}
collectionId={channel?.collection_id}
collectionName={channel?.name}
onComplete={fetchChannel}
needsReorganization={channel?.needs_reorganization}
/>
{/* Downloads Segment */}
Downloads setDownloadModalOpen(false)}>
New Channel Download setDownloadModalOpen(false)}
onDelete={onDelete}
/>
{channel && channel.statistics && }
>;
}
export function ChannelNewPage() {
useTitle('New Channel');
// Used to display messages to maintainer.
const [error, setError] = useState(false);
const [success, setSuccess] = useState(false);
const [messageHeader, setMessageHeader] = useState();
const [messageContent, setMessageContent] = useState();
const {channel, form} = useChannel(null);
const setErrorMessage = (header, message) => {
setError(true);
setSuccess(false);
setMessageHeader(header);
setMessageContent(message);
}
const setSuccessMessage = (header, message) => {
setError(false);
setSuccess(true);
setMessageHeader(header);
setMessageContent(message);
}
const handleSubmit = async () => {
const body = {
name: channel.name,
directory: channel.directory,
url: channel.url,
download_missing_data: channel.download_missing_data,
tag_name: _.isEmpty(channel.tag_name) ? null : channel.tag_name[0],
};
let response = null;
try {
response = await createChannel(body);
} catch (e) {
console.error(e);
toast({
type: 'error',
title: 'Unexpected server response',
description: 'Could not save channel',
time: 5000,
});
return;
}
if (response && response.ok) {
let location = response.headers.get('Location');
let channelResponse = await fetch(location);
let data = await channelResponse.json();
let newChannel = data['channel'];
setSuccessMessage(
'Channel created',
Your channel was created. View it here
);
} else if (response) {
let error = await response.json();
let cause = error.cause;
if (cause && cause.code === 'CHANNEL_DIRECTORY_CONFLICT') {
setErrorMessage(
'Invalid directory',
'This directory is already used by another channel',
);
} else if (cause && cause.code === 'CHANNEL_NAME_CONFLICT') {
setErrorMessage(
'Invalid name',
'This channel name is already taken',
);
} else {
setErrorMessage('Invalid channel', error.message || error.error || 'Unable to save channel. See logs.');
}
} else {
console.error('Did not get a response for channel!');
}
}
const downloadMissingDataInfo = 'Automatically download missing comments, etc, in the background.';
const downloadMissingDataLabel = <>Download Missing Data>;
let messageRow;
if (error || success) {
messageRow =
{error &&
{messageContent}}
{success &&
{messageContent}}
}
return <>
New Channel
>;
}
export function ChannelsPage() {
useTitle('Channels');
const [channels] = useChannels();
const [searchStr, setSearchStr] = useOneQuery('name');
const searchInputRef = React.useRef();
useHotkeys('f', (e) => {
e.preventDefault();
if (searchInputRef.current) {
searchInputRef.current.focus();
}
}, {enableOnFormTags: false});
// Header section matching DomainsPage pattern. No `mb`: this is a top-level block of the
// page, and the page's stack spaces it -- its own margin was added to that gap.
const header = setSearchStr('')}
onChange={setSearchStr}
onSubmit={null}
inputRef={searchInputRef}
/>
;
// Empty state
if (channels && channels.length === 0) {
return <>
{header}
Create one.
>;
}
// Error state
if (channels === undefined) {
return <>
{header}
Could not fetch Channels
>;
}
return <>
{header}
>;
}