From 30940cb85304d1a0dbe72a44dec9a60a40af0a10 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Thu, 18 Jan 2024 14:57:17 -0300 Subject: [PATCH] Refactor: Make IOView component use zustand store --- src/frontend/src/components/IOview/index.tsx | 93 +++++++ .../newChatView/chatInput/index.tsx | 127 ++++++++++ .../chatMessage/codeBlock/index.tsx | 79 ++++++ .../newChatView/chatMessage/index.tsx | 234 ++++++++++++++++++ .../newChatView/fileComponent/index.tsx | 87 +++++++ .../src/components/newChatView/index.tsx | 193 +++++++++++++++ .../components/textInputComponent/index.tsx | 15 ++ .../components/textOutputComponent/index.tsx | 15 ++ src/frontend/src/controllers/API/index.ts | 19 ++ src/frontend/src/stores/flowsIOStore.ts | 18 +- src/frontend/src/types/api/index.ts | 12 + src/frontend/src/types/chat/index.ts | 21 +- src/frontend/src/types/components/index.ts | 2 +- src/frontend/src/types/flow/index.ts | 6 +- .../src/types/zustand/flowIOStore/index.ts | 4 +- src/frontend/src/utils/buildUtils.ts | 81 ++++++ src/frontend/src/utils/utils.ts | 5 + 17 files changed, 994 insertions(+), 17 deletions(-) create mode 100644 src/frontend/src/components/IOview/index.tsx create mode 100644 src/frontend/src/components/newChatView/chatInput/index.tsx create mode 100644 src/frontend/src/components/newChatView/chatMessage/codeBlock/index.tsx create mode 100644 src/frontend/src/components/newChatView/chatMessage/index.tsx create mode 100644 src/frontend/src/components/newChatView/fileComponent/index.tsx create mode 100644 src/frontend/src/components/newChatView/index.tsx create mode 100644 src/frontend/src/components/textInputComponent/index.tsx create mode 100644 src/frontend/src/components/textOutputComponent/index.tsx create mode 100644 src/frontend/src/utils/buildUtils.ts diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx new file mode 100644 index 000000000..85587f8eb --- /dev/null +++ b/src/frontend/src/components/IOview/index.tsx @@ -0,0 +1,93 @@ +import { ReactNode, useContext, useState } from "react"; +import NewChatView from "../newChatView"; +import { extractTypeFromLongId, removeCountFromString } from "../../utils/utils"; +import AccordionComponent from "../AccordionComponent"; +import { Badge } from "../ui/badge"; +import ShadTooltip from "../ShadTooltipComponent"; +import IconComponent from "../genericIconComponent"; +import { Textarea } from "../ui/textarea"; +import { NodeDataType } from "../../types/flow"; +import useFlowStore from "../../stores/flowStore"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; +import useFlowIOStore from "../../stores/flowsIOStore"; + + +export default function IOView(): JSX.Element { + const {inputIds, outputIds, updateNodeFlowData } = + useFlowIOStore(); + const { reactFlowInstance } = useFlowStore(); + const options = inputIds.concat(outputIds); + const [selectedView, setSelectedView] = useState(handleSelectChange(options[0])); + // if (outputTypes.includes("ChatOutput")) { + // return ; + // } + function handleSelectChange(selected: string) { + const type = extractTypeFromLongId(selected); + return + switch (type) { + case "ChatOutput": + return ; + break; + } + } + + + return ( +
+
+
+ + + Inputs + +
+ { + inputIds.filter(input=>extractTypeFromLongId(input)!=="ChatInput").map((inputId,index) => { + const nodeData:NodeDataType = reactFlowInstance?.getNodes().find(node=>node.id===inputId)?.data; + return ( +
+ + + {inputId} + +
{ + event.stopPropagation(); + }} + > +
+
+ } + key={index} + keyValue={inputId} + > +
+ +
+ +
+ ) + }) + } +
+ {selectedView} + + ); +} diff --git a/src/frontend/src/components/newChatView/chatInput/index.tsx b/src/frontend/src/components/newChatView/chatInput/index.tsx new file mode 100644 index 000000000..7ae0a0915 --- /dev/null +++ b/src/frontend/src/components/newChatView/chatInput/index.tsx @@ -0,0 +1,127 @@ +import { useEffect, useState } from "react"; +import IconComponent from "../../../components/genericIconComponent"; +import { Textarea } from "../../../components/ui/textarea"; +import { chatInputType } from "../../../types/components"; +import { classNames } from "../../../utils/utils"; + +export default function ChatInput({ + lockChat, + chatValue, + sendMessage, + setChatValue, + inputRef, + noInput, +}: chatInputType): JSX.Element { + const [repeate, setRepeate] = useState(1); + useEffect(() => { + if (!lockChat && inputRef.current) { + inputRef.current.focus(); + } + }, [lockChat, inputRef]); + + + function handleChange(value:number){ + console.log(value) + if(value>0){ + setRepeate(value); + } + else{ + setRepeate(1); + } + } + + + useEffect(() => { + if (inputRef.current) { + inputRef.current.style.height = "inherit"; // Reset the height + inputRef.current.style.height = `${inputRef.current.scrollHeight}px`; // Set it to the scrollHeight + } + }, [chatValue]); + + + return ( +
+
+ repeate + { + handleChange(parseInt(e.target.value)); + }} className="bg-background" type="number" min={0}/> + + +
+