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

81 lines
2 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');
const DropDiv = styled.div`
2021-01-06 17:54:06 +00:00
width:33%;
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,
2021-01-08 03:52:51 +00:00
collectionLatestFile,
noDragEventsBubbling,
showProgress,
token,
encryptionKey,
}) => {
2021-01-08 03:52:51 +00:00
const upload = async (acceptedFiles) => {
closeModal();
showProgress();
2021-01-08 07:46:57 +00:00
await UploadService.uploadFiles(acceptedFiles, collectionLatestFile, token);
setData(fetchData(token, encryptionKey, collectionLatestFile.Collection));
2021-01-08 03:52:51 +00:00
}
return (
<Dropzone
onDropAccepted={upload}
onDropRejected={closeModal}
2021-01-08 03:52:51 +00:00
noDragEventsBubbling={noDragEventsBubbling}
accept="image/*, video/* "
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;