From 6b514a1ad6a36af0377965a38a99dfd6fae9141f Mon Sep 17 00:00:00 2001 From: alyssa Date: Fri, 14 Jul 2023 16:28:04 -0500 Subject: [PATCH 1/6] rendered an example of a chat entry --- src/App.js | 11 +++++++++-- src/components/ChatEntry.js | 10 +++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index c10859093..4024a298f 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,23 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatEntry from './components/ChatEntry'; const App = () => { + + const exampleMessage = chatMessages[0] + return (

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.js b/src/components/ChatEntry.js index b92f0b7b2..5a253c7b9 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,14 +1,15 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

+

{props.body}

+

{}

@@ -16,6 +17,9 @@ const ChatEntry = (props) => { }; ChatEntry.propTypes = { + sender: PropTypes.string, + body: PropTypes.string, + timeStamp: PropTypes.instanceOf(Date), //Fill with correct proptypes }; From 29cc1f26fd0ce34144f6d30c8dc439d2f4447353 Mon Sep 17 00:00:00 2001 From: alyssa Date: Fri, 14 Jul 2023 18:40:22 -0500 Subject: [PATCH 2/6] created and rendered ChatLog component --- src/App.js | 6 ++++-- src/components/ChatEntry.js | 8 +++++--- src/components/ChatLog.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/components/ChatLog.js diff --git a/src/App.js b/src/App.js index 4024a298f..3b4b32c21 100644 --- a/src/App.js +++ b/src/App.js @@ -2,10 +2,11 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; const App = () => { - const exampleMessage = chatMessages[0] + // const exampleMessage = chatMessages[0] return (
@@ -16,7 +17,8 @@ const App = () => { { /* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */ - + + // }
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 5a253c7b9..4097ad84c 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -17,9 +17,11 @@ const ChatEntry = (props) => { }; ChatEntry.propTypes = { - sender: PropTypes.string, - body: PropTypes.string, - timeStamp: PropTypes.instanceOf(Date), + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, //Fill with correct proptypes }; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..c3f8b45a3 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,32 @@ +import React from 'react'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; + +const ChatLog = (props) => { + const chatEntries = props.entries.map(entry => { + return ( + + ) + }) + + return ( +
+ {chatEntries} +
+ ) +}; + + +ChatLog.propTypes = { + entries: PropTypes.array.isRequired, +}; + +export default ChatLog; \ No newline at end of file From 24d876bb39a03be7687cd1dca55efa547e719613 Mon Sep 17 00:00:00 2001 From: alyssa Date: Sun, 16 Jul 2023 20:17:46 -0500 Subject: [PATCH 3/6] first working implementation for liking messages --- src/App.js | 24 ++++++++++++++++++++---- src/components/ChatEntry.js | 4 +++- src/components/ChatLog.js | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index 3b4b32c21..c8c9d5982 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,39 @@ -import React from 'react'; +import React, {useState} from 'react'; import './App.css'; import chatMessages from './data/messages.json'; import ChatEntry from './components/ChatEntry'; import ChatLog from './components/ChatLog'; const App = () => { + const [messages, setMessages] = useState(chatMessages) + + const handleLike = id => { + setMessages(prevMessages => { + return prevMessages.map(message => { + if (id === message.id) { + return { + ...message, + liked: !message.liked + }; + } + return message; + }) + }) + } - // const exampleMessage = chatMessages[0] + const totalLikes = messages.filter(entry => entry.liked).length return (
-

Application title

+

Chat Log

+

{totalLikes} ❤️'s

{ /* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */ - + // }
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 4097ad84c..a2d523b88 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -4,13 +4,15 @@ import PropTypes from 'prop-types'; import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { + const heartFill = props.liked ? '❤️' : '🤍'; + return (

{props.sender}

{props.body}

{}

- +
); diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index c3f8b45a3..d14cbdedd 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -13,6 +13,7 @@ const ChatLog = (props) => { body={entry.body} timeStamp={entry.timeStamp} liked={entry.liked} + handleLike={props.handleLike} /> ) }) From 806829442afb2dd2e49f545f93efc761cc5487fe Mon Sep 17 00:00:00 2001 From: alyssa Date: Sun, 16 Jul 2023 20:21:37 -0500 Subject: [PATCH 4/6] changed emoji to pass tests --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index c8c9d5982..dd3d93ccb 100644 --- a/src/App.js +++ b/src/App.js @@ -27,7 +27,7 @@ const App = () => {

Chat Log

-

{totalLikes} ❤️'s

+

{totalLikes} ❤️s

{ From a0190eccb7bedd5ffa629b57db964fbffb015bdc Mon Sep 17 00:00:00 2001 From: alyssa Date: Sun, 16 Jul 2023 20:37:40 -0500 Subject: [PATCH 5/6] edited Prop Types --- src/App.js | 3 --- src/components/ChatEntry.js | 2 +- src/components/ChatLog.js | 9 ++++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index dd3d93ccb..2e5cf0254 100644 --- a/src/App.js +++ b/src/App.js @@ -31,10 +31,7 @@ const App = () => {
{ - /* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */ - // }
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index a2d523b88..d03f88024 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -24,7 +24,7 @@ ChatEntry.propTypes = { body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, liked: PropTypes.bool.isRequired, - //Fill with correct proptypes + handleLike: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index d14cbdedd..ec4a4ebae 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -27,7 +27,14 @@ const ChatLog = (props) => { ChatLog.propTypes = { - entries: PropTypes.array.isRequired, + 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, + })), + handleLike: PropTypes.func.isRequired, }; export default ChatLog; \ No newline at end of file From 2b4ec3988eb2b238498c52fb613dfbdeaa3a9147 Mon Sep 17 00:00:00 2001 From: alyssa Date: Sun, 16 Jul 2023 20:53:17 -0500 Subject: [PATCH 6/6] fixed an issue with map and unique keys --- src/components/ChatLog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index ec4a4ebae..a756df6e3 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -7,7 +7,7 @@ const ChatLog = (props) => { const chatEntries = props.entries.map(entry => { return (