2021-01-05 02:30:43 +00:00
|
|
|
import React from 'react';
|
|
|
|
import Dropzone from 'react-dropzone';
|
|
|
|
import styled from 'styled-components';
|
2021-01-08 03:52:51 +00:00
|
|
|
import UploadService from 'services/uploadService';
|
2021-01-11 08:17:19 +00:00
|
|
|
import { fetchData } from 'services/fileService';
|
2021-01-05 02:30:43 +00:00
|
|
|
|
|
|
|
const getColor = (props) => {
|
2021-01-08 03:52:51 +00:00
|
|
|
if (props.isDragAccept) {
|
|
|
|
return '#00e676';
|
|
|
|
}
|
|
|
|
if (props.isDragReject) {
|
|
|
|
return '#ff1744';
|
|
|
|
}
|
|
|
|
if (props.isDragActive) {
|
|
|
|
return '#2196f3';
|
|
|
|
}
|
2021-01-05 02:30:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const enableBorder = (props) => (props.isDragActive ? 'dashed' : 'none');
|
|
|
|
|
|
|
|
const DropDiv = styled.div`
|
2021-01-06 17:54:06 +00:00
|
|
|
width:33%;
|
2021-01-05 02:30:43 +00:00
|
|
|
border-width: 2px;
|
|
|
|
border-radius: 2px;
|
|
|
|
border-color: ${(props) => getColor(props)};
|
|
|
|
border-style: ${(props) => enableBorder(props)};
|
|
|
|
outline: none;
|
|
|
|
transition: border 0.24s ease-in-out;
|
|
|
|
`;
|
|
|
|
|
2021-01-06 07:17:56 +00:00
|
|
|
const CollectionDropZone = ({
|
2021-01-08 03:52:51 +00:00
|
|
|
children,
|
|
|
|
closeModal,
|
2021-01-11 08:17:19 +00:00
|
|
|
setData,
|
2021-01-19 04:20:47 +00:00
|
|
|
showModal,
|
2021-01-08 03:52:51 +00:00
|
|
|
collectionLatestFile,
|
|
|
|
noDragEventsBubbling,
|
2021-01-12 06:59:37 +00:00
|
|
|
setProgressView,
|
2021-01-11 08:17:19 +00:00
|
|
|
token,
|
|
|
|
encryptionKey,
|
2021-01-12 06:59:37 +00:00
|
|
|
progressBarProps
|
2021-01-11 08:17:19 +00:00
|
|
|
|
2021-01-05 05:25:58 +00:00
|
|
|
}) => {
|
2021-01-08 03:52:51 +00:00
|
|
|
|
|
|
|
const upload = async (acceptedFiles) => {
|
2021-01-08 03:08:50 +00:00
|
|
|
closeModal();
|
2021-01-12 08:00:40 +00:00
|
|
|
progressBarProps.setPercentComplete(0);
|
2021-01-12 06:59:37 +00:00
|
|
|
setProgressView(true);
|
2021-01-12 08:00:40 +00:00
|
|
|
|
2021-01-12 06:59:37 +00:00
|
|
|
await UploadService.uploadFiles(acceptedFiles, collectionLatestFile, token, progressBarProps);
|
2021-01-11 09:15:41 +00:00
|
|
|
setData(await fetchData(token, encryptionKey, [collectionLatestFile.collection]));
|
2021-01-12 08:00:40 +00:00
|
|
|
setProgressView(false);
|
2021-01-08 03:52:51 +00:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Dropzone
|
2021-01-08 13:11:48 +00:00
|
|
|
onDropAccepted={upload}
|
2021-01-19 04:20:47 +00:00
|
|
|
onDragOver={showModal}
|
2021-01-08 13:11:48 +00:00
|
|
|
onDropRejected={closeModal}
|
2021-01-08 03:52:51 +00:00
|
|
|
noDragEventsBubbling={noDragEventsBubbling}
|
2021-01-12 13:43:41 +00:00
|
|
|
accept="image/*, video/*, application/json "
|
2021-01-08 03:52:51 +00:00
|
|
|
>
|
|
|
|
{({
|
|
|
|
getRootProps,
|
|
|
|
getInputProps,
|
|
|
|
isDragActive,
|
|
|
|
isDragAccept,
|
|
|
|
isDragReject,
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<DropDiv
|
|
|
|
{...getRootProps({
|
|
|
|
isDragActive,
|
|
|
|
isDragAccept,
|
|
|
|
isDragReject,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
{children}
|
|
|
|
</DropDiv>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Dropzone>
|
|
|
|
);
|
2021-01-05 02:30:43 +00:00
|
|
|
};
|
|
|
|
|
2021-01-06 07:17:56 +00:00
|
|
|
export default CollectionDropZone;
|