From cf79a6ee7618fd336722124061ab3b91ad995b7e Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 16 Feb 2023 15:31:00 -0300 Subject: [PATCH] Scroll to made and error when the message is empty done --- .../src/components/chatComponent/index.tsx | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/space_flow/src/components/chatComponent/index.tsx b/space_flow/src/components/chatComponent/index.tsx index 6fe087734..984a4e746 100644 --- a/space_flow/src/components/chatComponent/index.tsx +++ b/space_flow/src/components/chatComponent/index.tsx @@ -4,7 +4,7 @@ import { PaperAirplaneIcon, XMarkIcon, } from "@heroicons/react/24/outline"; -import { useContext, useState } from "react"; +import { useContext, useEffect, useRef, useState } from "react"; import { sendAll } from "../../controllers/NodesServices"; import { alertContext } from "../../contexts/alertContext"; @@ -22,12 +22,16 @@ export default function Chat({ reactFlowInstance }) { return newChat; }); }; + useEffect(()=>{ + ref.current.scrollIntoView({behavior: 'smooth'}); + }, [chatHistory]) function validateNodes(){ if(reactFlowInstance.getNodes().some((n) => (n.data.node && Object.keys(n.data.node.template).some((t: any) => (n.data.node.template[t].required && !reactFlowInstance.getEdges().some((e) => (e.sourceHandle.split('|')[1] === t && e.sourceHandle.split('|')[2] === n.id))))))){ return false; } return true; } + const ref = useRef(null); return ( <> -
+
{chatHistory.map((c, i) => (
{c.isSend ? ( @@ -73,6 +77,7 @@ export default function Chat({ reactFlowInstance }) { )}
))} +
@@ -88,19 +93,24 @@ export default function Chat({ reactFlowInstance }) {