From 8ba712c348d1b3c0290ec522b1cb29b227746ba8 Mon Sep 17 00:00:00 2001 From: Solhee Date: Fri, 13 Jun 2025 12:23:39 -0700 Subject: [PATCH 1/3] Implemented all waves React chatlog, tests passing --- src/App.jsx | 26 +++++++++++++++++++++--- src/components/ChatEntry.jsx | 25 +++++++++++++++++------ src/components/ChatLog.jsx | 39 ++++++++++++++++++++++++++++++++++++ src/data/messages.json | 2 +- 4 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..c66829f36 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,34 @@ import './App.css'; +// import ChatEntry from './components/ChatEntry.jsx'; +import ChatLog from './components/ChatLog.jsx'; +import messagesData from './data/messages.json'; +import { useState } from 'react'; const App = () => { + const [messageData, setMessageData] = useState(messagesData); + + const toggleLiked = (messageId) => { + const messages = messageData.map(message => { + if (message.id === messageId) { + return { ...message, liked: !message.liked }; + } else { + return message; // message like status not changed + } + }); + setMessageData(messages); + }; + const totalLikes = messageData.filter(message => message.liked).length; return (
-

Application title

+

React Chatlog

+

{totalLikes} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..0d3aae746 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,33 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp.jsx'; +import PropTypes from 'prop-types'; -const ChatEntry = () => { +const ChatEntry = ({id, sender, body, timeStamp, liked, onLikeToggle}) => { + const likeButtonClicked = () => { + onLikeToggle(id); + }; + const heartColor = liked ? '❤️' : '🤍'; return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{body}

+

+ +

+
); }; ChatEntry.propTypes = { - // Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + id: PropTypes.number, + liked: PropTypes.bool, + onLikeToggle: PropTypes.func }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..c70ae071b --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,39 @@ +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry.jsx'; + +const ChatLog = (props) => { + const messageComponents = props.entries.map(message => { + return ( + + ); + }); + + return ( + <> + {messageComponents} + + ) +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + id: PropTypes.number, + liked: PropTypes.bool + }) + ).isRequired, + onLikeToggle: PropTypes.func +}; +export default ChatLog; \ No newline at end of file diff --git a/src/data/messages.json b/src/data/messages.json index 64fdb053c..67cc5eb39 100644 --- a/src/data/messages.json +++ b/src/data/messages.json @@ -188,4 +188,4 @@ "timeStamp":"2018-05-29T23:17:34+00:00", "liked": false } -] +] \ No newline at end of file From d8a4f3872f51586106ef3367527b908f5b29d861 Mon Sep 17 00:00:00 2001 From: Solhee Date: Mon, 16 Jun 2025 09:59:02 -0700 Subject: [PATCH 2/3] Adjusted some styling --- src/App.css | 2 ++ src/App.jsx | 3 +-- src/components/ChatEntry.jsx | 2 +- src/components/ChatLog.css | 2 +- src/components/ChatLog.jsx | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/App.css b/src/App.css index d97beb4e6..ed95a4284 100644 --- a/src/App.css +++ b/src/App.css @@ -5,6 +5,7 @@ #App header { background-color: #222; color: #fff; + padding-top: 0.5rem; padding-bottom: 0.5rem; position: fixed; width: 100%; @@ -28,6 +29,7 @@ #App header section { background-color: #e0ffff; + color: black; } #App .widget { diff --git a/src/App.jsx b/src/App.jsx index c66829f36..305b09651 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,5 +1,4 @@ import './App.css'; -// import ChatEntry from './components/ChatEntry.jsx'; import ChatLog from './components/ChatLog.jsx'; import messagesData from './data/messages.json'; import { useState } from 'react'; @@ -22,7 +21,7 @@ const App = () => {

React Chatlog

-

{totalLikes} ❤️s

+
{totalLikes} ❤️s
{ const messageComponents = props.entries.map(message => { return ( - Date: Mon, 16 Jun 2025 10:01:20 -0700 Subject: [PATCH 3/3] Added missing semicolon --- src/components/ChatLog.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 4a73bf9e7..23c5ccd7e 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -21,7 +21,7 @@ const ChatLog = (props) => { <> {messageComponents} - ) + ); }; ChatLog.propTypes = {