diff --git a/safeshare/safeshare-frontend/src/pages/downloadFile.js b/safeshare/safeshare-frontend/src/pages/downloadFile.js index 6cb5377..1c706d0 100644 --- a/safeshare/safeshare-frontend/src/pages/downloadFile.js +++ b/safeshare/safeshare-frontend/src/pages/downloadFile.js @@ -27,8 +27,7 @@ function DownloadFile() { // Create a dynamically generated anchor element const a = document.createElement('a'); a.href = url; - // TODO: Set the file name below - a.download = response.data.name; + a.download = response.data.filename; // Trigger a click event on the anchor element to simulate a download a.click(); diff --git a/safeshare/safeshare-frontend/src/pages/shareFile.js b/safeshare/safeshare-frontend/src/pages/shareFile.js index 905ed0e..a18f5d1 100644 --- a/safeshare/safeshare-frontend/src/pages/shareFile.js +++ b/safeshare/safeshare-frontend/src/pages/shareFile.js @@ -6,6 +6,8 @@ import { Link } from 'react-router-dom'; function ShareFile() { const [file, setFile] = useState(null); const [passcode, setPasscode] = useState(''); + const [shareableLink, setShareableLink] = useState(''); + const [notification, setNotification] = useState(''); const handleFileUpload = (file) => { setFile(file); @@ -17,42 +19,41 @@ function ShareFile() { //formData.append('ttl', "60"); // Send POST request to the backend API using Axios - axios.post('http://127.0.0.1:8000/api/files/', formData) - .then(response => { + axios + .post('http://127.0.0.1:8000/api/files/', formData) + .then((response) => { // Handle a successful response from the server, set passcode to "key" in the response body const data = response.data; // If data is an array, take the first item if (Array.isArray(data)) { - setPasscode(data[0].key); + const passcode = data[0].key; + setPasscode(passcode); + // Copy the passcode to the clipboard + navigator.clipboard.writeText(passcode).then(() => { + // Show a notification + showNotification('Copied to clipboard!'); + }); } }) - .catch(error => { + .catch((error) => { // Handle errors here console.error('File upload failed', error); }); + const baseUrl = 'http://localhost:3000/download/'; + setShareableLink(baseUrl); } }; - // return ( - //