mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 12:56:24 -05:00
ui: two upload dialogs that had drifted apart (#664)
* ui: two upload dialogs that had drifted apart The dashboard and the file browser each had their own upload component: two dropzones, two overwrite toggles, two copies of the progress-bar rendering, against the same `useUploadFile` state. The file browser's dialog was made fullscreen with a drop target that grows; the dashboard's stayed a `large` dialog with a strip to drop onto, because it was a different file. They differ in one thing that is real: the file browser knows the destination because the user selected it, and the dashboard has to ask. That is now the `destination` prop -- `undefined` asks, a string uploads there, and '' is the media directory rather than a missing destination. Everything else is one component, so the next change to either entry point lands on both. * review: an upload dialog that looped on the media directory Pressing Upload in the file browser with nothing selected passes `''` -- the media directory. Three checks along that path read it as "no destination": * The clearing effect ran, and `doClear` is a new function every render whose own setState scheduled the next one. React ended it with "Maximum update depth exceeded", 16 warnings deep, on the default Upload path. The effect now clears only while asking, and `doClear` is stable. * The title read `Upload to: /media/wrolpi/`. * `doUpload` bailed, so a drop on the media root uploaded nothing. All three predate this branch; moving the dialog is what put them behind one component. Tests cover the title, what the hook is told, and that a fixed destination is never the thing that empties the queue.
This commit is contained in:
parent
82fdf9dd92
commit
4c71e84696
5 changed files with 238 additions and 214 deletions
|
|
@ -7,11 +7,8 @@ import {
|
|||
IconButton,
|
||||
IconStack,
|
||||
Modal,
|
||||
Panel,
|
||||
Placeholder,
|
||||
Progress,
|
||||
Skeleton,
|
||||
Stack,
|
||||
Table,
|
||||
TextInput,
|
||||
} from "./ui";
|
||||
|
|
@ -21,24 +18,22 @@ import {
|
|||
ErrorMessage,
|
||||
FileIcon,
|
||||
humanFileSize,
|
||||
mimetypeIconName,
|
||||
Toggle,
|
||||
useIsIgnoredDirectory
|
||||
} from "./Common";
|
||||
import React, {useContext, useEffect, useState} from "react";
|
||||
import {IconArrowsMove, IconChevronsUp, IconCursorText, IconTags} from "@tabler/icons-react";
|
||||
import {useDropzone} from "react-dropzone";
|
||||
import {useHotkeys} from "react-hotkeys-hook";
|
||||
import {deleteFile, ignoreDirectory, makeDirectory, movePaths, renamePath, unignoreDirectory} from "../api";
|
||||
import _ from 'lodash';
|
||||
import {SortableTable} from "./SortableTable";
|
||||
import {useBrowseFiles, useElementWidth, useMediaDirectory, useUploadFile, useWROLMode} from "../hooks/customHooks";
|
||||
import {useBrowseFiles, useElementWidth, useMediaDirectory, useWROLMode} from "../hooks/customHooks";
|
||||
import {FileRowTagIcon, FilesRefreshButton} from "./Files";
|
||||
import {FilePreviewContext} from "./FilePreview";
|
||||
import {DragSelectionContext, DragSelectionProvider, SettingsContext, ThemeContext} from "../contexts/contexts";
|
||||
import {BulkTagModal} from "./BulkTagModal";
|
||||
import {InlineErrorBoundary} from "./ErrorBoundary";
|
||||
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
||||
import {UploadModal} from "./Upload";
|
||||
|
||||
function depthIndentation(path) {
|
||||
// Repeated spaces for every folder a path is in.
|
||||
|
|
@ -456,7 +451,7 @@ export function FileBrowser() {
|
|||
disabled={wrolModeEnabled || (selectedPathsCount > 0 && !singleDirectorySelected)}
|
||||
onClick={() => setUploadOpen(true)}
|
||||
>{label('Upload')}</Button>
|
||||
<FileBrowserUploadModal
|
||||
<UploadModal
|
||||
open={uploadOpen}
|
||||
onClose={() => setUploadOpen(false)}
|
||||
destination={singleDirectorySelected && selectedPaths[0] ? selectedPaths[0].slice(0, -1) : ''}
|
||||
|
|
@ -847,146 +842,3 @@ export function MakeDirectoryModal({open, onClose, parent, onSubmit}) {
|
|||
</Modal.Actions>
|
||||
</Modal>
|
||||
}
|
||||
|
||||
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 <div key={name} style={{display: 'flex', alignItems: 'center', gap: '0.75em'}}>
|
||||
<Icon name={mimetypeIconName(type, name.toLowerCase())} size='large'/>
|
||||
<div style={{flex: 1}}>
|
||||
<Progress percent={percent} color={color} label={`${statusString} ${name}`}/>
|
||||
</div>
|
||||
</div>
|
||||
})
|
||||
}
|
||||
|
||||
const displayPath = destination ? `${mediaDirectory}/${destination}` : mediaDirectory;
|
||||
|
||||
/*
|
||||
* Fullscreen, for the drop target. At 620px the target was a strip about 90px tall in a
|
||||
* dialog covering a fifth of the screen -- a small thing to drag a file onto, and the
|
||||
* page behind it was the file browser it came from. Given the room, the target takes it.
|
||||
*/
|
||||
return <Modal open={open} onClose={handleClose} fullScreen>
|
||||
<Modal.Header>Upload to: {displayPath}</Modal.Header>
|
||||
<Modal.Content>
|
||||
<form onSubmit={e => e.preventDefault()}>
|
||||
{tagsSelector}
|
||||
<div style={{marginTop: '1em'}}>
|
||||
<Toggle
|
||||
checked={overwrite}
|
||||
label='Overwrite existing files'
|
||||
onChange={() => setOverwrite(!overwrite)}
|
||||
disabled={inProgress}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{/* The target takes the room the dialog gives it rather than sitting as a strip
|
||||
at the top of it. `min-height` as well as `flex`, so it stays a large target
|
||||
once the progress bars below it start claiming their own space. */}
|
||||
<Panel style={{
|
||||
marginTop: '1em',
|
||||
padding: '1em',
|
||||
flex: '1 1 auto',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}}>
|
||||
<div {...getRootProps()}
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
textAlign: 'center',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flex: '1 1 auto',
|
||||
minHeight: '30vh',
|
||||
}}>
|
||||
<input {...getInputProps()}/>
|
||||
<Header as='h4' icon='file text'>Click here, or drop files here to upload</Header>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
{progresses && Object.keys(progresses).length > 1 &&
|
||||
<div style={{marginTop: '1em'}}>
|
||||
<Progress percent={overallProgress} color='blue' label='Overall Progress'/>
|
||||
</div>}
|
||||
|
||||
<Stack gap={8} style={{marginTop: '1em'}}>
|
||||
{progressBars}
|
||||
</Stack>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button
|
||||
role='cancel'
|
||||
onClick={handleClose}
|
||||
disabled={inProgress}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue