From 36910ff1872ea26a20c29b5164b9320d313222e3 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Rosalino Date: Sun, 28 May 2023 02:13:24 -0300 Subject: [PATCH] chore: removed not needed inputDirectoryComponent --- .../inputDirectoryComponent/index.tsx | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/frontend/src/components/inputDirectoryComponent/index.tsx diff --git a/src/frontend/src/components/inputDirectoryComponent/index.tsx b/src/frontend/src/components/inputDirectoryComponent/index.tsx deleted file mode 100644 index eb167bbee..000000000 --- a/src/frontend/src/components/inputDirectoryComponent/index.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import { DocumentMagnifyingGlassIcon } from "@heroicons/react/24/outline"; -import { useContext, useEffect, useState } from "react"; -import { alertContext } from "../../contexts/alertContext"; -import { FileComponentType } from "../../types/components"; - -export default function InputDirectoryComponent({ - value, - onChange, - disabled, - suffixes, - fileTypes, - onFileChange, -}: FileComponentType) { - const [myValue, setMyValue] = useState(value); - const { setErrorData } = useContext(alertContext); - useEffect(() => { - if (disabled) { - setMyValue(""); - onChange(""); - onFileChange(""); - } - }, [disabled, onChange]); - - function attachFiles(files) { - onFileChange(files); - } - - function checkFileType(fileName: string): boolean { - for (let index = 0; index < suffixes.length; index++) { - if (fileName.endsWith(suffixes[index])) { - return true; - } - } - return false; - } - - const handleDirectoryButtonClick = () => { - const input = document.createElement("input"); - input.type = "file"; - input.accept = suffixes.join(","); - input.style.display = "none"; - input.multiple = true; - input.webkitdirectory = true; - input.onchange = (e: Event) => { - const filesArray = []; - const inputElement = e.target as HTMLInputElement; - console.log(inputElement.webkitEntries); // Not working - const files = (e.target as HTMLInputElement).files; - const directory = (e.target as HTMLInputElement).dirName; // Not working - - console.log(directory); - if (files) { - for (let index = 0; index < files.length; index++) { - const file = files[index]; - if (checkFileType(file.name)) { - console.log("going in: ", file); - filesArray.push(file); - } - } - if (filesArray.length > 0) { - setMyValue(filesArray[0].webkitRelativePath); - onChange(filesArray[0].webkitRelativePath); - attachFiles(filesArray[0].webkitRelativePath); - } else { - setErrorData({ - title: - "Please select a valid directory. Only directories containing files with these file types are allowed:", - list: fileTypes, - }); - } - } - }; - input.click(); - }; - - return ( -
-
- - {myValue !== "" ? myValue : "No directory"} - - -
-
- ); -}