From 8778b5a7841ecea599c82057ce9ca54fc58f70a2 Mon Sep 17 00:00:00 2001 From: rachanapatel Date: Mon, 16 Jun 2025 02:04:28 -0400 Subject: [PATCH 1/2] waves one and two finished --- src/App.jsx | 6 ++++++ src/components/ChatEntry.jsx | 24 +++++++++++++++++------- src/components/ChatLog.jsx | 13 +++++++++++++ src/components/TimeStamp.jsx | 4 +++- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..23b089bbd 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,20 @@ import './App.css'; +import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog';'./components/ChatLog'; +import jsonData from '/Users/Rach/Developer/projects/react-chatlog/src/data/messages.json'; const App = () => { return (

Application title

+

title2

+ {/* */} {/* 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..0c36c368d 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,30 @@ import './ChatEntry.css'; +import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; +import jsonData from '/Users/Rach/Developer/projects/react-chatlog/src/data/messages.json'; +import { useState } from 'react'; + +const ChatEntry = (props) => { + const [heart, setHeart] = useState(props.liked); + let heartShown = heart ? '❤️' : '🤍'; -const ChatEntry = () => { return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+
); }; ChatEntry.propTypes = { - // Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.boolean, }; -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..a1430582d --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,13 @@ +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; +// import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + return ( + props.entries.map(entry => + + )); +}; + + +export default ChatLog; \ No newline at end of file diff --git a/src/components/TimeStamp.jsx b/src/components/TimeStamp.jsx index e8892b4d4..60afe3bf8 100644 --- a/src/components/TimeStamp.jsx +++ b/src/components/TimeStamp.jsx @@ -6,7 +6,9 @@ const TimeStamp = (props) => { const absolute = time.toFormat('MMMM Do YYYY, h:mm:ss a'); const relative = time.toRelative(); - return {relative}; + return + {relative} + ; }; TimeStamp.propTypes = { From 07b466bdebfa7f4520a8bd509ad42833d801177a Mon Sep 17 00:00:00 2001 From: rachanapatel Date: Wed, 18 Jun 2025 03:03:18 -0400 Subject: [PATCH 2/2] wave three finished --- src/App.jsx | 33 +++++++++++++++++++++++++++------ src/components/ChatEntry.jsx | 12 +++++++----- src/components/ChatLog.jsx | 15 +++++++++++++-- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 23b089bbd..6f3a8330c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,20 +1,41 @@ import './App.css'; import ChatEntry from './components/ChatEntry'; import ChatLog from './components/ChatLog';'./components/ChatLog'; -import jsonData from '/Users/Rach/Developer/projects/react-chatlog/src/data/messages.json'; +import jsonData from './data/messages.json'; +import { useState }from 'react'; const App = () => { + const [messages, setMessages] = useState(jsonData); + + const updateMsgLikes = (id) => { + const update = messages.map(message => { + if (message.id === id) { + return { ...message, liked: !message.liked}; + } + return message; + }); + return setMessages(update) + }; + + const numHearts = () => { + let count = 0; + for (const msg of messages) { + if (msg.liked === true) { + count++; + } + } + return count; + } + + return (

Application title

-

title2

+

{numHearts()} ❤️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 0c36c368d..1ddd5261b 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,12 +1,11 @@ import './ChatEntry.css'; import PropTypes from 'prop-types'; import TimeStamp from './TimeStamp'; -import jsonData from '/Users/Rach/Developer/projects/react-chatlog/src/data/messages.json'; import { useState } from 'react'; const ChatEntry = (props) => { - const [heart, setHeart] = useState(props.liked); - let heartShown = heart ? '❤️' : '🤍'; + // const [heart, setHeart] = useState(props.liked); + let heartShown = props.liked ? '❤️' : '🤍'; return (
@@ -14,17 +13,20 @@ const ChatEntry = (props) => {

{props.body}

- + {/* */} +
); }; ChatEntry.propTypes = { + id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, - liked: PropTypes.boolean, + liked: PropTypes.bool.isRequired, + onHeart: PropTypes.func.isRequired, }; export default ChatEntry; \ No newline at end of file diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index a1430582d..dff10be81 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -1,13 +1,24 @@ import './ChatLog.css'; import ChatEntry from './ChatEntry'; -// import PropTypes from 'prop-types'; +import PropTypes from 'prop-types'; const ChatLog = (props) => { return ( props.entries.map(entry => - + )); }; +ChatLog.propTypes = { + entries: PropTypes.arrayOf(PropTypes.shape({ + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + })).isRequired, + onHeart: PropTypes.func.isRequired, +}; export default ChatLog; \ No newline at end of file