From 3bd103dbc5413e924f2c85a5dadfee710170be51 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 28 Jun 2023 17:42:58 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(promptComponent):=20mov?= =?UTF-8?q?e=20postValidatePrompt=20import=20statement=20to=20the=20top=20?= =?UTF-8?q?of=20the=20file=20for=20better=20organization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔥 chore(promptModal): remove unused promptModal component 🔨 refactor(promptComponent): use useEffect to make a POST request to validate the prompt value and update the nodeClass state if the API returns data --- .../src/components/promptComponent/index.tsx | 13 ++ src/frontend/src/modals/promptModal/index.tsx | 153 ------------------ 2 files changed, 13 insertions(+), 153 deletions(-) delete mode 100644 src/frontend/src/modals/promptModal/index.tsx diff --git a/src/frontend/src/components/promptComponent/index.tsx b/src/frontend/src/components/promptComponent/index.tsx index 59c4227ef..3f0742407 100644 --- a/src/frontend/src/components/promptComponent/index.tsx +++ b/src/frontend/src/components/promptComponent/index.tsx @@ -5,6 +5,7 @@ import GenericModal from "../../modals/genericModal"; import { TypeModal } from "../../utils"; import { INPUT_STYLE } from "../../constants"; import { ExternalLink } from "lucide-react"; +import { postValidatePrompt } from "../../controllers/API"; export default function PromptAreaComponent({ setNodeClass, @@ -23,6 +24,18 @@ export default function PromptAreaComponent({ } }, [disabled, onChange]); + useEffect(() => { + if (value) { + postValidatePrompt(myValue, nodeClass) + .then((apiReturn) => { + if (apiReturn.data) { + setNodeClass(apiReturn.data.frontend_node); + } + }) + .catch((error) => {}); + } + }, [value]); + useEffect(() => { setMyValue(value); }, [value]); diff --git a/src/frontend/src/modals/promptModal/index.tsx b/src/frontend/src/modals/promptModal/index.tsx deleted file mode 100644 index 2ab1c140a..000000000 --- a/src/frontend/src/modals/promptModal/index.tsx +++ /dev/null @@ -1,153 +0,0 @@ -import { Dialog, Transition } from "@headlessui/react"; -import { XMarkIcon, DocumentTextIcon } from "@heroicons/react/24/outline"; -import { Fragment, useContext, useRef, useState } from "react"; -import { PopUpContext } from "../../contexts/popUpContext"; -import { darkContext } from "../../contexts/darkContext"; -import { postValidatePrompt } from "../../controllers/API"; -import { alertContext } from "../../contexts/alertContext"; -export default function PromptAreaModal({ - value, - setValue, -}: { - setValue: (value: string) => void; - value: string; -}) { - const [open, setOpen] = useState(true); - const [myValue, setMyValue] = useState(value); - const { dark } = useContext(darkContext); - const { setErrorData, setSuccessData } = useContext(alertContext); - const { closePopUp } = useContext(PopUpContext); - const ref = useRef(); - function setModalOpen(x: boolean) { - setOpen(x); - if (x === false) { - setTimeout(() => { - closePopUp(); - }, 300); - } - } - return ( - - - -
- - -
-
- - -
- -
-
-
-
-
-
- - Edit Prompt - -
-
-
-
-
-