import React from "react"; import {useDropzone} from "react-dropzone"; import {Form, Header, Icon, Progress, Segment} from "./Theme"; import {DirectorySearch, mimetypeIconName} from "./Common"; import {useUploadFile} from "../hooks/customHooks"; import _ from "lodash"; import {ThemeContext} from "../contexts/contexts"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import {Form as SForm} from "semantic-ui-react"; export function Upload({disabled}) { const {t} = React.useContext(ThemeContext); const {setFiles, progresses, destination, setDestination, doClear, tagsSelector} = useUploadFile(); const onDrop = React.useCallback(async (acceptedFiles) => { if (acceptedFiles && acceptedFiles.length > 0) { setFiles(acceptedFiles); } }, [destination]); const {getRootProps, getInputProps} = useDropzone({onDrop}); React.useEffect(() => { if (!destination) { // Destination was cleared, clear progresses. doClear(); } }, [destination]); 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:'; } // Only indicating when upload is pending. let indicating = status === 'pending'; return

{statusString} {name}

}) } return <>
setDestination(i)} disabled={disabled} style={{marginBottom: '0.5em'}} /> {tagsSelector}
{destination ?
{ }}>
Click here, or drop files here to upload
:
You must search for a directory to place your files
}
{progressBars} }