import { FC, Fragment } from 'react'; import { useDropzone, DropzoneState } from 'react-dropzone'; import { AxiosProgressEvent } from 'axios'; import { Box, Button, LinearProgress, Theme, Typography, useTheme } from '@mui/material'; import CloudUploadIcon from '@mui/icons-material/CloudUpload'; import CancelIcon from '@mui/icons-material/Cancel'; import { useI18nContext } from '../../i18n/i18n-react'; const getBorderColor = (theme: Theme, props: DropzoneState) => { if (props.isDragAccept) { return theme.palette.success.main; } if (props.isDragReject) { return theme.palette.error.main; } if (props.isDragActive) { return theme.palette.info.main; } return theme.palette.grey[700]; }; export interface SingleUploadProps { onDrop: (acceptedFiles: File[]) => void; onCancel: () => void; uploading: boolean; progress?: AxiosProgressEvent; } const SingleUpload: FC = ({ onDrop, onCancel, uploading, progress }) => { const dropzoneState = useDropzone({ onDrop, accept: { 'application/octet-stream': ['.bin'], 'application/json': ['.json'] }, disabled: uploading, multiple: false }); const { getRootProps, getInputProps } = dropzoneState; const theme = useTheme(); const { LL } = useI18nContext(); const progressText = () => { if (uploading) { if (progress?.total) { return LL.UPLOADING() + ': ' + Math.round((progress.loaded * 100) / progress.total) + '%'; } return LL.UPLOADING() + `\u2026`; } return LL.UPLOAD_DROP_TEXT(); }; return ( {progressText()} {uploading && ( )} ); }; export default SingleUpload;