({
onFilesAdded,
isProcessing,
compact,
}: DropzoneProps)
| 9 | } |
| 10 | |
| 11 | const DropzoneComponent = ({ |
| 12 | onFilesAdded, |
| 13 | isProcessing, |
| 14 | compact, |
| 15 | }: DropzoneProps) => { |
| 16 | const [isDragOver, setIsDragOver] = useState(false); |
| 17 | const inputRef = useRef<HTMLInputElement>(null); |
| 18 | const containerRef = useRef<HTMLDivElement>(null); |
| 19 | const dragCounter = useRef(0); |
| 20 | |
| 21 | const isValidFile = (file: File) => { |
| 22 | return ( |
| 23 | file.type.startsWith('image/') || |
| 24 | file.type === 'application/zip' || |
| 25 | file.type === 'application/x-zip-compressed' || |
| 26 | file.name.endsWith('.zip') || |
| 27 | file.name.endsWith('.svg') |
| 28 | ); |
| 29 | }; |
| 30 | |
| 31 | useEffect(() => { |
| 32 | const handleWindowDragEnter = (e: DragEvent) => { |
| 33 | e.preventDefault(); |
| 34 | dragCounter.current += 1; |
| 35 | if ( |
| 36 | e.dataTransfer?.types && |
| 37 | Array.from(e.dataTransfer.types).includes('Files') |
| 38 | ) { |
| 39 | setIsDragOver(true); |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | const handleWindowDragLeave = (e: DragEvent) => { |
| 44 | e.preventDefault(); |
| 45 | dragCounter.current -= 1; |
| 46 | if (dragCounter.current === 0) { |
| 47 | setIsDragOver(false); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | const handleWindowDragOver = (e: DragEvent) => { |
| 52 | e.preventDefault(); |
| 53 | }; |
| 54 | |
| 55 | const handleWindowDrop = async (e: DragEvent) => { |
| 56 | e.preventDefault(); |
| 57 | dragCounter.current = 0; |
| 58 | setIsDragOver(false); |
| 59 | |
| 60 | if (e.dataTransfer?.items) { |
| 61 | const files: File[] = []; |
| 62 | const MAX_FILES = 100; |
| 63 | let processedCount = 0; |
| 64 | |
| 65 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 66 | const traverseFileTree = async (item: any, path?: string) => { |
| 67 | if (processedCount >= MAX_FILES) return; |
| 68 | path = path || ''; |
nothing calls this directly
no outgoing calls
no test coverage detected