From 6c19fab93f2be08cf20925533432999b2f806194 Mon Sep 17 00:00:00 2001 From: vaibhavgarg25 Date: Wed, 28 Aug 2024 22:32:07 +0530 Subject: [PATCH] chat template --- client/src/components/Negotiate/Chat.jsx | 52 ++++++++++++++++++++---- client/src/components/Negotiate/chat.css | 2 + 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/client/src/components/Negotiate/Chat.jsx b/client/src/components/Negotiate/Chat.jsx index 5f69903..3b14c88 100644 --- a/client/src/components/Negotiate/Chat.jsx +++ b/client/src/components/Negotiate/Chat.jsx @@ -1,20 +1,58 @@ -import './chat.css' +import './chat.css'; +import { useState, useRef, useEffect } from 'react'; export default function Chat() { + // State for the input text and messages + const [text, setText] = useState(''); + const [messages, setMessages] = useState([]); + + // Refs for the container and the last message + const messagesEndRef = useRef(null); + + // Scroll to the bottom whenever messages change + useEffect(() => { + messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); + }, [messages]); + + // Handle the click event to add a new message + const handleClick = () => { + if (text.trim()) { + setMessages([...messages, text]); + setText(''); + } + }; + + // Handle the change event for the textarea + const handleChange = (event) => { + setText(event.target.value); + }; + return ( -
+
-

chats display

+ {messages.map((msg, index) => ( +
+ {msg} +
+ ))} + {/* Empty div to scroll to */} +