Loading web/src/components/image_dropzone/image_dropzone.tsx +7 −13 Original line number Diff line number Diff line Loading @@ -4,16 +4,16 @@ import { useDropzone } from "react-dropzone"; import { useState } from 'react'; import "react-toastify/dist/ReactToastify.css"; import { UseFormSetValue } from 'react-hook-form'; import { TownFormValues } from '../../infraestructure/entities/town'; import { Town } from '../../infraestructure/entities/town'; interface props { setValue : UseFormSetValue<TownFormValues> setValue : UseFormSetValue<Town> } export const ImageDropzone = ({setValue}: props) => { const MAX_SIZE = 10485760; const [preview, setPreview] = useState<string | ArrayBuffer | null>(null); const {fileRejections,getRootProps, getInputProps} = useDropzone( const {getRootProps, getInputProps} = useDropzone( { multiple: false, maxSize: MAX_SIZE, Loading @@ -22,8 +22,6 @@ export const ImageDropzone = ({setValue}: props) => { 'image/png': [] }, onDrop(acceptedFiles, fileRejections) { const file = new FileReader; fileRejections.map(({file, errors}) => ( toast.error(errors[0].message, { position: "bottom-right", Loading @@ -36,15 +34,11 @@ export const ImageDropzone = ({setValue}: props) => { theme: "colored" }))); acceptedFiles.map((file)=>{ {setValue('imageURL',file,{shouldValidate: true})} acceptedFiles.forEach((file)=>{ const preview = URL.createObjectURL(file); setValue('imageURL',file,{shouldValidate: true}); setPreview(preview); }); file.onload = () => { setPreview(file.result); }; file.readAsDataURL(acceptedFiles[0]); } } ); Loading Loading
web/src/components/image_dropzone/image_dropzone.tsx +7 −13 Original line number Diff line number Diff line Loading @@ -4,16 +4,16 @@ import { useDropzone } from "react-dropzone"; import { useState } from 'react'; import "react-toastify/dist/ReactToastify.css"; import { UseFormSetValue } from 'react-hook-form'; import { TownFormValues } from '../../infraestructure/entities/town'; import { Town } from '../../infraestructure/entities/town'; interface props { setValue : UseFormSetValue<TownFormValues> setValue : UseFormSetValue<Town> } export const ImageDropzone = ({setValue}: props) => { const MAX_SIZE = 10485760; const [preview, setPreview] = useState<string | ArrayBuffer | null>(null); const {fileRejections,getRootProps, getInputProps} = useDropzone( const {getRootProps, getInputProps} = useDropzone( { multiple: false, maxSize: MAX_SIZE, Loading @@ -22,8 +22,6 @@ export const ImageDropzone = ({setValue}: props) => { 'image/png': [] }, onDrop(acceptedFiles, fileRejections) { const file = new FileReader; fileRejections.map(({file, errors}) => ( toast.error(errors[0].message, { position: "bottom-right", Loading @@ -36,15 +34,11 @@ export const ImageDropzone = ({setValue}: props) => { theme: "colored" }))); acceptedFiles.map((file)=>{ {setValue('imageURL',file,{shouldValidate: true})} acceptedFiles.forEach((file)=>{ const preview = URL.createObjectURL(file); setValue('imageURL',file,{shouldValidate: true}); setPreview(preview); }); file.onload = () => { setPreview(file.result); }; file.readAsDataURL(acceptedFiles[0]); } } ); Loading