From 71374c41f0593b3e4b5a6b5f35b8aaf0f912b372 Mon Sep 17 00:00:00 2001 From: Sawit Koseeyaumporn Date: Tue, 26 Nov 2024 00:01:32 +0700 Subject: [PATCH] add: chatbox and chatlist components --- frontend/src/components/ChatBox.jsx | 47 ++++++++++++++++++++++++++++ frontend/src/components/ChatList.jsx | 34 ++++++++++++++++++++ frontend/src/components/Navbar.jsx | 4 +-- frontend/src/message.jsx | 28 +++++++++++++++-- 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 frontend/src/components/ChatBox.jsx create mode 100644 frontend/src/components/ChatList.jsx diff --git a/frontend/src/components/ChatBox.jsx b/frontend/src/components/ChatBox.jsx new file mode 100644 index 0000000..5ef4252 --- /dev/null +++ b/frontend/src/components/ChatBox.jsx @@ -0,0 +1,47 @@ +import PropTypes from 'prop-types'; + +const ChatBox = ({ activeChat }) => { + if (!activeChat) { + return ( +
+

Select a chat to start messaging

+
+ ); + } + + return ( +
+ {/* Chat Header */} +
+

{activeChat.name}

+
+ + {/* Chat Messages */} +
+
+ {activeChat.message} +
+ {/* Add more messages as needed */} +
+ + {/* Message Input */} +
+ +
+
+ ); +}; + +ChatBox.propTypes = { + activeChat: PropTypes.shape({ + id: PropTypes.number.isRequired, + name: PropTypes.string.isRequired, + message: PropTypes.string.isRequired, + }), +}; + +export default ChatBox; \ No newline at end of file diff --git a/frontend/src/components/ChatList.jsx b/frontend/src/components/ChatList.jsx new file mode 100644 index 0000000..41e063d --- /dev/null +++ b/frontend/src/components/ChatList.jsx @@ -0,0 +1,34 @@ +import PropTypes from 'prop-types'; + +const ChatList = ({ contacts, onSelectChat }) => { + return ( +
+

Chats

+ +
+ ); +}; + +ChatList.propTypes = { + contacts: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number.isRequired, + name: PropTypes.string.isRequired, + message: PropTypes.string.isRequired, + }) + ).isRequired, + onSelectChat: PropTypes.func.isRequired, +}; + +export default ChatList; \ No newline at end of file diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index 5fdb970..9067a6b 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -148,7 +148,7 @@ function Navbar() { )} - + @@ -200,7 +200,7 @@ function Navbar() { )} - + diff --git a/frontend/src/message.jsx b/frontend/src/message.jsx index 4741bc7..be520da 100644 --- a/frontend/src/message.jsx +++ b/frontend/src/message.jsx @@ -1,7 +1,29 @@ +import { useState } from 'react'; +import ChatList from './components/ChatList'; +import ChatBox from './components/ChatBox'; + const Message = () => { + const [activeChat, setActiveChat] = useState(null); + + const contacts = [ + { id: 1, name: 'John Doe', message: 'Hey! How are you?' }, + { id: 2, name: 'Jane Smith', message: 'Let’s catch up soon!' }, + { id: 3, name: 'Mark Taylor', message: 'Check this out.' }, + ]; + + const handleChatSelect = (contact) => { + setActiveChat(contact); + }; + return ( -
Message
- ) -} +
+ {/* Chat List */} + + + {/* Chat Box */} + +
+ ); +}; export default Message; \ No newline at end of file