From ad9fe8d07303dbca00ae0d722eceab3d1f2cc487 Mon Sep 17 00:00:00 2001 From: "k.egorenko" <k.egorenko@g.nsu.ru> Date: Mon, 22 Jul 2024 10:08:12 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20=D1=84?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=202?= =?UTF-8?q?=20=D0=9C=D0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/EditPetForm/EditPetForm.js | 43 +++---------------- .../Forms/PetCreationForm/PetCreationForm.js | 21 ++------- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/src/components/Forms/EditPetForm/EditPetForm.js b/src/components/Forms/EditPetForm/EditPetForm.js index 66b6770..6797a1e 100644 --- a/src/components/Forms/EditPetForm/EditPetForm.js +++ b/src/components/Forms/EditPetForm/EditPetForm.js @@ -11,7 +11,6 @@ import * as Endpoint from "../../../services/Endpoints"; import {isChipValid} from "../../../utils/validation"; import {isStampValid} from "../../../utils/validation"; import {handleStampKeyPress} from "../../../utils/validation"; -import imageCompression from 'browser-image-compression'; const EditPetForm = () => { const {petId} = useParams() @@ -36,43 +35,15 @@ const EditPetForm = () => { const [modalConfirmIsOpen, setModalConfirmOpen] = useState(false); const [imageFileText, setImageFileText] = useState() - const handleFileUpload = async (e) => { + const handleFileUpload = (e) => { const file = e.target.files[0]; - if (file) { - if (file.size > 2 * 1024 * 1024) { - try { - const options = { - maxSizeMB: 2, - maxWidthOrHeight: 1920, - useWebWorker: true - }; - const compressedFile = await imageCompression(file, options); - console.log("Original file size:", file.size / 1024 / 1024, "MB"); - console.log("Compressed file size:", compressedFile.size / 1024 / 1024, "MB"); - setSelectedFile(compressedFile); - setImageFileText('Рзменить фото'); - - const reader = new FileReader(); - reader.onloadend = () => { - setImageUrl(reader.result); - }; - reader.readAsDataURL(compressedFile); - } catch (error) { - console.error("Error compressing the image:", error); - toast.error('РќРµ удалось загрузить фото, пожалуйста, попробуйте уменьшить его размер Рё попробуйте СЃРЅРѕРІР°'); - } - } else { - setSelectedFile(file); - setImageFileText('Рзменить фото'); - - const reader = new FileReader(); - reader.onloadend = () => { - setImageUrl(reader.result); - }; - reader.readAsDataURL(file); - } + console.log(file.name); + if (file && file.size > 2 * 1024 * 1024) { + toast.error('Размер загружаемого файла РЅРµ должен превышать 2 РњР±. Уменьшите, пожалуйста, размер фото'); + } else { + setSelectedFile(file); } - } + }; const handleStampId = e => { let value = e.target.value.toUpperCase(); diff --git a/src/components/Forms/PetCreationForm/PetCreationForm.js b/src/components/Forms/PetCreationForm/PetCreationForm.js index 5ab2332..a9e6fc1 100644 --- a/src/components/Forms/PetCreationForm/PetCreationForm.js +++ b/src/components/Forms/PetCreationForm/PetCreationForm.js @@ -1,5 +1,4 @@ import formstyles from "../LoginForm/LoginForm.module.css"; -import imageCompression from 'browser-image-compression'; import regstyles from "../RegistrationForm/RegistrationForm.module.css" import styles from "./PetCreationForm.module.css" import {useRef, useState} from "react"; @@ -33,28 +32,16 @@ const PetCreationForm = () => { const handleSex = (event) => { setSex(event.target.value) } - - const handleFileUpload = async (event) => { + + const handleFileUpload = (event) => { const file = event.target.files[0]; console.log(file.name); if (file && file.size > 2 * 1024 * 1024) { - try { - const options = { - maxSizeMB: 2, - maxWidthOrHeight: 1920, - useWebWorker: true - }; - const compressedFile = await imageCompression(file, options); - console.log("Original file size:", file.size / 1024 / 1024, "MB"); - console.log("Compressed file size:", compressedFile.size / 1024 / 1024, "MB"); - setSelectedFile(compressedFile); - } catch (error) { - console.error("Error compressing the image:", error); - } + toast.error('Размер загружаемого файла РЅРµ должен превышать 2 РњР±. Уменьшите, пожалуйста, размер фото'); } else { setSelectedFile(file); } - } + }; const handleStampId = e => { let value = e.target.value.toUpperCase(); -- GitLab