From 0688abec386adc83bca8d889f7a9030960071602 Mon Sep 17 00:00:00 2001 From: Yasiel Date: Tue, 17 Jun 2025 02:41:54 -0700 Subject: [PATCH] all code implemented and tests passed. --- src/App.jsx | 36 ++++++++++++++++++++++++++++++++---- src/components/ChatEntry.jsx | 29 ++++++++++++++++++++++------- src/components/ChatLog.jsx | 28 ++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..381296bba 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,17 +1,45 @@ import './App.css'; +import ChatLog from './components/ChatLog'; +import messagesData from './data/messages.json'; +import { useState } from 'react'; const App = () => { + const [messages, setMessages] = useState(messagesData); + + const toggleLike = (messageId) => { + setMessages(prevMessages => + prevMessages.map(message => + message.id === messageId + ? { ...message, liked: !message.liked } + : message + ) + ); + }; + + const getTotalLikes = () => { + return messages.filter(message => message.liked).length; + }; + + const totalLikes = getTotalLikes(); + return (
-

Application title

+

Ada Chat Log

+
+ + {totalLikes} ❤️s + +
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); }; -export default App; +export default App; \ No newline at end of file diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..a6b8ca159 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,35 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; +import PropTypes from 'prop-types'; + +const ChatEntry = ({ id, sender, body, timeStamp, liked, onToggleLike }) => { + const handleLikeClick = () => { + onToggleLike(id); + }; -const ChatEntry = () => { return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{body}

+

+ +

+
); }; ChatEntry.propTypes = { - // Fill with correct proptypes + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + onToggleLike: PropTypes.func.isRequired, }; -export default ChatEntry; +export default ChatEntry; \ No newline at end of file diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..cd22373c6 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,28 @@ +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = ({ entries, onToggleLike }) => { + return ( +
+ {entries.map(entry => ( + + ))} +
+ ); +}; + +ChatLog.propTypes = { + entries: PropTypes.array.isRequired, + onToggleLike: PropTypes.func.isRequired, +}; + +export default ChatLog; \ No newline at end of file