diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx new file mode 100644 index 000000000..4cfe74980 --- /dev/null +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -0,0 +1,85 @@ +import { useState, useContext } from "react"; +import { Transition } from "@headlessui/react"; +import { Bars3CenterLeftIcon } from "@heroicons/react/24/outline"; +import { Zap } from "lucide-react"; +import { nodeColors } from "../../../utils"; +import { PopUpContext } from "../../../contexts/popUpContext"; +import ChatModal from "../../../modals/chatModal"; +import { FlowType } from "../../../types/flow"; +import { postBuild } from "../../../controllers/API"; +import Loading from "../../../components/ui/loading"; + +export default function BuildTrigger({ + open, + flow, + setIsBuilt, + isBuilt, +}: { + open: boolean; + flow: FlowType; + setIsBuilt: any; + isBuilt: boolean; +}) { + const [isBuilding, setIsBuilding] = useState(false); + + function handleBuild(flow: FlowType) { + const minimumLoadingTime = 500; // in milliseconds + const startTime = Date.now(); + + setIsBuilding(true); + + postBuild(flow) + .then((res) => { + console.log(res); + setIsBuilt(true); + }) + .catch((err) => { + console.log(err); + setIsBuilt(false); + }) + .finally(() => { + const endTime = Date.now(); + const elapsedTime = endTime - startTime; + + if (elapsedTime < minimumLoadingTime) { + const remainingTime = minimumLoadingTime - elapsedTime; + setTimeout(() => { + setIsBuilding(false); + }, remainingTime); + } else { + setIsBuilding(false); + } + }); + } + + return ( + + + handleBuild(flow)} + > + + + {isBuilding ? ( + // Render your loading animation here when isBuilding is true + + ) : ( + + )} + + + + + + ); +} diff --git a/src/frontend/src/components/ui/loading.tsx b/src/frontend/src/components/ui/loading.tsx new file mode 100644 index 000000000..a32c046a4 --- /dev/null +++ b/src/frontend/src/components/ui/loading.tsx @@ -0,0 +1,39 @@ +import * as React from "react"; +import { SVGProps } from "react"; + +export const Loading = (props: SVGProps) => ( + + + + + + +); +export default Loading; diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index ffa9eef72..53480ae61 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -39,3 +39,7 @@ export async function getExamples(): Promise { return await Promise.all(contentsPromises); } + +export async function postBuild(flow: FlowType) { + return await axios.post(`/build/${flow.id}`, flow); +}