From e6d660d1032caf311e1b21c37d63fb9231529469 Mon Sep 17 00:00:00 2001 From: Gitika Kalal Date: Fri, 13 Jun 2025 14:30:46 -0700 Subject: [PATCH 1/3] completed ChatEntry component with sender, message, and timestamp display and connect messages.json in App to render first message --- src/App.jsx | 12 ++++++++++++ src/components/ChatEntry.jsx | 16 +++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..396038b5c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,12 +1,24 @@ import './App.css'; +import DATA from './data/messages.json'; +import ChatEntry from './components/ChatEntry'; + + const App = () => { + const firstMessagesData = DATA[0]; return (

Application title

+
+ +
{/* 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..b968d98aa 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,12 +1,16 @@ import './ChatEntry.css'; +import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; -const ChatEntry = () => { +const ChatEntry = ({ sender, body, timeStamp }) => { return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

+

{body}

+

+ +

@@ -14,7 +18,9 @@ const ChatEntry = () => { }; ChatEntry.propTypes = { - // Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, }; export default ChatEntry; From ef2e81bd46aad5ad5c772390b0ec442d0bcbc1c5 Mon Sep 17 00:00:00 2001 From: Gitika Kalal Date: Sun, 15 Jun 2025 19:22:28 -0700 Subject: [PATCH 2/3] add ChatLog component to display full chat using ChatEntry components --- src/App.jsx | 8 +++++--- src/components/ChatLog.jsx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 396038b5c..c9ec0fde4 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,11 +1,12 @@ import './App.css'; import DATA from './data/messages.json'; import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; const App = () => { - const firstMessagesData = DATA[0]; + const MessagesData = DATA; return (
@@ -13,11 +14,12 @@ const App = () => {
- + > */} +
{/* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */} diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..f7c1d999c --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,34 @@ +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; +import './ChatLog.css'; + +const ChatLog = ({entries}) =>{ + const ChatEntries = entries.map( (entry) => { + return( + + ); + }); + return ( +
+ {ChatEntries} +
+ ); +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + }) + ).isRequired, +}; + +export default ChatLog \ No newline at end of file From e073dc35a87472b7675f190db70a3431a5e11573 Mon Sep 17 00:00:00 2001 From: Gitika Kalal Date: Mon, 16 Jun 2025 00:13:10 -0700 Subject: [PATCH 3/3] add like toggle functionality and lift state to App to track total likes --- src/App.jsx | 33 ++++++++++++++++++++++++++------- src/components/ChatEntry.jsx | 9 +++++++-- src/components/ChatLog.jsx | 7 ++++++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index c9ec0fde4..435772bf6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,28 +1,47 @@ import './App.css'; import DATA from './data/messages.json'; -import ChatEntry from './components/ChatEntry'; +// import ChatEntry from './components/ChatEntry'; import ChatLog from './components/ChatLog'; +import { useState } from 'react'; +import './App.css'; const App = () => { - const MessagesData = DATA; + const [messagesData, setMessagesData] = useState(DATA); + const toggleLike = (Id) => { + const updatedMessages = messagesData.map((msg) => { + if (msg.id === Id) { + return { ...msg, liked: !msg.liked }; + } else { + return msg; + } + }); + setMessagesData(updatedMessages); + }; + const likedMessages = messagesData.filter((message) => { + return message.liked === true; + }); + const totalLikes = likedMessages.length; return (
-

Application title

+

Chat Between Vladimer and Estragon

+

{totalLikes} ❤️s

- {/* */} - + + {/* {Wave 02: Render ChatLog component */} +
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */}
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index b968d98aa..61cae5a90 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -2,7 +2,7 @@ import './ChatEntry.css'; import PropTypes from 'prop-types'; import TimeStamp from './TimeStamp'; -const ChatEntry = ({ sender, body, timeStamp }) => { +const ChatEntry = ({ id, sender, body, timeStamp, liked, onLikeToggle}) => { return (

{sender}

@@ -11,16 +11,21 @@ const ChatEntry = ({ sender, body, timeStamp }) => {

- +
); }; ChatEntry.propTypes = { + id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + onLikeToggle: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index f7c1d999c..86e69feee 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -2,14 +2,17 @@ import ChatEntry from './ChatEntry'; import PropTypes from 'prop-types'; import './ChatLog.css'; -const ChatLog = ({entries}) =>{ +const ChatLog = ({entries, onLikeToggle }) =>{ const ChatEntries = entries.map( (entry) => { return( ); }); @@ -27,8 +30,10 @@ ChatLog.propTypes = { sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, }) ).isRequired, + onLikeToggle: PropTypes.func.isRequired, }; export default ChatLog \ No newline at end of file