diff --git a/src/app/components/upload-section-file.tsx b/src/app/components/upload-section-file.tsx index dd2ca38..3918634 100644 --- a/src/app/components/upload-section-file.tsx +++ b/src/app/components/upload-section-file.tsx @@ -74,6 +74,11 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile return { isValid: true }; }; + function setErrorHandler(message: string | null): void { + setError(message); + setUploadProgress(0); + } + const getImageDimensions = (file: File): Promise<{ width: number; height: number }> => { return new Promise((resolve, reject) => { const img = new Image(); @@ -120,11 +125,11 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile dimensions = await getImageDimensions(file) as { width: number, height: number }; if (dimensions.width < 100 || dimensions.height < 100 || dimensions.width > 10000 || dimensions.height > 10000) { - setError(`${t('image-size')}: ${dimensions.width}x${dimensions.height}. ${t('acceptable-range')}: 100x100 - 10000x10000 ${t('pixels')}.`); + setErrorHandler(`${t('image-size')}: ${dimensions.width}x${dimensions.height}. ${t('acceptable-range')}: 100x100 - 10000x10000 ${t('pixels')}.`); return; } } catch (err) { - setError(t('error-reading-image')); + setErrorHandler(t('error-reading-image')); return; } } @@ -255,10 +260,9 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile } catch (error) { if (!isCancelledRef.current) { if (error === 'duplicate-file') { - setError(t('error-duplicate-file')); + setErrorHandler(t('error-duplicate-file')); } else { - setError(t('error-uploading-file')); - console.error('Upload error:', error); + setErrorHandler(t('error-uploading-file')); } } } finally { @@ -347,6 +351,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile className="btn btn-primary" onClick={handleButtonClick} type="button" + disabled={uploadProgress && uploadProgress !== 100 ? true : false} > {t('select-files-to-protect')} @@ -394,7 +399,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile src={selectedFile.preview} alt="Предпросмотр загруженного изображения" className="uploaded-image" - onError={() => setError('Не удалось загрузить превью изображения')} + onError={() => setErrorHandler('Не удалось загрузить превью изображения')} /> )} diff --git a/src/app/styles/pages-styles.scss b/src/app/styles/pages-styles.scss index 1d10934..982c74c 100644 --- a/src/app/styles/pages-styles.scss +++ b/src/app/styles/pages-styles.scss @@ -371,6 +371,11 @@ background: v.$p-color; margin-bottom: 10px; margin-top: 20px; + + &:disabled { + background: linear-gradient(135deg, v.$p-color-disabled, v.$s-color-disabled); + cursor: default; + } } } diff --git a/src/app/ui/search/section-search-file.tsx b/src/app/ui/search/section-search-file.tsx index aedfbc1..4a7e0f3 100644 --- a/src/app/ui/search/section-search-file.tsx +++ b/src/app/ui/search/section-search-file.tsx @@ -297,6 +297,7 @@ export default function SectionSearchFile({ fileType, allowedExtensions, maxFile className="btn btn-primary" onClick={handleButtonClick} type="button" + disabled={uploadProgress && uploadProgress !== 100 ? true : false} > Выбрать файл