2025-12-25 09:14:00 -07:00
|
|
|
import {Button, Header, Icon, Modal, Placeholder, Progress, Segment, Table} from "./Theme";
|
2023-05-29 18:04:03 -06:00
|
|
|
import {
|
|
|
|
|
Checkbox,
|
2024-05-19 16:04:45 -06:00
|
|
|
Form,
|
2025-12-25 09:14:00 -07:00
|
|
|
Grid,
|
2023-05-29 18:04:03 -06:00
|
|
|
IconGroup,
|
|
|
|
|
Input,
|
|
|
|
|
PlaceholderLine,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableHeaderCell,
|
|
|
|
|
TableRow
|
|
|
|
|
} from "semantic-ui-react";
|
2025-12-25 09:14:00 -07:00
|
|
|
import {
|
|
|
|
|
APIButton,
|
|
|
|
|
DirectorySearch,
|
|
|
|
|
ErrorMessage,
|
|
|
|
|
FileIcon,
|
|
|
|
|
humanFileSize,
|
|
|
|
|
mimetypeIconName,
|
|
|
|
|
Toggle,
|
|
|
|
|
useIsIgnoredDirectory
|
|
|
|
|
} from "./Common";
|
2025-12-26 11:28:10 -07:00
|
|
|
import React, {useContext, useEffect, useState} from "react";
|
2025-12-25 09:14:00 -07:00
|
|
|
import {useDropzone} from "react-dropzone";
|
2026-07-03 11:17:11 -06:00
|
|
|
import {useHotkeys} from "react-hotkeys-hook";
|
2024-02-19 13:45:41 -07:00
|
|
|
import {deleteFile, ignoreDirectory, makeDirectory, movePaths, renamePath, unignoreDirectory} from "../api";
|
2023-01-31 18:08:07 -07:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
import {SortableTable} from "./SortableTable";
|
2026-07-01 19:52:15 -06:00
|
|
|
import {useBrowseFiles, useElementWidth, useMediaDirectory, useUploadFile, useWROLMode} from "../hooks/customHooks";
|
2024-03-11 17:47:27 -06:00
|
|
|
import {FileRowTagIcon, FilesRefreshButton} from "./Files";
|
2023-02-15 20:58:07 -07:00
|
|
|
import {FilePreviewContext} from "./FilePreview";
|
2025-12-26 11:28:10 -07:00
|
|
|
import {DragSelectionContext, DragSelectionProvider, SettingsContext, ThemeContext} from "../contexts/contexts";
|
2025-12-06 18:07:20 -07:00
|
|
|
import {BulkTagModal} from "./BulkTagModal";
|
2025-12-25 09:14:00 -07:00
|
|
|
import {InlineErrorBoundary} from "./ErrorBoundary";
|
2026-05-03 17:28:06 -06:00
|
|
|
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
2023-01-31 18:08:07 -07:00
|
|
|
|
|
|
|
|
function depthIndentation(path) {
|
|
|
|
|
// Repeated spaces for every folder a path is in.
|
|
|
|
|
const depth = (path.match(/\//g) || []).length;
|
|
|
|
|
return '\xa0\xa0\xa0\xa0'.repeat(depth);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export function pathDirectory(path) {
|
|
|
|
|
// Return the full path of the path's directory.
|
|
|
|
|
// pathDirectory('/some/directory/file.txt') -> '/some/directory'
|
|
|
|
|
return path.substring(0, path.lastIndexOf('/'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function pathName(path) {
|
|
|
|
|
// Return the file's name.
|
|
|
|
|
// pathName('/some/directory/file.txt') -> 'file.txt'
|
|
|
|
|
// pathName('/some/directory') -> 'directory'
|
|
|
|
|
if (path.endsWith('/')) {
|
|
|
|
|
// Path is a directory, return its name.
|
|
|
|
|
path = path.substring(0, path.length - 1);
|
|
|
|
|
}
|
|
|
|
|
return path.substring(path.lastIndexOf('/') + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function splitPathParentAndName(path) {
|
|
|
|
|
if (path.endsWith('/')) {
|
|
|
|
|
// Path is a directory, return its name.
|
|
|
|
|
path = path.substring(0, path.length - 1);
|
|
|
|
|
}
|
|
|
|
|
const slashIndex = path.lastIndexOf('/');
|
|
|
|
|
return [path.substring(0, slashIndex), path.substring(slashIndex + 1, path.length)];
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 11:17:11 -06:00
|
|
|
export function filterBrowseFiles(browseFiles, filterStr) {
|
|
|
|
|
// Reduce the file tree to the rows whose name matches `filterStr`, keeping the ancestor
|
|
|
|
|
// folders of every match. A folder whose own name matches keeps its entire subtree.
|
|
|
|
|
if (!filterStr) {
|
|
|
|
|
return browseFiles;
|
|
|
|
|
}
|
|
|
|
|
const needle = filterStr.toLowerCase();
|
|
|
|
|
const filterList = (files) => {
|
|
|
|
|
// `files` may be a dict keyed by name (from the API) or an array.
|
|
|
|
|
const fileList = Array.isArray(files) ? files : Object.values(files);
|
|
|
|
|
const matches = [];
|
|
|
|
|
for (const file of fileList) {
|
|
|
|
|
if (pathName(file.path).toLowerCase().includes(needle)) {
|
|
|
|
|
matches.push(file);
|
|
|
|
|
} else if (file.children) {
|
|
|
|
|
const children = filterList(file.children);
|
|
|
|
|
if (children.length > 0) {
|
|
|
|
|
matches.push({...file, children});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return matches;
|
|
|
|
|
};
|
|
|
|
|
return filterList(browseFiles);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-03 16:36:44 -07:00
|
|
|
function Folder({folder, onFolderClick, sortData, onFileClick, disabled, loadingFolders}) {
|
|
|
|
|
const {handleDragStart, handleDragMove, getDragState, shouldAllowClick, selectedPaths, onSelect} = useContext(DragSelectionContext);
|
2023-01-31 18:08:07 -07:00
|
|
|
// Creates a single table row for a folder, or a row for itself and indented rows for its children.
|
2024-02-19 13:45:41 -07:00
|
|
|
let {path, children, is_empty} = folder;
|
|
|
|
|
const ignored = useIsIgnoredDirectory(path);
|
2023-01-31 18:08:07 -07:00
|
|
|
const pathWithNoTrailingSlash = path.substring(0, path.length - 1);
|
|
|
|
|
const name = path.substring(pathWithNoTrailingSlash.lastIndexOf('/') + 1);
|
2025-12-26 11:28:10 -07:00
|
|
|
const isInSelectedPaths = selectedPaths.indexOf(folder['path']) >= 0;
|
|
|
|
|
const {isDragSelecting, isDragDeselecting} = getDragState(path, isInSelectedPaths);
|
|
|
|
|
// Preview selection: show checked if selecting, unchecked if deselecting
|
|
|
|
|
const showAsSelected = (isInSelectedPaths && !isDragDeselecting) || isDragSelecting;
|
|
|
|
|
// Visual highlight class
|
|
|
|
|
const dragClass = isDragSelecting ? 'drag-selecting' : (isDragDeselecting ? 'drag-deselecting' : '');
|
2026-02-03 16:36:44 -07:00
|
|
|
|
|
|
|
|
const isLoading = loadingFolders && loadingFolders.has(path);
|
|
|
|
|
const depth = (path.match(/\//g) || []).length;
|
|
|
|
|
|
2025-12-26 11:28:10 -07:00
|
|
|
const f = <TableRow
|
|
|
|
|
key={path}
|
2026-02-03 16:36:44 -07:00
|
|
|
disabled={isLoading || disabled}
|
2025-12-26 11:28:10 -07:00
|
|
|
className={dragClass}
|
|
|
|
|
onMouseDown={(e) => handleDragStart(path, e)}
|
|
|
|
|
onMouseEnter={() => handleDragMove(path)}
|
|
|
|
|
>
|
2023-01-31 18:08:07 -07:00
|
|
|
<TableCell collapsing>
|
2025-12-26 11:28:10 -07:00
|
|
|
<Checkbox checked={showAsSelected} onChange={() => onSelect(folder['path'])}/>
|
2023-01-31 18:08:07 -07:00
|
|
|
</TableCell>
|
2026-02-03 16:36:44 -07:00
|
|
|
<TableCell onClick={() => shouldAllowClick() && onFolderClick(path)} className='file-path' colSpan={2} disabled={is_empty}>
|
2023-01-31 18:08:07 -07:00
|
|
|
{depthIndentation(pathWithNoTrailingSlash)}
|
2023-02-14 08:08:04 -07:00
|
|
|
{is_empty ? <Icon name='folder outline'/> : <Icon name='folder'/>}
|
2024-02-19 13:45:41 -07:00
|
|
|
{ignored && <Icon name='eye slash' color='red'/>}
|
2023-01-31 18:08:07 -07:00
|
|
|
{name}
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>;
|
2023-02-15 17:40:57 -07:00
|
|
|
if (children) {
|
2023-01-31 18:08:07 -07:00
|
|
|
// Folder has children, recursively display them.
|
|
|
|
|
children = sortData(children);
|
|
|
|
|
let childPaths = [];
|
|
|
|
|
_.forEach(children, (p, k) => {
|
|
|
|
|
childPaths = [...childPaths,
|
2025-12-25 09:14:00 -07:00
|
|
|
<InlineErrorBoundary key={k}>
|
|
|
|
|
<Path path={p} onFolderClick={onFolderClick} sortData={sortData} onFileClick={onFileClick}
|
2026-02-03 16:36:44 -07:00
|
|
|
disabled={disabled} loadingFolders={loadingFolders}/>
|
2025-12-25 09:14:00 -07:00
|
|
|
</InlineErrorBoundary>];
|
2023-01-31 18:08:07 -07:00
|
|
|
});
|
|
|
|
|
return <React.Fragment>
|
|
|
|
|
{f}
|
|
|
|
|
{childPaths}
|
|
|
|
|
</React.Fragment>
|
2026-02-03 16:36:44 -07:00
|
|
|
} else if (isLoading) {
|
|
|
|
|
// Folder is loading - show skeleton rows
|
|
|
|
|
return <React.Fragment>
|
|
|
|
|
{f}
|
|
|
|
|
<SkeletonFileRow depth={depth}/>
|
|
|
|
|
</React.Fragment>;
|
2023-01-31 18:08:07 -07:00
|
|
|
} else {
|
|
|
|
|
// Folder has no children.
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-03 16:36:44 -07:00
|
|
|
function File({file, onFileClick, disabled}) {
|
|
|
|
|
const {handleDragStart, handleDragMove, getDragState, shouldAllowClick, selectedPaths, onSelect} = useContext(DragSelectionContext);
|
2023-01-31 18:08:07 -07:00
|
|
|
const {path, size} = file;
|
2025-12-26 11:28:10 -07:00
|
|
|
const isInSelectedPaths = selectedPaths.indexOf(path) >= 0;
|
|
|
|
|
const {isDragSelecting, isDragDeselecting} = getDragState(path, isInSelectedPaths);
|
|
|
|
|
// Preview selection: show checked if selecting, unchecked if deselecting
|
|
|
|
|
const showAsSelected = (isInSelectedPaths && !isDragDeselecting) || isDragSelecting;
|
|
|
|
|
// Visual highlight class
|
|
|
|
|
const dragClass = isDragSelecting ? 'drag-selecting' : (isDragDeselecting ? 'drag-deselecting' : '');
|
|
|
|
|
return <TableRow
|
|
|
|
|
key={path}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
className={dragClass}
|
|
|
|
|
onMouseDown={(e) => handleDragStart(path, e)}
|
|
|
|
|
onMouseEnter={() => handleDragMove(path)}
|
|
|
|
|
>
|
2023-01-31 18:08:07 -07:00
|
|
|
<TableCell collapsing>
|
2025-12-26 11:28:10 -07:00
|
|
|
<Checkbox checked={showAsSelected} onChange={() => onSelect(path)}/>
|
2023-01-31 18:08:07 -07:00
|
|
|
</TableCell>
|
2026-02-03 16:36:44 -07:00
|
|
|
<TableCell onClick={() => shouldAllowClick() && onFileClick(file)} className='file-path'>
|
2023-01-31 18:08:07 -07:00
|
|
|
{depthIndentation(path)}
|
2023-04-01 11:52:41 -06:00
|
|
|
<FileRowTagIcon file={file}/>
|
2023-01-31 18:08:07 -07:00
|
|
|
{/*null size to make icon the correct size*/}
|
|
|
|
|
<FileIcon file={file} size={null}/>
|
2023-05-29 18:04:03 -06:00
|
|
|
{pathName(path)}
|
2023-01-31 18:08:07 -07:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell collapsing textAlign='right'>
|
|
|
|
|
{humanFileSize(size)}
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-03 16:36:44 -07:00
|
|
|
function Path({path, onFolderClick, onFileClick, sortData, disabled, loadingFolders}) {
|
2023-01-31 18:08:07 -07:00
|
|
|
if (path['path'].endsWith('/')) {
|
|
|
|
|
return <Folder
|
|
|
|
|
folder={path}
|
|
|
|
|
onFolderClick={onFolderClick}
|
|
|
|
|
sortData={sortData}
|
|
|
|
|
onFileClick={onFileClick}
|
2023-05-29 18:04:03 -06:00
|
|
|
disabled={disabled}
|
2026-02-03 16:36:44 -07:00
|
|
|
loadingFolders={loadingFolders}
|
2023-01-31 18:08:07 -07:00
|
|
|
/>
|
|
|
|
|
} else {
|
|
|
|
|
return <File
|
|
|
|
|
file={path}
|
|
|
|
|
onFileClick={onFileClick}
|
2023-05-29 18:04:03 -06:00
|
|
|
disabled={disabled}
|
2023-01-31 18:08:07 -07:00
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-03 16:36:44 -07:00
|
|
|
function SkeletonFileRow({depth}) {
|
|
|
|
|
const indentation = '\xa0\xa0\xa0\xa0'.repeat(depth);
|
|
|
|
|
return (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell collapsing>
|
|
|
|
|
<Checkbox disabled/>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className='file-path' colSpan={2}>
|
|
|
|
|
{indentation}
|
|
|
|
|
<Placeholder style={{display: 'inline-block', width: '200px', marginLeft: '0.5em'}}>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</Placeholder>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-01 19:52:15 -06:00
|
|
|
// Below this footer width (px) the action buttons are icon-only; at or above it they expand to show labels.
|
|
|
|
|
// The eight labeled buttons need ~1020px to fit on a single row; this leaves a small buffer.
|
|
|
|
|
const FOOTER_LABELS_MIN_WIDTH = 1050;
|
|
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
export function FileBrowser() {
|
2023-05-29 18:04:03 -06:00
|
|
|
const [selectedPaths, setSelectedPaths] = React.useState([]);
|
|
|
|
|
const [renameOpen, setRenameOpen] = React.useState(false);
|
|
|
|
|
const [moveOpen, setMoveOpen] = React.useState(false);
|
|
|
|
|
const [makeDirectoryOpen, setMakeDirectoryOpen] = React.useState(false);
|
2024-02-19 13:45:41 -07:00
|
|
|
const [ignoreDirectoryOpen, setIgnoreDirectoryOpen] = React.useState(false);
|
2025-12-06 18:07:20 -07:00
|
|
|
const [bulkTagOpen, setBulkTagOpen] = React.useState(false);
|
2025-12-25 09:14:00 -07:00
|
|
|
const [uploadOpen, setUploadOpen] = React.useState(false);
|
2023-05-29 18:04:03 -06:00
|
|
|
const [pending, setPending] = React.useState(false);
|
2026-02-03 16:36:44 -07:00
|
|
|
// Tracks which folders are currently loading their children
|
|
|
|
|
const [loadingFolders, setLoadingFolders] = React.useState(new Set());
|
2024-02-19 13:45:41 -07:00
|
|
|
// Only true if only one path is selected, and it is a directory.
|
|
|
|
|
const [singleDirectorySelected, setSingleDirectorySelected] = React.useState(false);
|
|
|
|
|
// Only true if single directory is selected, and it is in settings['ignored_directories']
|
|
|
|
|
const [isDirectoryIgnored, setIsDirectoryIgnored] = React.useState(false);
|
2025-12-25 10:05:00 -07:00
|
|
|
// Tracks folder that was opened while selected - its children will be auto-selected when they load
|
|
|
|
|
const pendingAutoSelectRef = React.useRef(null);
|
2026-04-14 10:40:24 -06:00
|
|
|
// Tagged file groups that would be deleted - shown in confirmation modal
|
|
|
|
|
const [taggedFileGroups, setTaggedFileGroups] = React.useState(null);
|
2026-07-03 11:17:11 -06:00
|
|
|
// Reduces the visible rows to those matching, and their parent folders.
|
|
|
|
|
const [filterStr, setFilterStr] = React.useState('');
|
|
|
|
|
const filterInputRef = React.useRef();
|
|
|
|
|
|
|
|
|
|
// 'f' focuses the filter input, like the search inputs on other pages.
|
|
|
|
|
useHotkeys('f', (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (filterInputRef.current) {
|
|
|
|
|
filterInputRef.current.focus();
|
|
|
|
|
}
|
|
|
|
|
}, {enableOnFormTags: false});
|
2024-02-19 13:45:41 -07:00
|
|
|
|
|
|
|
|
const {settings, fetchSettings} = React.useContext(SettingsContext);
|
2025-12-07 09:17:30 -07:00
|
|
|
const {inverted} = React.useContext(ThemeContext);
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
const selectedPathsCount = selectedPaths ? selectedPaths.length : 0;
|
2023-01-31 18:08:07 -07:00
|
|
|
|
|
|
|
|
const {browseFiles, openFolders, setOpenFolders, fetchFiles} = useBrowseFiles();
|
2023-07-21 15:14:09 -06:00
|
|
|
const wrolModeEnabled = useWROLMode();
|
2023-01-31 18:08:07 -07:00
|
|
|
|
2023-04-01 11:52:41 -06:00
|
|
|
const headers = [
|
|
|
|
|
{key: 'select', text: ''},
|
|
|
|
|
{key: 'path', text: 'Path', sortBy: i => i['path'].toLowerCase()},
|
|
|
|
|
{key: 'size', text: 'Size', sortBy: 'size'},
|
|
|
|
|
];
|
2023-01-31 18:08:07 -07:00
|
|
|
|
2023-04-01 11:52:41 -06:00
|
|
|
const {setPreviewFile, setCallbacks} = React.useContext(FilePreviewContext);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Fetch files after tagging.
|
2023-04-10 12:27:55 -06:00
|
|
|
setCallbacks([() => fetchFiles(openFolders)]);
|
2023-04-01 11:52:41 -06:00
|
|
|
|
|
|
|
|
return () => setCallbacks(null);
|
|
|
|
|
}, []);
|
2023-01-31 18:08:07 -07:00
|
|
|
|
2024-02-19 13:45:41 -07:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (selectedPaths.length === 1 && selectedPaths[0].endsWith('/')) {
|
|
|
|
|
setSingleDirectorySelected(true);
|
|
|
|
|
if (!_.isEmpty(settings)) {
|
|
|
|
|
// Used to toggle between ignore/un-ignore (eye/eye lash) icon.
|
|
|
|
|
const directory = selectedPaths[0].slice(0, -1);
|
|
|
|
|
setIsDirectoryIgnored(settings['ignored_directories'].indexOf(directory) >= 0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setSingleDirectorySelected(false);
|
|
|
|
|
}
|
|
|
|
|
}, [selectedPaths, settings]);
|
|
|
|
|
|
2025-12-25 10:05:00 -07:00
|
|
|
// Auto-select immediate children when a selected folder is opened
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const folderToAutoSelect = pendingAutoSelectRef.current;
|
|
|
|
|
if (folderToAutoSelect && browseFiles && typeof browseFiles === 'object') {
|
|
|
|
|
// browseFiles is a dict: {'map/': {path: 'map/', children: {...}}, ...}
|
|
|
|
|
// children is also a dict: {'file.txt': {path: 'map/file.txt', ...}, ...}
|
|
|
|
|
const findFolderChildren = (files, targetFolder) => {
|
|
|
|
|
if (!files || typeof files !== 'object') return null;
|
|
|
|
|
// Convert dict to array of values for iteration
|
|
|
|
|
const fileList = Array.isArray(files) ? files : Object.values(files);
|
|
|
|
|
for (const file of fileList) {
|
|
|
|
|
if (file.path === targetFolder && file.children) {
|
|
|
|
|
// Return children as array of values
|
|
|
|
|
return Array.isArray(file.children) ? file.children : Object.values(file.children);
|
|
|
|
|
}
|
|
|
|
|
if (file.children) {
|
|
|
|
|
const found = findFolderChildren(file.children, targetFolder);
|
|
|
|
|
if (found) return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const children = findFolderChildren(browseFiles, folderToAutoSelect);
|
|
|
|
|
if (children && children.length > 0) {
|
|
|
|
|
const childPaths = children.map(child => child.path);
|
|
|
|
|
const newSelectedPaths = [...new Set([...selectedPaths, ...childPaths])];
|
|
|
|
|
setSelectedPaths(newSelectedPaths);
|
|
|
|
|
}
|
|
|
|
|
pendingAutoSelectRef.current = null;
|
|
|
|
|
}
|
|
|
|
|
}, [browseFiles]);
|
|
|
|
|
|
2026-02-03 16:36:44 -07:00
|
|
|
// Clear loading states when file data updates
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (loadingFolders.size > 0) {
|
|
|
|
|
setLoadingFolders(new Set());
|
|
|
|
|
}
|
|
|
|
|
}, [browseFiles]);
|
|
|
|
|
|
2024-02-19 13:45:41 -07:00
|
|
|
const onIgnore = async () => {
|
|
|
|
|
setIgnoreDirectoryOpen(false);
|
|
|
|
|
await fetchSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 10:40:24 -06:00
|
|
|
const handleDeleteComplete = async () => {
|
2025-12-25 09:44:11 -07:00
|
|
|
// Remove deleted directories from openFolders to prevent fetching non-existent directories
|
|
|
|
|
const deletedDirs = selectedPaths.filter(p => p.endsWith('/'));
|
|
|
|
|
if (deletedDirs.length > 0 && openFolders && openFolders.length > 0) {
|
|
|
|
|
const newOpenFolders = openFolders.filter(folder =>
|
|
|
|
|
!deletedDirs.some(deleted => folder === deleted || folder.startsWith(deleted))
|
|
|
|
|
);
|
|
|
|
|
setOpenFolders(newOpenFolders.length > 0 ? newOpenFolders : null);
|
|
|
|
|
}
|
2023-05-29 18:04:03 -06:00
|
|
|
await reset();
|
2023-01-31 18:08:07 -07:00
|
|
|
};
|
|
|
|
|
|
2026-04-14 10:40:24 -06:00
|
|
|
const onDelete = async () => {
|
|
|
|
|
const result = await deleteFile(selectedPaths);
|
|
|
|
|
if (result && result.tagged) {
|
|
|
|
|
// Show modal with tagged file groups for user to confirm.
|
|
|
|
|
setTaggedFileGroups(result.file_groups);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await handleDeleteComplete();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onForceDelete = async () => {
|
|
|
|
|
setTaggedFileGroups(null);
|
|
|
|
|
const result = await deleteFile(selectedPaths, true);
|
|
|
|
|
if (result && result.tagged) return; // unexpected tagged response
|
|
|
|
|
if (result && !result.ok) return; // error already toasted
|
|
|
|
|
await handleDeleteComplete();
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
const handleMakeDirectory = async () => {
|
|
|
|
|
setMakeDirectoryOpen(false);
|
|
|
|
|
await reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const reset = async () => {
|
|
|
|
|
setSelectedPaths([]);
|
|
|
|
|
setPending(true);
|
|
|
|
|
try {
|
|
|
|
|
await fetchFiles();
|
|
|
|
|
} finally {
|
|
|
|
|
setPending(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-01 19:52:15 -06:00
|
|
|
const [footerRef, footerWidth] = useElementWidth();
|
|
|
|
|
// Expand icon-only buttons to include labels once the footer is wide enough to fit them.
|
|
|
|
|
const showLabels = footerWidth >= FOOTER_LABELS_MIN_WIDTH;
|
|
|
|
|
// Semantic UI renders a labeled icon button when `content` and `labelPosition` are set, else icon-only.
|
|
|
|
|
const labelProps = (content) => showLabels ? {content, labelPosition: 'left'} : {};
|
|
|
|
|
|
2025-12-07 09:17:30 -07:00
|
|
|
const footerClassName = `sticky-footer ${inverted}`;
|
2026-07-01 19:52:15 -06:00
|
|
|
const footer = <div className={footerClassName} ref={footerRef}>
|
|
|
|
|
<FilesRefreshButton paths={selectedPaths} showLabel={showLabels}/>
|
2025-12-07 09:17:30 -07:00
|
|
|
<APIButton
|
|
|
|
|
icon='trash'
|
|
|
|
|
color='red'
|
|
|
|
|
confirmContent='Are you sure you want to delete these files?'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onClick={onDelete}
|
|
|
|
|
disabled={selectedPathsCount === 0}
|
|
|
|
|
obeyWROLMode={true}
|
2026-07-01 19:52:15 -06:00
|
|
|
{...labelProps('Delete')}
|
2025-12-07 09:17:30 -07:00
|
|
|
/>
|
|
|
|
|
<Button icon='text cursor'
|
|
|
|
|
color='yellow'
|
|
|
|
|
onClick={() => setRenameOpen(true)}
|
|
|
|
|
disabled={wrolModeEnabled || selectedPathsCount !== 1}
|
2026-07-01 19:52:15 -06:00
|
|
|
{...labelProps('Rename')}
|
2025-12-07 09:17:30 -07:00
|
|
|
/>
|
|
|
|
|
{selectedPathsCount === 1 ?
|
|
|
|
|
<RenameModal
|
|
|
|
|
open={renameOpen}
|
|
|
|
|
onClose={() => setRenameOpen(false)}
|
|
|
|
|
onPending={setPending}
|
|
|
|
|
path={selectedPaths[0]}
|
|
|
|
|
onSubmit={reset}
|
|
|
|
|
/> : null}
|
|
|
|
|
<Button icon='move'
|
|
|
|
|
color='teal'
|
|
|
|
|
disabled={wrolModeEnabled || selectedPathsCount === 0}
|
|
|
|
|
onClick={() => setMoveOpen(true)}
|
2026-07-01 19:52:15 -06:00
|
|
|
{...labelProps('Move')}
|
2025-12-07 09:17:30 -07:00
|
|
|
/>
|
|
|
|
|
{selectedPathsCount > 0 ?
|
|
|
|
|
<MoveModal open={moveOpen}
|
|
|
|
|
onClose={() => setMoveOpen(false)}
|
|
|
|
|
paths={selectedPaths}
|
|
|
|
|
onSubmit={reset}
|
|
|
|
|
/> : null}
|
|
|
|
|
<Button
|
|
|
|
|
color='blue'
|
|
|
|
|
onClick={() => setMakeDirectoryOpen(true)}
|
|
|
|
|
disabled={wrolModeEnabled}
|
2026-07-01 19:52:15 -06:00
|
|
|
style={{paddingLeft: '1em', paddingRight: showLabels ? '1em' : '0.8em'}}
|
2025-12-07 09:17:30 -07:00
|
|
|
>
|
|
|
|
|
<IconGroup>
|
|
|
|
|
<Icon name='folder'/>
|
|
|
|
|
<Icon corner name='add'/>
|
|
|
|
|
</IconGroup>
|
2026-07-01 19:52:15 -06:00
|
|
|
{showLabels ? <> New Folder</> : null}
|
2025-12-07 09:17:30 -07:00
|
|
|
</Button>
|
|
|
|
|
<MakeDirectoryModal
|
|
|
|
|
open={makeDirectoryOpen}
|
|
|
|
|
onClose={() => setMakeDirectoryOpen(false)}
|
|
|
|
|
parent={selectedPaths.length ? selectedPaths[0] : null}
|
|
|
|
|
onSubmit={handleMakeDirectory}
|
|
|
|
|
/>
|
2025-12-25 09:14:00 -07:00
|
|
|
<Button
|
|
|
|
|
icon='upload'
|
|
|
|
|
color='green'
|
|
|
|
|
disabled={wrolModeEnabled || (selectedPathsCount > 0 && !singleDirectorySelected)}
|
|
|
|
|
onClick={() => setUploadOpen(true)}
|
2026-07-01 19:52:15 -06:00
|
|
|
{...labelProps('Upload')}
|
2025-12-25 09:14:00 -07:00
|
|
|
/>
|
|
|
|
|
<FileBrowserUploadModal
|
|
|
|
|
open={uploadOpen}
|
|
|
|
|
onClose={() => setUploadOpen(false)}
|
|
|
|
|
destination={singleDirectorySelected && selectedPaths[0] ? selectedPaths[0].slice(0, -1) : ''}
|
|
|
|
|
onComplete={reset}
|
|
|
|
|
/>
|
2025-12-07 09:17:30 -07:00
|
|
|
<Button
|
|
|
|
|
color='grey'
|
|
|
|
|
icon={isDirectoryIgnored ? 'eye' : 'eye slash'}
|
|
|
|
|
disabled={!singleDirectorySelected || wrolModeEnabled}
|
|
|
|
|
onClick={() => setIgnoreDirectoryOpen(true)}
|
2026-07-01 19:52:15 -06:00
|
|
|
{...labelProps(isDirectoryIgnored ? 'Unignore' : 'Ignore')}
|
2025-12-07 09:17:30 -07:00
|
|
|
/>
|
|
|
|
|
<IgnoreDirectoryModal
|
|
|
|
|
open={ignoreDirectoryOpen}
|
|
|
|
|
onClose={onIgnore}
|
|
|
|
|
onSubmit={onIgnore}
|
|
|
|
|
directory={selectedPaths.length === 1 ? selectedPaths[0] : null}
|
|
|
|
|
ignored={isDirectoryIgnored}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
color='violet'
|
|
|
|
|
icon='tags'
|
|
|
|
|
disabled={selectedPathsCount === 0}
|
|
|
|
|
onClick={() => setBulkTagOpen(true)}
|
2026-07-01 19:52:15 -06:00
|
|
|
{...labelProps('Tag')}
|
2025-12-07 09:17:30 -07:00
|
|
|
/>
|
|
|
|
|
<BulkTagModal
|
|
|
|
|
open={bulkTagOpen}
|
|
|
|
|
onClose={() => setBulkTagOpen(false)}
|
|
|
|
|
paths={selectedPaths}
|
|
|
|
|
onComplete={reset}
|
|
|
|
|
/>
|
2026-05-03 17:28:06 -06:00
|
|
|
<TaggedDeleteConfirmModal
|
2026-04-14 10:40:24 -06:00
|
|
|
open={taggedFileGroups !== null}
|
2026-05-03 17:28:06 -06:00
|
|
|
taggedFileGroups={taggedFileGroups}
|
|
|
|
|
onCancel={() => setTaggedFileGroups(null)}
|
|
|
|
|
onConfirm={onForceDelete}
|
|
|
|
|
/>
|
2025-12-07 09:17:30 -07:00
|
|
|
</div>;
|
2023-01-31 18:08:07 -07:00
|
|
|
|
2026-07-03 11:17:11 -06:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
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));
|
2025-12-25 10:05:00 -07:00
|
|
|
// 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);
|
|
|
|
|
}
|
2023-01-31 18:08:07 -07:00
|
|
|
} else {
|
|
|
|
|
// Add the new folder to the opened folders.
|
|
|
|
|
newFolders = [...openFolders, folder];
|
2026-02-03 16:36:44 -07:00
|
|
|
// Mark folder as loading so skeleton rows show
|
|
|
|
|
setLoadingFolders(prev => new Set([...prev, folder]));
|
2025-12-25 10:05:00 -07:00
|
|
|
// If folder is selected, mark it for auto-selection of its children
|
|
|
|
|
if (selectedPaths.includes(folder)) {
|
|
|
|
|
pendingAutoSelectRef.current = folder;
|
|
|
|
|
}
|
2023-01-31 18:08:07 -07:00
|
|
|
}
|
|
|
|
|
console.debug(`newFolders=${newFolders}`);
|
|
|
|
|
setOpenFolders(newFolders);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 11:17:11 -06:00
|
|
|
const filteredFiles = React.useMemo(
|
|
|
|
|
() => browseFiles ? filterBrowseFiles(browseFiles, filterStr) : browseFiles,
|
|
|
|
|
[browseFiles, filterStr],
|
|
|
|
|
);
|
|
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
if (browseFiles === null) {
|
|
|
|
|
return <Placeholder>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</Placeholder>;
|
2023-09-07 20:13:36 -06:00
|
|
|
} else if (browseFiles === undefined) {
|
|
|
|
|
return <ErrorMessage>Could not fetch files</ErrorMessage>
|
2023-01-31 18:08:07 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-26 11:28:10 -07:00
|
|
|
return <DragSelectionProvider
|
|
|
|
|
selectedPaths={selectedPaths}
|
|
|
|
|
setSelectedPaths={setSelectedPaths}
|
2026-07-03 11:17:11 -06:00
|
|
|
browseFiles={filteredFiles}
|
2025-12-26 11:28:10 -07:00
|
|
|
openFolders={openFolders}
|
|
|
|
|
>
|
2026-07-03 11:17:11 -06:00
|
|
|
<div className='file-browser-filter-container'>
|
|
|
|
|
<Input
|
|
|
|
|
icon='filter'
|
|
|
|
|
iconPosition='left'
|
|
|
|
|
placeholder='Filter files...'
|
|
|
|
|
value={filterStr}
|
|
|
|
|
onChange={(e, {value}) => setFilterStr(value)}
|
|
|
|
|
aria-label='Filter files'
|
|
|
|
|
className='file-browser-filter'
|
|
|
|
|
ref={filterInputRef}
|
|
|
|
|
action={<Button
|
|
|
|
|
icon='close'
|
|
|
|
|
type='button'
|
|
|
|
|
onClick={() => setFilterStr('')}
|
|
|
|
|
disabled={!filterStr}
|
|
|
|
|
className='search-clear'
|
|
|
|
|
aria-label='Clear filter'
|
|
|
|
|
/>}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
icon='angle double up'
|
|
|
|
|
type='button'
|
|
|
|
|
onClick={onCollapseAll}
|
|
|
|
|
disabled={!openFolders || openFolders.length === 0}
|
|
|
|
|
title='Close all folders'
|
|
|
|
|
aria-label='Close all folders'
|
|
|
|
|
style={{marginLeft: '0.5em'}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-12-26 11:28:10 -07:00
|
|
|
<FileBrowserContent
|
2026-07-03 11:17:11 -06:00
|
|
|
browseFiles={filteredFiles}
|
2025-12-26 11:28:10 -07:00
|
|
|
headers={headers}
|
|
|
|
|
onFolderClick={onFolderClick}
|
|
|
|
|
setPreviewFile={setPreviewFile}
|
|
|
|
|
pending={pending}
|
2026-02-03 16:36:44 -07:00
|
|
|
loadingFolders={loadingFolders}
|
2025-12-26 11:28:10 -07:00
|
|
|
/>
|
|
|
|
|
{footer}
|
|
|
|
|
</DragSelectionProvider>
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-03 16:36:44 -07:00
|
|
|
function FileBrowserContent({browseFiles, headers, onFolderClick, setPreviewFile, pending, loadingFolders}) {
|
2025-12-26 11:28:10 -07:00
|
|
|
const {isDragging} = useContext(DragSelectionContext);
|
|
|
|
|
const containerClassName = isDragging ? 'file-browser-dragging' : '';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={{marginBottom: '4em'}} className={containerClassName}>
|
2025-12-07 09:17:30 -07:00
|
|
|
<SortableTable
|
ui: nine leaf files off Semantic, and the components they needed
Phase 2, part 2. Baseline 72 -> 63.
Migrated: Tables, SortableTable, DonatePage, Share, Headline, ErrorBoundary,
and the QR code, VIN decoder, and temperature calculators.
New in the library, all in the gallery and tested:
SearchBox Semantic's `<Search category>`, keeping its grouped `results`
shape because four call sites already build it. A real
combobox: arrows move, Enter takes the highlighted suggestion
or submits the raw text, Escape closes without clearing.
Pagination Semantic's prop names, but onPageChange gets the page number
rather than an (event, data) pair.
TabBar the strip and its house style only; routing stays at the call
site, which is what decides what is active.
IconStack two glyphs composed into one symbol, named once for assistive
technology (Semantic's IconGroup).
Table.HeaderCell gains `sorted` and `onSort`.
That last one is a fix, not just a port. Semantic's `sorted` prop set
`aria-sort`; migrating a table by hand dropped it, leaving a clickable <th>
that no keyboard could reach and no screen reader could describe. Putting it
in the library means the next table gets it right without anyone remembering.
Night mode holes closed along the way: the QR codes on the donate, share, and
calculator pages are white by necessity — a scanner needs the contrast — and
they render as SVG, which the media filter does not target. In night mode that
was a lit panel. They now carry `.media`, so the filter remaps the block as a
unit and the contrast survives the mapping.
Also: `paypal` joins the icon map rather than being imported ad hoc in a page,
and FileBrowser stops passing Semantic-only table props into a DOM element.
2026-07-30 09:31:15 -06:00
|
|
|
tableProps={{striped: true}}
|
2025-12-07 09:17:30 -07:00
|
|
|
data={browseFiles}
|
|
|
|
|
tableHeaders={headers}
|
|
|
|
|
defaultSortColumn='path'
|
|
|
|
|
rowKey='path'
|
2025-12-26 11:28:10 -07:00
|
|
|
rowFunc={(i, sortData) => (
|
|
|
|
|
<Path
|
|
|
|
|
key={i['key']}
|
|
|
|
|
path={i}
|
|
|
|
|
onFolderClick={onFolderClick}
|
|
|
|
|
onFileClick={(file) => setPreviewFile(file)}
|
|
|
|
|
sortData={sortData}
|
|
|
|
|
disabled={pending}
|
2026-02-03 16:36:44 -07:00
|
|
|
loadingFolders={loadingFolders}
|
2025-12-26 11:28:10 -07:00
|
|
|
/>
|
|
|
|
|
)}
|
2025-12-07 09:17:30 -07:00
|
|
|
/>
|
|
|
|
|
</div>
|
2025-12-26 11:28:10 -07:00
|
|
|
);
|
2023-01-31 18:08:07 -07:00
|
|
|
}
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
export function RenameModal({open, onClose, path, onSubmit, onPending}) {
|
|
|
|
|
const [parent, name] = splitPathParentAndName(path);
|
|
|
|
|
const [value, setValue] = React.useState(name);
|
|
|
|
|
const disabled = value === name;
|
|
|
|
|
|
|
|
|
|
const handleInputChange = (e, props) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
setValue(props.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
console.log(`Renaming: ${path} to ${value}`);
|
|
|
|
|
onPending(true);
|
|
|
|
|
await renamePath(path, value);
|
|
|
|
|
} finally {
|
|
|
|
|
onClose();
|
|
|
|
|
onPending(false);
|
|
|
|
|
if (onSubmit) {
|
|
|
|
|
await onSubmit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setValue(pathName(path));
|
|
|
|
|
}, [path]);
|
|
|
|
|
|
|
|
|
|
return <Modal closeIcon
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Header>Rename: {name}</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
2024-05-19 16:04:45 -06:00
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
|
<Header as='h4'>New Name</Header>
|
|
|
|
|
<pre>{parent ? parent + '/' : null}{value}</pre>
|
|
|
|
|
|
|
|
|
|
<Input fluid
|
2026-07-06 15:35:23 -06:00
|
|
|
autoFocus
|
2024-05-19 16:04:45 -06:00
|
|
|
label='Name'
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Button
|
|
|
|
|
color='violet'
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
onClick={handleSubmit}
|
|
|
|
|
>
|
|
|
|
|
Rename
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setValue(name)}
|
|
|
|
|
floated='left'
|
|
|
|
|
>
|
|
|
|
|
Reset
|
|
|
|
|
</Button>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Modal>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function MoveModal({open, paths, onClose, onSubmit}) {
|
|
|
|
|
const [destination, setDestination] = React.useState('');
|
|
|
|
|
const [pending, setPending] = React.useState(false);
|
|
|
|
|
|
|
|
|
|
const handleDirectory = (value) => {
|
|
|
|
|
setDestination(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleMove = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setPending(true);
|
|
|
|
|
await movePaths(destination, paths);
|
|
|
|
|
onClose();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
setPending(false);
|
|
|
|
|
}
|
|
|
|
|
if (onSubmit) {
|
|
|
|
|
await onSubmit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fileCell = i => <TableCell>
|
|
|
|
|
<pre style={{marginTop: 0, marginBottom: 0}}>{i}</pre>
|
|
|
|
|
</TableCell>;
|
|
|
|
|
|
|
|
|
|
const destinationRows = paths.map(i => <TableRow key={i}>
|
|
|
|
|
{fileCell(i)}
|
|
|
|
|
{destination ? fileCell(destination + '/' + pathName(i)) : fileCell(pathName(i))}
|
|
|
|
|
</TableRow>);
|
|
|
|
|
|
|
|
|
|
return <Modal closeIcon
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
open={open}
|
|
|
|
|
>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Header>Move Files/Directories</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
2023-05-29 18:04:03 -06:00
|
|
|
<p>Search for a directory to move your files into:</p>
|
2026-07-06 15:35:23 -06:00
|
|
|
<DirectorySearch onSelect={handleDirectory} disabled={pending} input={{autoFocus: true}}/>
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHeaderCell>Source</TableHeaderCell>
|
|
|
|
|
<TableHeaderCell>Destination</TableHeaderCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{destinationRows}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Button
|
|
|
|
|
color='violet'
|
|
|
|
|
onClick={handleMove}
|
|
|
|
|
disabled={pending}
|
|
|
|
|
>Move</Button>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setDestination(null)}
|
|
|
|
|
floated='left'
|
|
|
|
|
disabled={pending}
|
|
|
|
|
>Reset</Button>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Modal>
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-19 13:45:41 -07:00
|
|
|
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 = <Button primary
|
|
|
|
|
disabled={pending}
|
|
|
|
|
onClick={handleIgnore}
|
|
|
|
|
>{ignored ? 'Un-ignore' : 'Ignore'}</Button>;
|
|
|
|
|
|
|
|
|
|
return <Modal closeIcon open={open} onClose={onClose}>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Header>{header}</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
2024-02-19 13:45:41 -07:00
|
|
|
{content}
|
|
|
|
|
<pre>{mediaDirectory}/{directory}</pre>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
2024-02-19 13:45:41 -07:00
|
|
|
{submitButton}
|
|
|
|
|
<Button secondary floated='left' onClick={onClose}>Close</Button>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Actions>
|
2024-02-19 13:45:41 -07:00
|
|
|
</Modal>
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export function MakeDirectoryModal({open, onClose, parent, onSubmit}) {
|
|
|
|
|
const [value, setValue] = useState('');
|
|
|
|
|
const mediaDirectory = useMediaDirectory();
|
|
|
|
|
|
|
|
|
|
const handleInputChange = (e, props) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
setValue(props.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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Modal closeIcon open={open} onClose={onClose}>
|
2025-12-07 11:32:07 -07:00
|
|
|
<Modal.Header>Make Directory</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
2024-05-19 16:04:45 -06:00
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
|
<pre>{mediaDirectory}/{parent}{value}</pre>
|
|
|
|
|
<Input fluid
|
2026-07-06 15:35:23 -06:00
|
|
|
autoFocus
|
2024-05-19 16:04:45 -06:00
|
|
|
label='Name'
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
<Button color='violet' onClick={handleSubmit}>Create</Button>
|
2025-12-07 11:32:07 -07:00
|
|
|
</Modal.Actions>
|
2023-05-29 18:04:03 -06:00
|
|
|
</Modal>
|
2025-12-07 09:17:30 -07:00
|
|
|
}
|
2025-12-25 09:14:00 -07:00
|
|
|
|
|
|
|
|
export function FileBrowserUploadModal({open, onClose, destination, onComplete}) {
|
|
|
|
|
const mediaDirectory = useMediaDirectory();
|
|
|
|
|
const {t} = React.useContext(ThemeContext);
|
|
|
|
|
|
|
|
|
|
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:';
|
|
|
|
|
}
|
|
|
|
|
let indicating = status === 'pending';
|
|
|
|
|
|
|
|
|
|
return <Grid.Row key={name}>
|
|
|
|
|
<Grid.Column mobile={3} tablet={2} computer={1}>
|
|
|
|
|
<Icon name={mimetypeIconName(type, name.toLowerCase())} size='big'/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column mobile={13} tablet={14} computer={15}>
|
|
|
|
|
<Progress progress indicating={indicating} percent={percent} color={color}>
|
|
|
|
|
<p {...t}>{statusString} {name}</p>
|
|
|
|
|
</Progress>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const displayPath = destination ? `${mediaDirectory}/${destination}` : mediaDirectory;
|
|
|
|
|
|
|
|
|
|
return <Modal closeIcon open={open} onClose={handleClose} size='large'>
|
|
|
|
|
<Modal.Header>Upload to: {displayPath}</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<Form>
|
|
|
|
|
{tagsSelector}
|
|
|
|
|
<div style={{marginTop: '1em'}}>
|
|
|
|
|
<Toggle
|
|
|
|
|
checked={overwrite}
|
|
|
|
|
label='Overwrite existing files'
|
|
|
|
|
onChange={() => setOverwrite(!overwrite)}
|
|
|
|
|
disabled={inProgress}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
|
|
|
|
|
<Segment>
|
|
|
|
|
<Grid columns={1}>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column style={{padding: '1em'}}>
|
|
|
|
|
<Form>
|
|
|
|
|
<div {...getRootProps()}>
|
|
|
|
|
<input {...getInputProps()}/>
|
|
|
|
|
<Grid textAlign='center'>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Header icon>
|
|
|
|
|
<Icon name='file text'/>
|
|
|
|
|
Click here, or drop files here to upload
|
|
|
|
|
</Header>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Segment>
|
|
|
|
|
|
|
|
|
|
<Grid>
|
|
|
|
|
<Grid.Row columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
{progresses && Object.keys(progresses).length > 1 && <Progress progress
|
|
|
|
|
percent={overallProgress}
|
|
|
|
|
color='blue'
|
|
|
|
|
label='Overall Progress'
|
|
|
|
|
/>}
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid columns={2}>
|
|
|
|
|
{progressBars}
|
|
|
|
|
</Grid>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
disabled={inProgress}
|
|
|
|
|
>
|
|
|
|
|
Close
|
|
|
|
|
</Button>
|
|
|
|
|
</Modal.Actions>
|
|
|
|
|
</Modal>
|
|
|
|
|
}
|