From f30a0894a59edad036953e7ae19beed570335743 Mon Sep 17 00:00:00 2001 From: vlada Date: Sun, 15 Dec 2024 20:09:41 -0800 Subject: [PATCH 1/4] completed wave 1 --- src/App.jsx | 8 ++++++-- src/components/ChatEntry.jsx | 14 +++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..315c70c59 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,5 @@ import './App.css'; +import ChatEntry from './components/ChatEntry'; const App = () => { return ( @@ -7,8 +8,11 @@ const App = () => {

Application title

- {/* Wave 01: Render one ChatEntry component - 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 15c56f96b..21b80e134 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,12 +1,14 @@ +import PropTypes from 'prop-types'; import './ChatEntry.css'; +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 +16,9 @@ const ChatEntry = () => { }; ChatEntry.propTypes = { - // Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.elementType.isRequired, }; export default ChatEntry; From 674d76ddd1b351ce8452dbae3d4cc273670ef26b Mon Sep 17 00:00:00 2001 From: vlada Date: Sun, 15 Dec 2024 20:46:29 -0800 Subject: [PATCH 2/4] completed wave 2 --- src/App.jsx | 5 +++-- src/components/ChatLog.jsx | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 315c70c59..2f09dd101 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,5 +1,6 @@ import './App.css'; -import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; +import messages from './data/messages.json'; const App = () => { return ( @@ -11,7 +12,7 @@ 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..dab3cb0c6 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,24 @@ +import PropTypes from 'prop-types'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + +const ChatLog = ({entries}) => { + return ( +
+ {entries.map((entry) => ( + + ))} +
+ ); +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf(PropTypes.elementType.isRequired), +}; + +export default ChatLog; From e5ab60baa1c5dcec5efe23ddd73b7206d3ae4a19 Mon Sep 17 00:00:00 2001 From: vlada Date: Sun, 15 Dec 2024 21:43:29 -0800 Subject: [PATCH 3/4] completed wave3 --- src/App.jsx | 21 ++++++++++++++++++--- src/components/ChatEntry.jsx | 19 +++++++++++++++++-- src/components/ChatLog.jsx | 6 +++++- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 2f09dd101..6adcfd7b6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,18 +1,33 @@ +import { useState } from 'react'; import './App.css'; import ChatLog from './components/ChatLog'; import messages from './data/messages.json'; const App = () => { + const [counter, setCounter] = useState(0); // Initial counter set to 0 + + const onLike = () => { + setCounter((prevCounter) => prevCounter + 1); + }; + + const onUnlike = () => { + setCounter((prevCounter) => prevCounter - 1); + }; + + const likes = counter + ' ❤️s'; + return (
+

{likes}

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 21b80e134..8b84d9f22 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,15 +1,28 @@ +import { useState } from 'react'; import PropTypes from 'prop-types'; import './ChatEntry.css'; import TimeStamp from './TimeStamp'; -const ChatEntry = ({sender, body, timeStamp}) => { +const ChatEntry = ({sender, body, timeStamp, onLike, onUnlike}) => { + const [buttonText, setButtonText] = useState('🤍'); + + const onLikeClick = () => { + if (buttonText === '🤍') { + setButtonText('❤️'); + onLike(); + } else { + setButtonText('🤍'); + onUnlike(); + } + }; + return (

{sender}

{body}

- +
); @@ -19,6 +32,8 @@ ChatEntry.propTypes = { sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.elementType.isRequired, + onLike: PropTypes.func.isRequired, + onUnlike: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index dab3cb0c6..2c5147e39 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -2,7 +2,7 @@ import PropTypes from 'prop-types'; import './ChatLog.css'; import ChatEntry from './ChatEntry'; -const ChatLog = ({entries}) => { +const ChatLog = ({entries, onLike, onUnlike}) => { return (
{entries.map((entry) => ( @@ -11,6 +11,8 @@ const ChatLog = ({entries}) => { sender={entry.sender} body={entry.body} timeStamp={entry.timeStamp} + onLike={onLike} + onUnlike={onUnlike} /> ))}
@@ -19,6 +21,8 @@ const ChatLog = ({entries}) => { ChatLog.propTypes = { entries: PropTypes.arrayOf(PropTypes.elementType.isRequired), + onLike: PropTypes.func.isRequired, + onUnlike: PropTypes.func.isRequired, }; export default ChatLog; From 2a0a40ecbbd6508617e10885b7a1a65cce7dfe4b Mon Sep 17 00:00:00 2001 From: vlada Date: Sun, 15 Dec 2024 21:59:57 -0800 Subject: [PATCH 4/4] updated chatlog prop --- src/components/ChatLog.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 2c5147e39..261533daa 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -20,7 +20,13 @@ const ChatLog = ({entries, onLike, onUnlike}) => { }; ChatLog.propTypes = { - entries: PropTypes.arrayOf(PropTypes.elementType.isRequired), + entries: PropTypes.arrayOf( + PropTypes.shape({ + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.node.isRequired, + }).isRequired + ).isRequired, onLike: PropTypes.func.isRequired, onUnlike: PropTypes.func.isRequired, };