From 1a9086852aad17afba4574ad0c814bda4ea2f89d Mon Sep 17 00:00:00 2001 From: l3wdfut4pwr Date: Sun, 3 May 2026 17:18:46 +0300 Subject: minor upload update --- src/components/upload/Dropzone.tsx | 68 +++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'src/components/upload/Dropzone.tsx') diff --git a/src/components/upload/Dropzone.tsx b/src/components/upload/Dropzone.tsx index 6980f5c..5c882be 100644 --- a/src/components/upload/Dropzone.tsx +++ b/src/components/upload/Dropzone.tsx @@ -3,40 +3,70 @@ import Dropzone from 'react-dropzone'; import UploadIcon from '@icons/upload.svg'; import { Button } from '@/components/ui'; -import { useRef, useState } from 'react'; +import { useEffect, useState } from 'react'; export function FileDropzone() { - // const [files, setFiles] = useState([]); - const hiddenInputRef = useRef(null); + const [file, setFile] = useState(null); + const [preview, setPreview] = useState(null); + + useEffect(() => { + return () => { + if (preview) URL.revokeObjectURL(preview); + }; + }, [preview]); + return ( { - // setFiles((prev) => [...prev, ...acceptedFiles]); + multiple={false} + accept={{ 'image/*': [] }} + onDrop={(acceptedFiles) => { + const f = acceptedFiles[0]; + if (!f) return; + + const url = URL.createObjectURL(f); + + setFile(f); + setPreview(url); }} > {({ getRootProps, getInputProps }) => (
- -
- - - Выбери файлы на компьютере или перетащи сюда. JPG, - PNG до 20MB. - - - {hiddenInputRef.current?.files?.length ?? 0} - +
+ {!preview ? ( +
+ + + Выбери файлы на компьютере или перетащи + сюда. JPG, PNG до 20MB. + +
+ ) : ( + preview + )}
-
)} -- cgit v1.3-3-g829e