Skip to content

Commit

Permalink
Merge pull request #64 from hytech-racing/loading
Browse files Browse the repository at this point in the history
added loading feature for file upload
  • Loading branch information
aesteri authored Nov 23, 2024
2 parents 52ca217 + 4cb70c5 commit 0642b98
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
const [error, setError] = useState<string | null>(null);
const [success, setSuccess] = useState<string | null>(null);
const [loading, setLoading] = useState(false);


const handleFileChange = (files: File[]) => {
if (files.length > 0) {
Expand All @@ -19,6 +21,7 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
};

const handleUpload = async () => {
setLoading(true);
setError(null);
setSuccess(null)
if (selectedFiles.length > 0) {
Expand Down Expand Up @@ -60,6 +63,7 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
} else {
setError('Please select files to upload.');
}
setLoading(false);
};

const toggleModal = () => {
Expand Down Expand Up @@ -104,8 +108,9 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
</div>
)}
</div>

<Button onClick={handleUpload} style={{ marginTop: 10 }}>Upload</Button>

<Button loading={loading} loaderProps={{ type: 'dots' }} onClick={handleUpload} style={{ marginTop: 10 }} disabled={loading}>Upload</Button>

{success && (
<Notification color="green" onClose={() => setSuccess(null)} style={{ marginTop: 10 }}>
{success}
Expand Down

0 comments on commit 0642b98

Please sign in to comment.