Skip to content

Commit 9154d4f

Browse files
upload prt
1 parent 92134df commit 9154d4f

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Local_Storage/notes_pdf/intel.pdf

-985 KB
Binary file not shown.

client/src/components/Upload.jsx

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

client/src/components/UploadNotes.jsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import { motion } from 'framer-motion';
3-
import Lotte from 'lottie-react';
3+
import Lottie from 'lottie-react';
44
import animationData from '../assets/95241-uploading.json';
55

66
function UploadNotes() {
@@ -10,41 +10,44 @@ function UploadNotes() {
1010

1111
const handleFileChange = (event) => {
1212
setSelectedFile(event.target.files[0]);
13+
setUploadSuccess(false); // Reset upload success status when a new file is selected
1314
};
1415

1516
const handleUpload = () => {
1617
if (!selectedFile) {
1718
return;
1819
}
19-
20+
2021
setUploading(true);
21-
22+
2223
const reader = new FileReader();
23-
24+
2425
reader.onload = () => {
2526
// Get the file contents
2627
const fileContents = reader.result;
27-
28+
2829
// Create a Blob from the file contents
2930
const blob = new Blob([fileContents], { type: selectedFile.type });
30-
31+
3132
// Create a file path within the Local_Storage/notes_pdf folder
3233
const filePath = `Local_Storage/notes_pdf/${selectedFile.name}`;
33-
34+
3435
// Save the file locally
3536
saveFileLocally(filePath, blob)
3637
.then(() => {
3738
setUploadSuccess(true);
38-
setUploading(false);
3939
})
4040
.catch((error) => {
4141
console.error('Error saving file:', error);
42+
})
43+
.finally(() => {
44+
setUploading(false);
4245
});
4346
};
44-
47+
4548
reader.readAsArrayBuffer(selectedFile);
4649
};
47-
50+
4851
const saveFileLocally = (filePath, file) => {
4952
return new Promise((resolve, reject) => {
5053
const virtualLink = document.createElement('a');
@@ -62,7 +65,6 @@ function UploadNotes() {
6265
document.body.removeChild(virtualLink);
6366
});
6467
};
65-
6668

6769
return (
6870
<div className="flex flex-col items-center justify-center h-screen text-center">
@@ -72,7 +74,7 @@ function UploadNotes() {
7274
animate={{ scale: 1 }}
7375
transition={{ duration: 0.5 }}
7476
>
75-
<Lotte animationData={animationData} style={{ width: 400, height: 300 }} />
77+
<Lottie animationData={animationData} style={{ width: 400, height: 300 }} />
7678
<h1 className="text-3xl font-bold mb-4">Upload Notes</h1>
7779
{!uploadSuccess ? (
7880
<>
@@ -91,15 +93,14 @@ function UploadNotes() {
9193
whileHover={!uploading ? { scale: 1.05 } : {}}
9294
whileTap={!uploading ? { scale: 0.95 } : {}}
9395
>
94-
{uploading ? 'Uploading...' : 'Upload'}
96+
{uploading ? 'Uploaded' : 'Upload'}
9597
</motion.button>
9698
</>
9799
) : (
98100
<motion.div
99101
className="text-xl"
100102
initial={{ opacity: 0 }}
101103
animate={{ opacity: 1 }}
102-
transition={{ duration: 0.5 }}
103104
>
104105
Upload successful!
105106
</motion.div>

0 commit comments

Comments
 (0)