App.jsx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import React, { useState } from "react"; import DropboxChooser from "react-dropbox-chooser"; import { Container, Row, Col, Card, Button } from "react-bootstrap"; import "bootstrap/dist/css/bootstrap.min.css"; const DROPBOX_APP_KEY = ""; function App() { const [files, setFiles] = useState([]); const onSuccess = (selectedFiles) => { setFiles(selectedFiles); }; const onCancel = () => { console.log("User canceled the operation."); }; const handleDownload = (link, name) => { const anchor = document.createElement("a"); anchor.href = link; anchor.download = name; anchor.click(); }; return ( <div> <h1 className="text-center my-4">Dropbox File Selector</h1> <div className="text-center"> <DropboxChooser appKey={DROPBOX_APP_KEY} success={onSuccess} cancel={onCancel} multiselect={true} > <Button variant="primary">Select Files</Button> </DropboxChooser> </div> <Container className="my-5"> <Row> {files.map((file, index) => ( <Col key={index} md={4} className="mb-4"> <Card> {/* Preview Section */} {file.link && ( <Card.Img variant="top" src={ file.thumbnailLink || file.link } /* Use thumbnail if available */ alt={file.name} style={{ height: "200px", objectFit: "cover", borderBottom: "1px solid #ddd", }} /> )} <Card.Body> <Card.Title>{file.name}</Card.Title> <Card.Text> <strong>Size:</strong> {(file.bytes / 1024).toFixed(2)} KB </Card.Text> <Button variant="success" onClick={() => handleDownload(file.link, file.name)} > Download </Button> </Card.Body> </Card> </Col> ))} </Row> </Container> </div> ); } export default App; |