Skip to content

Commit

Permalink
added loading feature for file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteri committed Nov 23, 2024
1 parent 52ca217 commit 609f4a8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Modal, Button, Notification, FileInput } from '@mantine/core';
import { Modal, Button, Loader, Notification, FileInput } from '@mantine/core';
import '@/css/FileUpload.css';

interface FileUploadProps {
Expand All @@ -11,6 +11,7 @@ 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 +20,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 +62,7 @@ const FileUpload: React.FC<FileUploadProps> = ({ uploadUrl }) => {
} else {
setError('Please select files to upload.');
}
setLoading(false);
};

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

{loading && (
<Loader color="blue" />
)}
<br/>
<Button onClick={handleUpload} style={{ marginTop: 10 }}>Upload</Button>


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

0 comments on commit 609f4a8

Please sign in to comment.