From 77fab44e6047938a48390d21345e15cb288905f8 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 16 Feb 2023 12:19:21 -0300 Subject: [PATCH] chat post done --- .../src/components/chatComponent/index.tsx | 105 ++++++++++++------ .../src/controllers/NodesServices/index.ts | 4 + 2 files changed, 77 insertions(+), 32 deletions(-) diff --git a/space_flow/src/components/chatComponent/index.tsx b/space_flow/src/components/chatComponent/index.tsx index 504cbafd5..59f727fea 100644 --- a/space_flow/src/components/chatComponent/index.tsx +++ b/space_flow/src/components/chatComponent/index.tsx @@ -5,20 +5,32 @@ import { XMarkIcon, } from "@heroicons/react/24/outline"; import { useState } from "react"; +import { sendAll } from "../../controllers/NodesServices"; -export default function Chat({nodes, edges}) { +const _ = require("lodash"); + +export default function Chat({ nodes, edges }) { const [open, setOpen] = useState(true); + const [chatValue, setChatValue] = useState(""); + const [chatHistory, setChatHistory] = useState([]); + const addChatHistory = (message, isSend) => { + setChatHistory((old) => { + let newChat = _.cloneDeep(old); + newChat.push({ message, isSend }); + return newChat; + }); + }; return ( <>
@@ -27,33 +39,58 @@ export default function Chat({nodes, edges}) { Chat
-
-
-
- Lorem Ipsum is simply dummy text of the printing and - typesetting industry. + {chatHistory.map((c, i) => ( +
+ {c.isSend ? ( +
+
+ {c.message} +
+
+ ) : ( +
+
+ {c.message} +
+
+ )}
-
-
-
- Lorem Ipsum has been the industry's standard dummy text ever - since the 1500s -
-
+ ))}
{ + setChatValue(e.target.value); + }} className="form-input block w-full rounded-md border-gray-300 pr-10 sm:text-sm" placeholder="Send a message..." />
- +
diff --git a/space_flow/src/controllers/NodesServices/index.ts b/space_flow/src/controllers/NodesServices/index.ts index 8aa2af5fd..468734935 100644 --- a/space_flow/src/controllers/NodesServices/index.ts +++ b/space_flow/src/controllers/NodesServices/index.ts @@ -3,3 +3,7 @@ import axios from "axios"; export async function getAll() { return await axios.get("http://localhost:5003/"); } + +export async function sendAll(data) { + return await axios.post("http://localhost:5003/send", JSON.stringify(data)); +}