From b8ec2523b9b031fb32c7869c8d12ab7fe9ce2380 Mon Sep 17 00:00:00 2001 From: Ajar Duishembieva Date: Sun, 15 Dec 2024 20:05:40 -0800 Subject: [PATCH 1/3] submit solution to the wave one. --- src/components/ChatEntry.jsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..c79489769 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,12 +1,20 @@ +import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; + import './ChatEntry.css'; -const ChatEntry = () => { +const ChatEntry = (props) => { + const{ + sender, + body, + timeStamp, + } = props; return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

+

{body}

+

@@ -15,6 +23,11 @@ const ChatEntry = () => { 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, }; export default ChatEntry; From c1f748c0b0c07be46d1a3852c3fc41f7556e0e52 Mon Sep 17 00:00:00 2001 From: Ajar Duishembieva Date: Sun, 15 Dec 2024 21:24:06 -0800 Subject: [PATCH 2/3] submit solution to the wave two. --- src/App.jsx | 5 +++-- src/components/ChatLog.jsx | 25 +++++++++++++++++++++++++ src/components/ChatLog.test.jsx | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..23ae2c3bb 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,3 +1,5 @@ +import data from './data/messages.json'; +import ChatLog from './components/ChatLog'; import './App.css'; const App = () => { @@ -7,8 +9,7 @@ const App = () => {

Application title

- {/* 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..859737c9d --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,25 @@ +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; + +import './ChatLog.css'; + +const ChatLog= (props) => { + const{ + entries + } = props; + + return ( +
+ { + entries.length === 0 ? [] : entries.map((entry) => ) + } +
+ ); +}; + +ChatLog.propTypes = { + // Fill with correct proptypes + entries: PropTypes.array.isRequired +}; + +export default ChatLog; diff --git a/src/components/ChatLog.test.jsx b/src/components/ChatLog.test.jsx index dfcfeda99..cffaa8d39 100644 --- a/src/components/ChatLog.test.jsx +++ b/src/components/ChatLog.test.jsx @@ -1,6 +1,6 @@ -import ChatLog from './ChatLog'; import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; +import ChatLog from './ChatLog'; const LOG = [ { From 07304a1a9583259b630301beb8a8153b54210dd9 Mon Sep 17 00:00:00 2001 From: Ajar Duishembieva Date: Sun, 15 Dec 2024 22:05:35 -0800 Subject: [PATCH 3/3] submit solution to the wave three. --- src/App.jsx | 21 +++++++++++++++++++-- src/components/ChatEntry.jsx | 6 +++++- src/components/ChatLog.jsx | 8 +++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 23ae2c3bb..963a81d05 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,15 +1,32 @@ +import { useState } from 'react'; import data from './data/messages.json'; import ChatLog from './components/ChatLog'; import './App.css'; + +const countLikes = (entries) => { + let counts = 0; + for( let index = 0; index < entries.length; index++){ + if(entries[index].liked){ + counts++; + } + } + return counts; +} + const App = () => { + const [entries, setEntries ] = useState(data); + const handleClick = (id) => { + const updatedEntries = entries.map((entry) => entry.id === id ? {...entry, liked: !entry.liked} : entry); + setEntries(updatedEntries); + }; return (
-

Application title

+

{`${countLikes(entries)} ❤️s`}

- +
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index c79489769..662b2ad56 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -7,7 +7,10 @@ const ChatEntry = (props) => { const{ sender, body, + id, + liked, timeStamp, + handleClick, } = props; return (
@@ -15,7 +18,7 @@ const ChatEntry = (props) => {

{body}

- +
); @@ -28,6 +31,7 @@ ChatEntry.propTypes = { body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, liked: PropTypes.bool.isRequired, + handleClick: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 859737c9d..71a69a068 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -5,13 +5,14 @@ import './ChatLog.css'; const ChatLog= (props) => { const{ - entries + entries, + handleClick } = props; return (
{ - entries.length === 0 ? [] : entries.map((entry) => ) + entries.length === 0 ? [] : entries.map((entry) => ) }
); @@ -19,7 +20,8 @@ const ChatLog= (props) => { ChatLog.propTypes = { // Fill with correct proptypes - entries: PropTypes.array.isRequired + entries: PropTypes.array.isRequired, + handleClick: PropTypes.func.isRequired, }; export default ChatLog;