;
const onCollapseAll = () => {
if (!openFolders) return;
// Deselect any paths that will no longer be visible (descendants of the open folders).
const newSelectedPaths = selectedPaths.filter(p =>
!openFolders.some(folder => p.startsWith(folder) && p !== folder));
if (newSelectedPaths.length !== selectedPaths.length) {
setSelectedPaths(newSelectedPaths);
}
setOpenFolders(null);
}
const onFolderClick = async (folder) => {
let newFolders;
if (openFolders.indexOf(folder) >= 0) {
// Remove the folder that was clicked on, as well as its sub-folders.
newFolders = openFolders.filter(i => !i.startsWith(folder));
// Unselect any children of the closed folder (they're no longer visible)
const newSelectedPaths = selectedPaths.filter(p => !p.startsWith(folder) || p === folder);
if (newSelectedPaths.length !== selectedPaths.length) {
setSelectedPaths(newSelectedPaths);
}
} else {
// Add the new folder to the opened folders.
newFolders = [...openFolders, folder];
// Mark folder as loading so skeleton rows show
setLoadingFolders(prev => new Set([...prev, folder]));
// If folder is selected, mark it for auto-selection of its children
if (selectedPaths.includes(folder)) {
pendingAutoSelectRef.current = folder;
}
}
console.debug(`newFolders=${newFolders}`);
setOpenFolders(newFolders);
}
const filteredFiles = React.useMemo(
() => browseFiles ? filterBrowseFiles(browseFiles, filterStr) : browseFiles,
[browseFiles, filterStr],
);
if (browseFiles === null) {
return ;
} else if (browseFiles === undefined) {
return Could not fetch files
}
return
;
const destinationRows = paths.map(i =>
{fileCell(i)}
{destination ? fileCell(destination + '/' + pathName(i)) : fileCell(pathName(i))}
);
/*
* Audited: `large` (620px). This dialog holds a DirectorySearch and a two-column
* Source/Destination table of every path being moved, which is the densest content
* of the five FileBrowser modals.
*/
return Move Files/Directories
Search for a directory to move your files into:
SourceDestination
{destinationRows}
}
export function IgnoreDirectoryModal({open, onClose, onSubmit, directory, ignored}) {
const mediaDirectory = useMediaDirectory();
const [pending, setPending] = React.useState(false);
const handleIgnore = async () => {
try {
setPending(true);
if (ignored) {
await unignoreDirectory(`${mediaDirectory}/${directory}`);
} else {
await ignoreDirectory(`${mediaDirectory}/${directory}`);
}
if (onSubmit) {
onSubmit();
}
} finally {
setPending(false);
}
}
const header = ignored ? 'Remove Ignore Directory' : 'Ignore Directory';
const content = ignored ?
'Remove ignore of the following directory? You must refresh your files after this.'
: 'Ignore the following directory? The files within will not be indexed and will not show in search results.';
let submitButton = ;
// Audited: `small` (440px), which is the width it already had.
return {header}
{content}
{mediaDirectory}/{directory}
{submitButton}
}
export function MakeDirectoryModal({open, onClose, parent, onSubmit}) {
const [value, setValue] = useState('');
const mediaDirectory = useMediaDirectory();
const handleInputChange = (e) => {
setValue(e.target.value);
}
const handleSubmit = async (e) => {
if (e) {
e.preventDefault();
}
try {
const path = parent ? `${parent}/${value}` : value;
await makeDirectory(path);
setValue('');
if (onSubmit) {
await onSubmit();
}
} catch (e) {
console.error(e);
}
}
/*
* Audited: `large` (620px), deliberately wider than RenameModal's `small` even though
* the form is the same shape -- one field and a button. The difference is the path
* above it: rename shows a RELATIVE path, this shows the absolute one including the
* media directory, and a bare `
` is `white-space: pre`, so it scrolls rather
* than wraps. Measured in the browser: 440px holds 42 characters and 620px holds
* 61. `/media/wrolpi/videos/Practical Engineering/Season 2024/` is 55, so an
* ordinary channel-and-season path scrolls out of sight at 440 and fits at 620.
*
* Written out because it reads like an inconsistency next to rename, and the next
* person to notice that should see the measurement before narrowing it back.
*/
return Make Directory
}
export function FileBrowserUploadModal({open, onClose, destination, onComplete}) {
const mediaDirectory = useMediaDirectory();
const {
setFiles,
progresses,
setDestination,
doClear,
tagsSelector,
overwrite,
setOverwrite,
overallProgress,
inProgress,
} = useUploadFile();
const onDrop = React.useCallback(async (acceptedFiles) => {
if (acceptedFiles && acceptedFiles.length > 0) {
setFiles(acceptedFiles);
}
}, [setFiles]);
const {getRootProps, getInputProps} = useDropzone({onDrop, disabled: inProgress});
// Set destination when modal opens or destination changes
useEffect(() => {
if (open) {
setDestination(destination);
}
}, [open, destination, setDestination]);
// Clear upload state when destination is cleared
useEffect(() => {
if (!destination && open) {
doClear();
}
}, [destination, open, doClear]);
const handleClose = () => {
if (!inProgress) {
doClear();
onClose();
if (onComplete) {
onComplete();
}
}
};
let progressBars;
if (!_.isEmpty(progresses)) {
progressBars = Object.entries(progresses).map(([name, value]) => {
const {percent, status, type} = value;
let color = 'grey';
let statusString;
if (status === 'complete') {
color = 'green';
statusString = 'Complete:';
} else if (status === 'pending') {
statusString = 'Pending:';
} else if (status === 'failed') {
color = 'red';
statusString = 'Failed:';
} else if (status === 'conflicting') {
color = 'orange';
statusString = 'Already Exists:';
}
return