ente/src/pages/gallery/components/CollectionDropZone.tsx

90 lines
2.3 KiB
TypeScript
Raw Normal View History

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';
import { fetchData } from 'services/fileService';
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';
}
};
const enableBorder = (props) => (props.isDragActive ? 'dashed' : 'none');
2021-01-19 04:57:21 +00:00
export const DropDiv = styled.div`
width:200px;
margin:5px;
height:230px;
2021-01-14 14:07:26 +00:00
color:black;
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;
`;
const CollectionDropZone = ({
2021-01-08 03:52:51 +00:00
children,
closeModal,
setData,
showModal,
2021-01-08 03:52:51 +00:00
collectionLatestFile,
noDragEventsBubbling,
2021-01-12 06:59:37 +00:00
setProgressView,
token,
encryptionKey,
2021-01-12 06:59:37 +00:00
progressBarProps
}) => {
2021-01-08 03:52:51 +00:00
const upload = async (acceptedFiles) => {
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);
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
onDropAccepted={upload}
onDragOver={showModal}
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>
);
};
export default CollectionDropZone;