From 43e9fac680e854e828d1ea4e35a297676a44f459 Mon Sep 17 00:00:00 2001 From: Brianna Root Date: Mon, 16 Dec 2024 18:02:41 +1300 Subject: [PATCH 1/6] Updated Apps and ChatEntry to display a bubble with json data. --- src/App.jsx | 13 +++++++++++-- src/components/ChatEntry.jsx | 14 +++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..f251984d7 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,23 @@ import './App.css'; +import ChatEntry from './components/ChatEntry'; +import messages from './data/messages.json'; + + +// const samepleMessage = messages[0]; const App = () => { + console.log(messages); 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..ae4f5df37 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,12 +1,14 @@ 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}

+

{timeStamp}

@@ -14,7 +16,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 228a018f51e84df62536382bced2d81b8d41248a Mon Sep 17 00:00:00 2001 From: Brianna Root Date: Mon, 16 Dec 2024 19:41:32 +1300 Subject: [PATCH 2/6] Created ChatLog and maped each entry. --- src/App.jsx | 6 ++++-- src/components/ChatLog.jsx | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index f251984d7..186a0996c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,6 +1,7 @@ import './App.css'; import ChatEntry from './components/ChatEntry'; import messages from './data/messages.json'; +import ChatLog from './components/ChatLog'; // const samepleMessage = messages[0]; @@ -14,10 +15,11 @@ const App = () => {
+
); diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..87620218d --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,31 @@ +import { fireEvent } from '@testing-library/react'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = ({ entries }) => { + return ( +
+ {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, + }) + ).isRequired, +}; + +export default ChatLog; From 18355fa57203d7985116142e955ed302ff75c2ab Mon Sep 17 00:00:00 2001 From: Brianna Root Date: Mon, 16 Dec 2024 21:33:57 +1300 Subject: [PATCH 3/6] Updated logic to sucessfully render --- src/App.jsx | 22 +++++++++++++--------- src/components/ChatEntry.jsx | 2 +- src/components/ChatLog.jsx | 26 ++++++++++++++------------ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 186a0996c..326e050f5 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,22 +3,26 @@ import ChatEntry from './components/ChatEntry'; import messages from './data/messages.json'; import ChatLog from './components/ChatLog'; - -// const samepleMessage = messages[0]; - const App = () => { - console.log(messages); + const testMessageData = { + 'id': 1, + 'sender':'Vladimir', + 'body':'why are you arguing with me', + 'timeStamp':'2018-05-29T22:49:06+00:00', + 'liked': false + } + return (

Application title

- + + sender={testMessageData.sender} + body={testMessageData.body} + timeStamp={testMessageData.timeStamp} +
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index ae4f5df37..25de3f3df 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 = ({sender, body, timeStamp, id}) => { return (

{sender}

diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 87620218d..399e01633 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -1,24 +1,26 @@ -import { fireEvent } from '@testing-library/react'; import ChatEntry from './ChatEntry'; import PropTypes from 'prop-types'; const ChatLog = ({ entries }) => { + const chatEntries = entries.map((entry) => { + return( + + ); + }); return ( -
- {entries.map((entry) => ( - - ))}; -
+ <> + {chatEntries} + ); }; ChatLog.propTypes = { - entries: PropTypes.arrayOf( + entry: PropTypes.arrayOf( PropTypes.shape({ id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, From fee01f9a56ad51f2bdc7ca830499b65c0773b9b4 Mon Sep 17 00:00:00 2001 From: Brianna Root Date: Mon, 16 Dec 2024 21:39:31 +1300 Subject: [PATCH 4/6] Passed timestamp display test --- src/components/ChatEntry.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 25de3f3df..c05dd9cc7 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -8,7 +8,9 @@ const ChatEntry = ({sender, body, timeStamp, id}) => {

{sender}

{body}

-

{timeStamp}

+

+ +

From 1fe90e3efe52a51d832d183a6527a764f1006f64 Mon Sep 17 00:00:00 2001 From: Brianna Root Date: Mon, 16 Dec 2024 23:23:24 +1300 Subject: [PATCH 5/6] Cleaned up, removed code used for testing component --- src/App.jsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 326e050f5..d2180da83 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -4,14 +4,6 @@ import messages from './data/messages.json'; import ChatLog from './components/ChatLog'; const App = () => { - const testMessageData = { - 'id': 1, - 'sender':'Vladimir', - 'body':'why are you arguing with me', - 'timeStamp':'2018-05-29T22:49:06+00:00', - 'liked': false - } - return (
@@ -19,9 +11,6 @@ const App = () => {
- sender={testMessageData.sender} - body={testMessageData.body} - timeStamp={testMessageData.timeStamp}
From c237c757c2ec38b6ddaeb97ef03aeecde0fa69d6 Mon Sep 17 00:00:00 2001 From: Brianna Root Date: Tue, 17 Dec 2024 06:26:22 +1300 Subject: [PATCH 6/6] added toggle and count logic --- src/App.jsx | 20 +++++++++++++++++--- src/components/ChatEntry.jsx | 13 +++++++++++-- src/components/ChatLog.jsx | 9 +++++++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index d2180da83..23ea72958 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -2,17 +2,31 @@ import './App.css'; import ChatEntry from './components/ChatEntry'; import messages from './data/messages.json'; import ChatLog from './components/ChatLog'; +import { useState } from 'react'; const App = () => { + const [chatMessages, setChatMessages] = useState(messages); + + const toggleLike = (id) => { + setChatMessages(chatMessages => chatMessages.map(message => { + if (message.id === id) { + return { ...message, liked: !message.liked }; + } else { + return message; + } + })); + }; + + const totalLikes = chatMessages.filter(message => message.liked).length; + return (

Application title

+

{totalLikes} 🤍s

- - - +
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index c05dd9cc7..7f4b854a2 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -2,7 +2,11 @@ import './ChatEntry.css'; import PropTypes from 'prop-types'; import TimeStamp from './TimeStamp'; -const ChatEntry = ({sender, body, timeStamp, id}) => { +const ChatEntry = ({sender, body, timeStamp, id, liked, onToggleLike}) => { + const handleClick = () => { + onToggleLike(id); + }; + return (

{sender}

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

- +
); }; ChatEntry.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; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 399e01633..ed5c3f9d5 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -1,14 +1,17 @@ import ChatEntry from './ChatEntry'; import PropTypes from 'prop-types'; -const ChatLog = ({ entries }) => { +const ChatLog = ({ entries, onToggleLike }) => { const chatEntries = entries.map((entry) => { return( ); }); @@ -20,14 +23,16 @@ const ChatLog = ({ entries }) => { }; ChatLog.propTypes = { - entry: PropTypes.arrayOf( + 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, + onToggleLike: PropTypes.func.isRequired, }; export default ChatLog;