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 |
import React, { useState } from "react"; import useDrivePicker from "react-google-drive-picker"; function App() { const [openPicker, setOpenPicker] = useDrivePicker(); const [selectedFiles, setSelectedFiles] = useState([]); const handleOpenPicker = () => { openPicker({ clientId:"", developerKey:"", viewId: "DOCS", showUploadView: true, showUploadFolders: true, supportDrives: true, multiselect: true, callbackFunction: (data) => { if (data.action === "cancel") { console.log("User clicked cancel/close button"); } else if (data.docs) { console.log(data); setSelectedFiles(data.docs); // Store all file details } }, }); }; return ( <div style={{ padding: "20px", textAlign: "center" }}> <button onClick={handleOpenPicker} style={{ marginBottom: "20px" }}> Open Picker </button> <div style={{ display: "flex", flexWrap: "wrap", gap: "20px", justifyContent: "center", }} > {selectedFiles.map((file, index) => ( <div key={index} style={{ border: "1px solid #ccc", padding: "10px", width: "200px", textAlign: "left", }} > <h4 style={{ fontSize: "14px", marginBottom: "10px" }}> {file.name} </h4> <p style={{ fontSize: "12px", marginBottom: "10px" }}> <strong>Type:</strong> {file.mimeType} </p> <a href={file.url} target="_blank" rel="noopener noreferrer"> Open File </a> </div> ))} </div> </div> ); } export default App; |