ente/src/pages/gallery/components/CollectionSelector.tsx
2021-01-12 12:29:37 +05:30

67 lines
2.3 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { Button, Card, Modal } from 'react-bootstrap';
import { getActualKey } from 'utils/common/key';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import CollectionDropZone from './CollectionDropZone';
import PreviewCard from './PreviewCard';
function CollectionSelector({
uploadModalView,
closeUploadModal,
collectionLatestFile,
setProgressView,
setData,
progressBarProps,
}) {
const [token, setToken] = useState(null);
const [encryptionKey, setEncryptionKey] = useState(null);
useEffect(() => {
(async () => {
setToken(getData(LS_KEYS.USER).token);
setEncryptionKey(await getActualKey());
})();
});
const CollectionIcons = collectionLatestFile?.map((item) => (
<CollectionDropZone key={item.collectionID}
closeModal={closeUploadModal}
collectionLatestFile={item}
noDragEventsBubbling
setProgressView={setProgressView}
token={token}
encryptionKey={encryptionKey}
setData={setData}
progressBarProps={progressBarProps}
>
<Card style={{ cursor: 'pointer', border: 'solid', width: "95%", marginBottom: "5px", padding: "auto" }}>
<PreviewCard data={item.file} updateUrl={() => { }} onClick={() => { }} />
<Card.Body>
<Card.Text>{item.collection.name}</Card.Text>
</Card.Body>
</Card>
</CollectionDropZone>
));
return (
<Modal
show={uploadModalView}
aria-labelledby='contained-modal-title-vcenter'
centered
onHide={closeUploadModal}
>
<Modal.Header closeButton>
<Modal.Title id='contained-modal-title-vcenter'>
Select/Click on Collection to upload
</Modal.Title>
</Modal.Header>
<Modal.Body style={{ display: "flex", justifyContent: "space-between", flexWrap: "wrap" }}>
{CollectionIcons}
</Modal.Body>
<Modal.Footer>
<Button onClick={closeUploadModal}>Close</Button>
</Modal.Footer>
</Modal>
);
}
export default CollectionSelector;