diff --git a/client/src/App.js b/client/src/App.js index 2f60d09..d0b0184 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -7,15 +7,17 @@ import NavPrompt from "./components/NavPrompt"; function App() { const [showMenu, setShowMenu] = useState(false); - const [chatPrompt, setChatPrompt] = useState("Hello bot!"); - const [botMessage, setBotMessage] = useState( - "Hey human! I am an AI. Tell me how can I help you." - ); const [inputPrompt, setInputPrompt] = useState(""); + const [chatLog, setChatLog] = useState([ + { + chatPrompt: "Hello bot!", + botMessage: "Hey human! I am an AI. Tell me how can I help you.", + }, + ]); const handleSubmit = (e) => { e.preventDefault(); - console.log("form runs"); + setChatLog([...chatLog, { chatPrompt: inputPrompt }]); async function callAPI() { const response = await fetch("http://localhost:4000/", { method: "POST", @@ -23,9 +25,13 @@ function App() { body: JSON.stringify({ message: inputPrompt }), }); const data = await response.json(); - console.log("data", data.botResponse); - setChatPrompt(inputPrompt); - setBotMessage(data.botResponse); + setChatLog([ + ...chatLog, + { + chatPrompt: inputPrompt, + botMessage: data.botResponse, + }, + ]); } callAPI(); setInputPrompt(""); @@ -54,7 +60,7 @@ function App() { {showMenu && (