update state

This commit is contained in:
smanylov
2025-12-26 20:17:41 +07:00
parent aa67d722c3
commit a3bcccdf28
+9 -9
View File
@@ -38,7 +38,6 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
const [uploadId, setUploadId] = useState<string | null>(null);
const [isFileUploaded, setIsFileUploaded] = useState<boolean>(false);
const [uploadProgress, setUploadProgress] = useState<number>(0);
const [isUploading, setIsUploading] = useState(false);
const t = useTranslations('Global');
let SUPPORTED_FORMATS: string[] = [];
@@ -152,7 +151,10 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
return;
}
setUploadProgress(0);
setUploadId(null);
setError(null);
setIsFileUploaded(false)
const validation = validateFile(file);
@@ -246,12 +248,11 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
};
const handlerFileUpload = useCallback(async (file: SelectedFile): Promise<void> => {
// Защита от повторного вызова
if (isUploading) return;
if (uploadId) {
return;
};
// Сбрасываем состояния
setError(null);
setIsUploading(true);
try {
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);
}
} finally {
setIsUploading(false);
setUploadId(null);
}
}, [isUploading, fileType]); // Добавьте зависимости
}, [uploadId, fileType]);
useEffect(() => {
// Обработка закрытия вкладки
@@ -480,12 +480,12 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{isFileUploaded ? t('close') : t('cancel')}
</button>
<button
className={`btn btn-confirm ${error || isFileUploaded ? 'disabled' : ''}`}
className={`btn btn-confirm ${error || isFileUploaded || uploadId ? 'disabled' : ''}`}
onClick={() => {
handlerFileUpload(selectedFile);
}}
type="button"
disabled={error || isFileUploaded || isUploading ? true : false}
disabled={error || isFileUploaded || uploadId ? true : false}
>
{t('upload-file')}
</button>