2022-08-06 05:22:07 +00:00
|
|
|
import React, {useState} from "react";
|
2026-02-23 17:29:09 -07:00
|
|
|
import {useHotkeys} from "react-hotkeys-hook";
|
2025-12-05 18:26:36 -07:00
|
|
|
import {createChannel, deleteChannel, refreshChannel, tagChannel, tagChannelInfo} from "../api";
|
2025-10-29 22:16:33 -06:00
|
|
|
import {CollectionTagModal} from "./collections/CollectionTagModal";
|
2026-01-23 19:51:02 -07:00
|
|
|
import {CollectionReorganizeModal} from "./collections/CollectionReorganizeModal";
|
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,
|
|
|
|
|
secondsToFullDuration,
|
2024-11-02 15:14:02 -06:00
|
|
|
SimpleAccordion,
|
2022-10-25 15:57:44 -06:00
|
|
|
useTitle,
|
2022-01-12 09:38:21 -07:00
|
|
|
WROLModeMessage
|
|
|
|
|
} from "./Common";
|
2025-12-07 11:54:20 -07:00
|
|
|
import {Link, useNavigate, useParams} from "react-router";
|
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";
|
2026-07-30 13:02:57 -06:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Grid,
|
|
|
|
|
Group,
|
|
|
|
|
Header,
|
|
|
|
|
Loading,
|
|
|
|
|
Message,
|
|
|
|
|
Modal,
|
|
|
|
|
Panel,
|
|
|
|
|
Stack,
|
|
|
|
|
Statistic,
|
|
|
|
|
StatisticGroup,
|
|
|
|
|
toast,
|
|
|
|
|
} from "./ui";
|
2024-06-25 22:12:13 -06:00
|
|
|
import {RecurringDownloadsTable} from "./admin/Downloads";
|
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";
|
2025-10-29 22:16:33 -06:00
|
|
|
import {CollectionTable} from "./collections/CollectionTable";
|
2025-12-05 18:26:36 -07:00
|
|
|
import {CollectionEditForm} from "./collections/CollectionEditForm";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
// Channel table column configuration
|
|
|
|
|
const CHANNEL_COLUMNS = [
|
|
|
|
|
{key: 'name', label: 'Name', sortable: true, width: 7},
|
|
|
|
|
{key: 'tag_name', label: 'Tag', sortable: true, width: 2},
|
|
|
|
|
{key: 'video_count', label: 'Videos', sortable: true, align: 'right', width: 2},
|
2025-12-06 14:49:46 -07:00
|
|
|
{
|
|
|
|
|
key: 'min_download_frequency',
|
|
|
|
|
label: 'Download Frequency',
|
|
|
|
|
sortable: true,
|
|
|
|
|
format: 'frequency',
|
|
|
|
|
width: 2,
|
|
|
|
|
hideOnMobile: true
|
|
|
|
|
},
|
2025-12-05 17:12:21 -07:00
|
|
|
{key: 'total_size', label: 'Size', sortable: true, align: 'right', format: 'bytes', width: 2, hideOnMobile: true},
|
|
|
|
|
{key: 'actions', label: 'Manage', sortable: false, type: 'actions', width: 1}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const CHANNEL_ROUTES = {
|
|
|
|
|
list: '/videos/channel',
|
|
|
|
|
edit: '/videos/channel/:id/edit',
|
|
|
|
|
search: '/videos/channel/:id/video',
|
|
|
|
|
id_field: 'channel_id'
|
|
|
|
|
};
|
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 <></>
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-30 13:02:57 -06:00
|
|
|
return <Panel>
|
2023-02-17 16:09:24 -07:00
|
|
|
<Header as='h1'>Statistics</Header>
|
2026-07-30 13:02:57 -06:00
|
|
|
<StatisticGroup>
|
|
|
|
|
<Statistic value={statistics.video_count} label='Videos'/>
|
|
|
|
|
<Statistic value={humanFileSize(statistics.size, true)} label='Total Size'/>
|
|
|
|
|
<Statistic value={humanFileSize(statistics.largest_video, true)} label='Largest Video'/>
|
|
|
|
|
<Statistic value={secondsToFullDuration(statistics.length)} label='Total Duration'/>
|
|
|
|
|
<Statistic value={humanNumber(statistics.video_tags)} label='Video Tags'/>
|
|
|
|
|
</StatisticGroup>
|
|
|
|
|
</Panel>
|
2021-12-24 15:31:15 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2025-12-05 18:26:36 -07:00
|
|
|
export function ChannelEditPage() {
|
2022-08-06 05:22:07 +00:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const {channelId} = useParams();
|
|
|
|
|
|
2024-10-04 16:32:48 -06:00
|
|
|
const [tagEditModalOpen, setTagEditModalOpen] = useState(false);
|
2025-12-05 18:26:36 -07:00
|
|
|
const [downloadModalOpen, setDownloadModalOpen] = useState(false);
|
2026-01-23 19:51:02 -07:00
|
|
|
const [reorganizeModalOpen, setReorganizeModalOpen] = useState(false);
|
2024-08-06 18:13:21 -06:00
|
|
|
|
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`);
|
|
|
|
|
|
2025-12-05 18:26:36 -07:00
|
|
|
if (!form.ready) {
|
2026-07-30 13:02:57 -06:00
|
|
|
return <Loading/>;
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2025-12-05 18:26:36 -07:00
|
|
|
const handleRefreshChannel = async (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
await refreshChannel(channelId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDelete = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let response = await deleteChannel(channelId);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
navigate('/videos/channel');
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to delete channel', e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handler for tag modal save
|
|
|
|
|
const handleTagSave = async (tagName, directory) => {
|
|
|
|
|
try {
|
|
|
|
|
await tagChannel(channelId, tagName, directory);
|
|
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Channel Tagged',
|
|
|
|
|
description: `Channel has been tagged with "${tagName}"`,
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to tag channel', e);
|
|
|
|
|
} finally {
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
await fetchChannel();
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Handler for fetching tag info
|
|
|
|
|
const handleGetTagInfo = async (tagName) => {
|
|
|
|
|
return await tagChannelInfo(channelId, tagName);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const afterNewDownloadSave = async () => {
|
|
|
|
|
setDownloadModalOpen(false);
|
|
|
|
|
await form.fetcher();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onDelete = async () => {
|
|
|
|
|
await form.fetcher();
|
|
|
|
|
setDownloadModalOpen(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async (e) => {
|
|
|
|
|
if (e) e.preventDefault();
|
|
|
|
|
try {
|
|
|
|
|
await form.onSubmit();
|
|
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Channel Updated',
|
|
|
|
|
description: 'Channel was successfully updated',
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
await fetchChannel();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to update channel:', e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteButton = <APIButton
|
2026-07-30 13:02:57 -06:00
|
|
|
role='danger'
|
2025-12-05 18:26:36 -07:00
|
|
|
size='small'
|
|
|
|
|
confirmContent='Are you sure you want to delete this channel? No video files will be deleted.'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
confirmHeader='Delete Channel?'
|
|
|
|
|
onClick={handleDelete}
|
|
|
|
|
obeyWROLMode={true}
|
|
|
|
|
>Delete</APIButton>;
|
|
|
|
|
|
|
|
|
|
const refreshButton = <APIButton
|
2026-07-30 13:02:57 -06:00
|
|
|
role='primary'
|
2025-12-05 18:26:36 -07:00
|
|
|
size='small'
|
|
|
|
|
onClick={handleRefreshChannel}
|
|
|
|
|
obeyWROLMode={true}
|
|
|
|
|
>Refresh</APIButton>;
|
|
|
|
|
|
|
|
|
|
const tagButton = <Button
|
|
|
|
|
type="button"
|
|
|
|
|
size='small'
|
|
|
|
|
onClick={() => setTagEditModalOpen(true)}
|
2026-07-30 13:02:57 -06:00
|
|
|
role='primary'
|
2025-12-05 18:26:36 -07:00
|
|
|
>Tag</Button>;
|
|
|
|
|
|
2026-01-23 19:51:02 -07:00
|
|
|
const reorganizeButton = (
|
|
|
|
|
<APIButton
|
2026-07-30 13:02:57 -06:00
|
|
|
role='retry'
|
2026-01-23 19:51:02 -07:00
|
|
|
size='small'
|
|
|
|
|
onClick={() => setReorganizeModalOpen(true)}
|
|
|
|
|
obeyWROLMode={true}
|
|
|
|
|
>Reorganize Files</APIButton>
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-05 18:26:36 -07:00
|
|
|
const actionButtons = <>
|
|
|
|
|
{deleteButton}
|
|
|
|
|
{refreshButton}
|
|
|
|
|
{tagButton}
|
2026-01-23 19:51:02 -07:00
|
|
|
{reorganizeButton}
|
2025-12-05 18:26:36 -07:00
|
|
|
</>;
|
|
|
|
|
|
|
|
|
|
const downloadMissingDataInfo = 'Automatically download missing comments, etc, in the background.';
|
|
|
|
|
const downloadMissingDataLabel = <>Download Missing Data<InfoPopup content={downloadMissingDataInfo}/></>;
|
|
|
|
|
|
|
|
|
|
return <>
|
ui: a Back button is a row of one, not a stretched flex child
Reported: the Back button fills the page width on the domain and channel edit
pages. It fills it on all nine pages that have one, and this is mine from the
last PR.
`.wrolpi-stack` is a flex column at `align-items: stretch`, deliberately -- a
panel was full-width as a block element and has to stay that way. A BARE button
as a direct child of that stack is stretched too, and every page's Back button
was one. On the domain, channel and playlist edit pages it also pushed the
button beside it onto its own line, where the two had been inline.
Wrapping each in a `.wrolpi-button-row` fixes both without touching the stack:
the row is the stretched child, and it lays its buttons out at their own width.
The three pages that have a second button get one row holding both, which is how
they read before.
Also the Videos, Archives and Documents select bars, whose Tag/Delete/Invert/
Clear were four touching buttons in a bare div. They are inline elements rather
than interpolations, which is the shape the bare-siblings scan does not see.
Guarded twice: the row keeps its buttons their own width inside a stack while
itself stretching (both halves, since a row that refused to stretch would pass a
test that only looked at the button), and every `<BackButton/>` in the app is
inside a row.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 16:47:33 -06:00
|
|
|
<div className='wrolpi-button-row'>
|
|
|
|
|
<BackButton/>
|
|
|
|
|
<Link to={`/videos/channel/${channel.id}/video`}>
|
|
|
|
|
<Button>Videos</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
2025-12-05 18:26:36 -07:00
|
|
|
|
2026-01-23 19:51:02 -07:00
|
|
|
{channel?.needs_reorganization && (
|
2026-07-30 13:02:57 -06:00
|
|
|
<Message kind='warning' title='File Format Changed'>
|
2026-01-23 19:51:02 -07:00
|
|
|
<p>
|
|
|
|
|
The file name format has changed. Click "Reorganize Files" to move existing files
|
|
|
|
|
to match the new format.
|
|
|
|
|
</p>
|
|
|
|
|
</Message>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-12-05 18:26:36 -07:00
|
|
|
<CollectionEditForm
|
|
|
|
|
form={form}
|
|
|
|
|
title="Edit Channel"
|
|
|
|
|
wrolModeContent='Channel editing is disabled while in WROL Mode.'
|
|
|
|
|
actionButtons={actionButtons}
|
|
|
|
|
appliedTagName={channel?.tag_name}
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
>
|
2026-07-30 13:02:57 -06:00
|
|
|
<Grid>
|
|
|
|
|
<Grid.Col span={{base: 12, sm: 6}}>
|
2025-12-05 18:26:36 -07:00
|
|
|
<InputForm
|
|
|
|
|
form={form}
|
|
|
|
|
label="Channel Name"
|
|
|
|
|
name="name"
|
|
|
|
|
placeholder="Short Channel Name"
|
|
|
|
|
required={true}
|
|
|
|
|
/>
|
2026-07-30 13:02:57 -06:00
|
|
|
</Grid.Col>
|
|
|
|
|
<Grid.Col span={{base: 12, sm: 6}}>
|
2025-12-05 18:26:36 -07:00
|
|
|
<DestinationForm
|
|
|
|
|
form={form}
|
|
|
|
|
label='Directory'
|
|
|
|
|
name='directory'
|
|
|
|
|
path='directory'
|
|
|
|
|
required={true}
|
|
|
|
|
/>
|
2026-07-30 13:02:57 -06:00
|
|
|
</Grid.Col>
|
|
|
|
|
<Grid.Col span={12}>
|
2025-12-05 18:26:36 -07:00
|
|
|
<ToggleForm
|
|
|
|
|
form={form}
|
|
|
|
|
label={downloadMissingDataLabel}
|
|
|
|
|
path='download_missing_data'
|
|
|
|
|
/>
|
2026-07-30 13:02:57 -06:00
|
|
|
</Grid.Col>
|
|
|
|
|
{(channel.url || channel.rss_url) &&
|
|
|
|
|
<Grid.Col span={12}>
|
2025-12-05 18:26:36 -07:00
|
|
|
<SimpleAccordion title='Details'>
|
2026-07-30 13:02:57 -06:00
|
|
|
<Stack gap='sm'>
|
|
|
|
|
{channel.url && <div>
|
|
|
|
|
<Header as='h4'>URL</Header>
|
|
|
|
|
<a href={channel.url}>{channel.url}</a>
|
|
|
|
|
</div>}
|
|
|
|
|
{channel.rss_url && <div>
|
|
|
|
|
<Header as='h4'>RSS URL</Header>
|
|
|
|
|
<a href={channel.rss_url}>{channel.rss_url}</a>
|
|
|
|
|
</div>}
|
|
|
|
|
</Stack>
|
2025-12-05 18:26:36 -07:00
|
|
|
</SimpleAccordion>
|
2026-07-30 13:02:57 -06:00
|
|
|
</Grid.Col>}
|
|
|
|
|
</Grid>
|
2025-12-05 18:26:36 -07:00
|
|
|
</CollectionEditForm>
|
|
|
|
|
|
|
|
|
|
{/* Tag Modal */}
|
|
|
|
|
<CollectionTagModal
|
|
|
|
|
open={tagEditModalOpen}
|
|
|
|
|
onClose={() => setTagEditModalOpen(false)}
|
|
|
|
|
currentTagName={channel.tag_name}
|
|
|
|
|
originalDirectory={channel.directory}
|
|
|
|
|
getTagInfo={handleGetTagInfo}
|
|
|
|
|
onSave={handleTagSave}
|
|
|
|
|
collectionName="Channel"
|
2025-12-06 09:27:40 -07:00
|
|
|
hasDirectory={!!channel.directory}
|
2025-12-05 18:26:36 -07:00
|
|
|
/>
|
|
|
|
|
|
2026-01-23 19:51:02 -07:00
|
|
|
{/* Reorganize Modal */}
|
|
|
|
|
<CollectionReorganizeModal
|
|
|
|
|
open={reorganizeModalOpen}
|
|
|
|
|
onClose={() => setReorganizeModalOpen(false)}
|
|
|
|
|
collectionId={channel?.collection_id}
|
|
|
|
|
collectionName={channel?.name}
|
|
|
|
|
onComplete={fetchChannel}
|
|
|
|
|
needsReorganization={channel?.needs_reorganization}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-12-05 18:26:36 -07:00
|
|
|
{/* Downloads Segment */}
|
2026-07-30 13:02:57 -06:00
|
|
|
<Panel>
|
|
|
|
|
<Group justify='space-between' align='center' wrap='wrap'>
|
|
|
|
|
<Header as='h1'>Downloads</Header>
|
|
|
|
|
<Button onClick={() => setDownloadModalOpen(!downloadModalOpen)}>
|
|
|
|
|
New Download
|
|
|
|
|
</Button>
|
|
|
|
|
</Group>
|
ui: only the top modal answers Escape, and the audited widths
Two things, both reported from the running app.
Nested modals could not exist. Mantine binds a window-level keydown listener
per open modal, gated only on whether that modal is open -- nothing checks which
one the user is looking at:
useWindowEvent('keydown', (event) => {
if (event.key === 'Escape' && closeOnEscape && ... && opened) onClose();
}, {capture: true});
Two open modals meant two listeners, so one Escape closed both. Reproduced on
the dashboard: the download modal plus the search modal over it, one press, both
gone, back to the page. Both also sat at z-index 200, so which one drew on top
was DOM order rather than which the user opened.
Mantine's own answer is Modal.Stack with a stackId, which is the only thing that
gates closeOnEscape. Not used, for two reasons: every call site would have to
be rewritten to hoist its modal into a stack, and it sets `__hidden` on
everything below the top -- the parent disappears while the child is open. The
parent should be dimmed and still there, as it was before the migration.
So the wrapper keeps the register itself: a module-level list of open modals,
most recent on top, from which each modal takes closeOnEscape, trapFocus and a
z-index two above its parent. Module-level rather than React context because
the two modals in the bug are not nested in the JSX at all -- the search modal
is rendered by KeyboardShortcutsProvider near the app root and the download
modal by the dashboard. They are siblings that happen to be open together, and
no context relates them. The increment is small on purpose: Mantine puts
popovers at 300, and a stack that climbed past it would paint over the select
dropdowns inside its own forms.
Widths: Roland audited the modal list and chose sizes against Mantine's scale.
Sixteen get wider -- twelve to `large` (620), four to `fullscreen` -- and eleven
keep the width they had, with the size now written down so the decision is in
the source rather than in a default. Flasher was passing Mantine's raw `sm`,
which worked but bypassed the naming the audit used; it says `tiny` now.
The size table itself is guarded, because it is the single thing that halved
every modal during the migration and a quiet edit to it moves seventy at once.
Semantic's widths, measured on the pre-migration build still running on the QA
Pi: mini 360, tiny 540, small 720, large 1080, no-size 900. Mantine's, read out
of its stylesheet: 320/380/440/620/780. A `small` modal went 720 -> 440 and one
with no size went 900 -> 440. Three cases now hold the scale, the mapping, and
the rule that no call site may name a size the table does not know -- an unknown
name is passed to Mantine, ignored, and silently rendered at the default.
Tested in a real browser: none of it is visible to jsdom -- the listener is on
window with capture, the stacking is z-index, and "still visible behind" is
geometry. Note that `should('be.visible')` is the wrong assertion for the
parent: it is an occlusion check, so a child drawn correctly over its parent
trips it. The test uses a wide viewport and asserts the parent is rendered and
shows to both sides of the child. Planting the pre-fix behaviour reddens three.
1124 jest / 62 suites, 8 in modal-stack.cy.js, clean npm run build. The 12
failures in Tags/Channels/Download/Inventory.cy.js are the known pre-existing
Semantic-era selector failures, unchanged.
2026-08-02 15:26:15 -06:00
|
|
|
<Modal size='small' open={downloadModalOpen} onClose={() => setDownloadModalOpen(false)}>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Content>
|
2025-12-05 18:26:36 -07:00
|
|
|
<Header as='h2'>New Channel Download</Header>
|
|
|
|
|
<ChannelDownloadForm
|
|
|
|
|
channel_id={channelId}
|
|
|
|
|
onSuccess={afterNewDownloadSave}
|
|
|
|
|
onCancel={() => setDownloadModalOpen(false)}
|
|
|
|
|
onDelete={onDelete}
|
|
|
|
|
/>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
2025-12-05 18:26:36 -07:00
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
|
<RecurringDownloadsTable downloads={channel?.downloads} fetchDownloads={fetchChannel} onDelete={onDelete}/>
|
2026-07-30 13:02:57 -06:00
|
|
|
</Panel>
|
2025-12-05 18:26:36 -07:00
|
|
|
|
|
|
|
|
{channel && channel.statistics && <ChannelStatistics statistics={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);
|
|
|
|
|
|
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,
|
2025-12-05 18:26:36 -07:00
|
|
|
tag_name: _.isEmpty(channel.tag_name) ? null : channel.tag_name[0],
|
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 {
|
2025-12-05 18:26:36 -07:00
|
|
|
response = await createChannel(body);
|
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();
|
2025-12-05 18:26:36 -07:00
|
|
|
let newChannel = data['channel'];
|
|
|
|
|
|
|
|
|
|
setSuccessMessage(
|
|
|
|
|
'Channel created',
|
|
|
|
|
<span>
|
|
|
|
|
Your channel was created. View it <Link to={`/videos/channel/${newChannel.id}/edit`}>here</Link>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
2022-08-06 05:22:07 +00:00
|
|
|
} else if (response) {
|
2021-11-01 16:42:52 -06:00
|
|
|
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',
|
|
|
|
|
);
|
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',
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2025-12-05 18:26:36 -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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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}/></>;
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
let messageRow;
|
|
|
|
|
if (error || success) {
|
2026-07-30 13:02:57 -06:00
|
|
|
messageRow = <Grid.Col span={12}>
|
|
|
|
|
{error &&
|
|
|
|
|
<Message kind='error' title={messageHeader}>{messageContent}</Message>}
|
|
|
|
|
{success &&
|
|
|
|
|
<Message kind='success' title={messageHeader}>{messageContent}</Message>}
|
|
|
|
|
</Grid.Col>
|
2024-11-02 15:14:02 -06:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 11:25:46 -07:00
|
|
|
return <>
|
ui: a Back button is a row of one, not a stretched flex child
Reported: the Back button fills the page width on the domain and channel edit
pages. It fills it on all nine pages that have one, and this is mine from the
last PR.
`.wrolpi-stack` is a flex column at `align-items: stretch`, deliberately -- a
panel was full-width as a block element and has to stay that way. A BARE button
as a direct child of that stack is stretched too, and every page's Back button
was one. On the domain, channel and playlist edit pages it also pushed the
button beside it onto its own line, where the two had been inline.
Wrapping each in a `.wrolpi-button-row` fixes both without touching the stack:
the row is the stretched child, and it lays its buttons out at their own width.
The three pages that have a second button get one row holding both, which is how
they read before.
Also the Videos, Archives and Documents select bars, whose Tag/Delete/Invert/
Clear were four touching buttons in a bare div. They are inline elements rather
than interpolations, which is the shape the bare-siblings scan does not see.
Guarded twice: the row keeps its buttons their own width inside a stack while
itself stretching (both halves, since a row that refused to stretch would pass a
test that only looked at the button), and every `<BackButton/>` in the app is
inside a row.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 16:47:33 -06:00
|
|
|
<div className='wrolpi-button-row'><BackButton/></div>
|
2022-11-30 19:31:18 -07:00
|
|
|
|
2026-07-30 13:02:57 -06:00
|
|
|
<Panel>
|
2025-12-05 18:26:36 -07:00
|
|
|
<Header as="h1">New Channel</Header>
|
|
|
|
|
<WROLModeMessage content='Channel creation is disabled while WROL Mode is enabled.'/>
|
2026-07-30 13:02:57 -06:00
|
|
|
<form
|
2025-12-05 18:26:36 -07:00
|
|
|
id="newChannel"
|
2022-12-02 11:23:05 -07:00
|
|
|
autoComplete="off"
|
2026-07-30 13:02:57 -06:00
|
|
|
onSubmit={e => e.preventDefault()}
|
2022-12-02 11:23:05 -07:00
|
|
|
>
|
2026-07-30 13:02:57 -06:00
|
|
|
<Grid>
|
|
|
|
|
<Grid.Col span={{base: 12, sm: 6}}>
|
|
|
|
|
<InputForm
|
|
|
|
|
form={form}
|
|
|
|
|
label="Channel Name"
|
|
|
|
|
name="name"
|
|
|
|
|
placeholder="Short Channel Name"
|
|
|
|
|
required={true}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Col>
|
|
|
|
|
<Grid.Col span={{base: 12, sm: 6}}>
|
|
|
|
|
<DestinationForm
|
|
|
|
|
form={form}
|
|
|
|
|
label='Directory'
|
|
|
|
|
name='directory'
|
|
|
|
|
path='directory'
|
|
|
|
|
required={true}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Col>
|
|
|
|
|
<Grid.Col span={12}>
|
|
|
|
|
<ToggleForm
|
|
|
|
|
form={form}
|
|
|
|
|
label={downloadMissingDataLabel}
|
|
|
|
|
path='download_missing_data'
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Col>
|
2024-11-02 15:14:02 -06:00
|
|
|
{messageRow}
|
2026-07-30 13:02:57 -06:00
|
|
|
<Grid.Col span={{base: 12, sm: 8}}>
|
|
|
|
|
<DownloadTagsSelector
|
|
|
|
|
form={form}
|
|
|
|
|
limit={1}
|
|
|
|
|
path='tag_name'
|
|
|
|
|
name='tag_name'
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Col>
|
|
|
|
|
<Grid.Col span={{base: 12, sm: 4}}>
|
|
|
|
|
<div style={{textAlign: 'right'}}>
|
2023-07-21 15:14:09 -06:00
|
|
|
<APIButton
|
2026-07-30 13:02:57 -06:00
|
|
|
role='primary'
|
2022-12-02 11:23:05 -07:00
|
|
|
size='big'
|
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>
|
2026-07-30 13:02:57 -06:00
|
|
|
</div>
|
|
|
|
|
</Grid.Col>
|
2022-12-02 11:23:05 -07:00
|
|
|
</Grid>
|
2026-07-30 13:02:57 -06:00
|
|
|
</form>
|
|
|
|
|
</Panel>
|
2025-12-05 18:26:36 -07:00
|
|
|
</>;
|
2021-11-01 16:42:52 -06: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
|
|
|
|
2025-12-05 17:12:21 -07:00
|
|
|
const [channels] = useChannels();
|
2023-11-02 10:45:35 -06:00
|
|
|
const [searchStr, setSearchStr] = useOneQuery('name');
|
2026-02-23 17:29:09 -07:00
|
|
|
const searchInputRef = React.useRef();
|
|
|
|
|
|
|
|
|
|
useHotkeys('f', (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (searchInputRef.current) {
|
|
|
|
|
searchInputRef.current.focus();
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false});
|
2022-08-06 05:22:07 +00:00
|
|
|
|
ui: stop /archives/settings wrapping itself in a second PageContainer
`ArchiveRoute` wraps its `<Routes>` in a PageContainer, and
`ArchiveSettingsPage` wrapped itself in another. PageContainer carries
`margin-top: 1em` and `padding: 1em`, so that page sat 1em lower and 1em
further in on all four sides than /archives/domains beside it -- which is
exactly what "seems to have more margin" was. It is a fragment now, so its
panels are blocks of the route's own stack.
Guarded by a source scan rather than a render, since a doubled margin throws
nothing: it takes each PageContainer that wraps a router, reads the
components it routes to, and fails if one of them renders a PageContainer of
its own.
The first version of that scan passed against the live bug. It looked at
only the first `<PageContainer>` in a file, and in Archive.js that is the
offender itself, whose block holds no `<Routes>` -- so the file was skipped
before the route wrapper 400 lines below was reached. It reads every
occurrence now, and the premise assertions count both the wrappers found and
the routes within them.
Two more top-level blocks gave up margins that were being added to the
page's gap, both headers "matching" each other's pattern: the domain filter
row (35.2px against 17.6px) and the channel filter row.
/archives/settings and /archives/domains now measure identically -- tab bar
bottom at 136.8px, first block 17.6px below it, content inset 17.6px -- as
do the statistics and settings pages of every other tab group.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 15:53:04 -06:00
|
|
|
// 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 = <Group justify='space-between' align='flex-end' wrap='wrap'>
|
2026-07-30 13:02:57 -06:00
|
|
|
<SearchInput
|
|
|
|
|
placeholder='Name filter...'
|
|
|
|
|
size='large'
|
|
|
|
|
searchStr={searchStr}
|
|
|
|
|
disabled={!Array.isArray(channels) || channels.length === 0}
|
|
|
|
|
onClear={() => setSearchStr('')}
|
|
|
|
|
onChange={setSearchStr}
|
|
|
|
|
onSubmit={null}
|
|
|
|
|
inputRef={searchInputRef}
|
|
|
|
|
/>
|
|
|
|
|
<Link to='/videos/channel/new'>
|
|
|
|
|
<Button role='primary'>New Channel</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</Group>;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2025-10-29 22:16:33 -06:00
|
|
|
// Empty state
|
2023-09-07 20:13:36 -06:00
|
|
|
if (channels && channels.length === 0) {
|
|
|
|
|
return <>
|
|
|
|
|
{header}
|
2026-07-30 13:02:57 -06:00
|
|
|
<Message title='No channels exist yet!'>
|
|
|
|
|
<Link to='/videos/channel/new'>Create one.</Link>
|
2023-09-07 20:13:36 -06:00
|
|
|
</Message>
|
2025-10-29 22:16:33 -06:00
|
|
|
</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Error state
|
|
|
|
|
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>
|
2025-10-29 22:16:33 -06:00
|
|
|
</>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
{header}
|
2025-10-29 22:16:33 -06:00
|
|
|
<CollectionTable
|
|
|
|
|
collections={channels}
|
2025-12-05 17:12:21 -07:00
|
|
|
columns={CHANNEL_COLUMNS}
|
|
|
|
|
routes={CHANNEL_ROUTES}
|
2025-10-29 22:16:33 -06:00
|
|
|
searchStr={searchStr}
|
|
|
|
|
/>
|
|
|
|
|
</>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|