update state
This commit is contained in:
@@ -38,7 +38,6 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
|||||||
const [uploadId, setUploadId] = useState<string | null>(null);
|
const [uploadId, setUploadId] = useState<string | null>(null);
|
||||||
const [isFileUploaded, setIsFileUploaded] = useState<boolean>(false);
|
const [isFileUploaded, setIsFileUploaded] = useState<boolean>(false);
|
||||||
const [uploadProgress, setUploadProgress] = useState<number>(0);
|
const [uploadProgress, setUploadProgress] = useState<number>(0);
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
|
||||||
|
|
||||||
const t = useTranslations('Global');
|
const t = useTranslations('Global');
|
||||||
let SUPPORTED_FORMATS: string[] = [];
|
let SUPPORTED_FORMATS: string[] = [];
|
||||||
@@ -152,7 +151,10 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setUploadProgress(0);
|
setUploadProgress(0);
|
||||||
|
|
||||||
|
setUploadId(null);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
setIsFileUploaded(false)
|
||||||
|
|
||||||
const validation = validateFile(file);
|
const validation = validateFile(file);
|
||||||
|
|
||||||
@@ -246,12 +248,11 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handlerFileUpload = useCallback(async (file: SelectedFile): Promise<void> => {
|
const handlerFileUpload = useCallback(async (file: SelectedFile): Promise<void> => {
|
||||||
// Защита от повторного вызова
|
if (uploadId) {
|
||||||
if (isUploading) return;
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
// Сбрасываем состояния
|
|
||||||
setError(null);
|
setError(null);
|
||||||
setIsUploading(true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const extension = file.name.split('.').pop();
|
const extension = file.name.split('.').pop();
|
||||||
@@ -327,10 +328,9 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
|||||||
if (error.cause) console.error('Error cause:', error.cause);
|
if (error.cause) console.error('Error cause:', error.cause);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsUploading(false);
|
|
||||||
setUploadId(null);
|
setUploadId(null);
|
||||||
}
|
}
|
||||||
}, [isUploading, fileType]); // Добавьте зависимости
|
}, [uploadId, fileType]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Обработка закрытия вкладки
|
// Обработка закрытия вкладки
|
||||||
@@ -480,12 +480,12 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
|||||||
{isFileUploaded ? t('close') : t('cancel')}
|
{isFileUploaded ? t('close') : t('cancel')}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`btn btn-confirm ${error || isFileUploaded ? 'disabled' : ''}`}
|
className={`btn btn-confirm ${error || isFileUploaded || uploadId ? 'disabled' : ''}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlerFileUpload(selectedFile);
|
handlerFileUpload(selectedFile);
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={error || isFileUploaded || isUploading ? true : false}
|
disabled={error || isFileUploaded || uploadId ? true : false}
|
||||||
>
|
>
|
||||||
{t('upload-file')}
|
{t('upload-file')}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user