Skip to content

Commit 92134df

Browse files
2
1 parent 145b802 commit 92134df

File tree

5 files changed

+61
-37
lines changed

5 files changed

+61
-37
lines changed

Local_Storage/notes_pdf/intel.pdf

985 KB
Binary file not shown.

client/src/components/Aibot.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
3+
const Aibot = () => {
4+
return (
5+
<div>
6+
7+
</div>
8+
)
9+
}
10+
11+
export default Aibot

client/src/components/Hero.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Hero() {
1010
<div className="mr-auto place-self-center lg:col-span-7">
1111
<h1 className="max-w-2xl mb-4 text-4xl font-extrabold tracking-tight leading-none md:text-5xl xl:text-6xl dark:text-white">Unlock Your Academic Potential with LearnMateAI</h1>
1212
<p className="max-w-2xl mb-6 font-light text-gray-500 lg:mb-8 md:text-lg lg:text-xl dark:text-gray-400">Personalized Learning for Smarter Results</p>
13-
<Link to='/upload'>
13+
<Link to='/uploadnotes'>
1414
<a href="#" className="inline-flex items-center justify-center px-5 py-3 mr-3 text-base font-medium text-center text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:focus:ring-primary-900">
1515
Upload Notes
1616
<svg className="w-5 h-5 ml-2 -mr-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fillRule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clipRule="evenodd"></path></svg>

client/src/components/Navbar.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ const Navbar = () => {
3737
About
3838
</Link>
3939
<Link
40-
to="/features"
40+
to="/aibot"
4141
className="hover:text-gray-900 px-3 py-2 rounded-md text-sm"
4242
>
43-
Features
43+
Tutor
4444
</Link>
4545
<Link
4646
to="/team"

client/src/components/UploadNotes.jsx

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22
import { motion } from 'framer-motion';
33
import Lotte from 'lottie-react';
44
import animationData from '../assets/95241-uploading.json';
5+
56
function UploadNotes() {
67
const [selectedFile, setSelectedFile] = useState(null);
78
const [uploading, setUploading] = useState(false);
@@ -11,55 +12,67 @@ function UploadNotes() {
1112
setSelectedFile(event.target.files[0]);
1213
};
1314

14-
const handleUpload = async () => {
15+
const handleUpload = () => {
1516
if (!selectedFile) {
1617
return;
1718
}
18-
19+
1920
setUploading(true);
20-
21-
// Generate a pre-signed URL for file upload
22-
const url = await getPresignedUrl(selectedFile.name, selectedFile.type);
23-
24-
try {
25-
// Use the generated URL to upload the file directly to S3
26-
await uploadFile(url, selectedFile);
27-
setUploadSuccess(true);
28-
} catch (error) {
29-
console.error('Error uploading file:', error);
30-
}
31-
32-
setUploading(false);
33-
};
34-
35-
// Function to generate a pre-signed URL for file upload
36-
const getPresignedUrl = async (filename, filetype) => {
37-
const response = await fetch(`/api/get-upload-url?filename=${filename}&filetype=${filetype}`);
38-
const data = await response.json();
39-
return data.url;
21+
22+
const reader = new FileReader();
23+
24+
reader.onload = () => {
25+
// Get the file contents
26+
const fileContents = reader.result;
27+
28+
// Create a Blob from the file contents
29+
const blob = new Blob([fileContents], { type: selectedFile.type });
30+
31+
// Create a file path within the Local_Storage/notes_pdf folder
32+
const filePath = `Local_Storage/notes_pdf/${selectedFile.name}`;
33+
34+
// Save the file locally
35+
saveFileLocally(filePath, blob)
36+
.then(() => {
37+
setUploadSuccess(true);
38+
setUploading(false);
39+
})
40+
.catch((error) => {
41+
console.error('Error saving file:', error);
42+
});
43+
};
44+
45+
reader.readAsArrayBuffer(selectedFile);
4046
};
41-
42-
// Function to upload the file to the generated URL
43-
const uploadFile = async (url, file) => {
44-
await fetch(url, {
45-
method: 'PUT',
46-
body: file,
47-
headers: {
48-
'Content-Type': file.type,
49-
},
47+
48+
const saveFileLocally = (filePath, file) => {
49+
return new Promise((resolve, reject) => {
50+
const virtualLink = document.createElement('a');
51+
virtualLink.href = URL.createObjectURL(file);
52+
virtualLink.download = filePath;
53+
virtualLink.addEventListener('load', () => {
54+
URL.revokeObjectURL(virtualLink.href);
55+
resolve();
56+
});
57+
virtualLink.addEventListener('error', (error) => {
58+
reject(error);
59+
});
60+
document.body.appendChild(virtualLink);
61+
virtualLink.click();
62+
document.body.removeChild(virtualLink);
5063
});
5164
};
65+
5266

5367
return (
5468
<div className="flex flex-col items-center justify-center h-screen text-center">
55-
5669
<motion.div
5770
className="bg-blue-500 text-white py-6 px-6 rounded-lg shadow-lg"
5871
initial={{ scale: 0 }}
5972
animate={{ scale: 1 }}
6073
transition={{ duration: 0.5 }}
6174
>
62-
<Lotte animationData={animationData} style={{width: 400, height: 300}}/>
75+
<Lotte animationData={animationData} style={{ width: 400, height: 300 }} />
6376
<h1 className="text-3xl font-bold mb-4">Upload Notes</h1>
6477
{!uploadSuccess ? (
6578
<>
@@ -96,4 +109,4 @@ function UploadNotes() {
96109
);
97110
}
98111

99-
export default UploadNotes;
112+
export default UploadNotes;

0 commit comments

Comments
 (0)