mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fix warnings, correctly show abort text when cancelling
This commit is contained in:
@@ -12,7 +12,12 @@ import { useI18nContext } from 'i18n/i18n-react';
|
|||||||
import DragNdrop from './DragNdrop';
|
import DragNdrop from './DragNdrop';
|
||||||
import { LinearProgressWithLabel } from './LinearProgressWithLabel';
|
import { LinearProgressWithLabel } from './LinearProgressWithLabel';
|
||||||
|
|
||||||
const SingleUpload = ({ text, doRestart }) => {
|
interface SingleUploadProps {
|
||||||
|
text: string;
|
||||||
|
doRestart: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SingleUpload = ({ text, doRestart }: SingleUploadProps) => {
|
||||||
const [md5, setMd5] = useState<string>();
|
const [md5, setMd5] = useState<string>();
|
||||||
const [file, setFile] = useState<File>();
|
const [file, setFile] = useState<File>();
|
||||||
const { LL } = useI18nContext();
|
const { LL } = useI18nContext();
|
||||||
@@ -25,8 +30,8 @@ const SingleUpload = ({ text, doRestart }) => {
|
|||||||
} = useRequest(SystemApi.uploadFile, {
|
} = useRequest(SystemApi.uploadFile, {
|
||||||
immediate: false
|
immediate: false
|
||||||
}).onSuccess(({ data }) => {
|
}).onSuccess(({ data }) => {
|
||||||
if (data) {
|
if (data && typeof data === 'object' && 'md5' in data) {
|
||||||
setMd5(data.md5 as string);
|
setMd5((data as { md5: string }).md5);
|
||||||
toast.success(LL.UPLOAD() + ' MD5 ' + LL.SUCCESSFUL());
|
toast.success(LL.UPLOAD() + ' MD5 ' + LL.SUCCESSFUL());
|
||||||
setFile(undefined);
|
setFile(undefined);
|
||||||
} else {
|
} else {
|
||||||
@@ -34,16 +39,19 @@ const SingleUpload = ({ text, doRestart }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(async () => {
|
useEffect(() => {
|
||||||
|
const uploadFile = async () => {
|
||||||
if (file) {
|
if (file) {
|
||||||
await sendUpload(file).catch((error: Error) => {
|
await sendUpload(file).catch((error: Error) => {
|
||||||
if (error.message === 'The user aborted a request') {
|
if (error.message.includes('The user aborted a request')) {
|
||||||
toast.warning(LL.UPLOAD() + ' ' + LL.ABORTED());
|
toast.warning(LL.UPLOAD() + ' ' + LL.ABORTED());
|
||||||
} else {
|
} else {
|
||||||
toast.warning('Invalid file extension or incompatible bin file');
|
toast.warning('Invalid file extension or incompatible bin file');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
uploadFile();
|
||||||
}, [file]);
|
}, [file]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user