From d97429591ee2c5729fae8fb884148ea861184e8c Mon Sep 17 00:00:00 2001 From: Paige Date: Fri, 21 Jul 2023 14:19:01 -0400 Subject: [PATCH 1/3] logs are logging --- src/App.js | 25 +++++++++++++++++++---- src/components/ChatEntry.css | 3 ++- src/components/ChatEntry.js | 24 +++++++++++++++++----- src/components/ChatLog.js | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 src/components/ChatLog.js diff --git a/src/App.js b/src/App.js index c10859093..7c86fdf72 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,33 @@ -import React from 'react'; +import React, {useState} from 'react'; import './App.css'; +import ChatLog from './components/ChatLog'; import chatMessages from './data/messages.json'; + const App = () => { + const [chatEntries, setChatEntries] = useState(chatMessages) + + // this works bc we are setting the state of the page in like 21 which will rerender the page(app component) everytime the buttone is pressed. + const likeCount = chatEntries.filter((entry) => entry.liked).length + + const updateLike = (chatEntryId) => { + const updatedEntries = chatEntries.map((entry) => { + if (entry.id === chatEntryId) { + entry.liked = !entry.liked; + } + return entry; + }) + + setChatEntries(updatedEntries); + } + return (
-

Application title

+

Chat 🪵 {likeCount}

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa44..d0e8d6539 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -97,4 +97,5 @@ button { .chat-entry.remote .entry-bubble:hover::before { background-color: #a9f6f6; -} \ No newline at end of file +} + diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..bfe9db8ce 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,36 @@ import React from 'react'; +// import TimeStamp from './TimeStamp'; import './ChatEntry.css'; import PropTypes from 'prop-types'; const ChatEntry = (props) => { + const heart = props.liked ? '🤍' : '❤️'; + console.log(heart) + + const handleLikeButton = () => { + props.updateLike(props.id); + }; + return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

{props.timeStamp}

+
); }; 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, + updateLike: PropTypes.func.isRequired, + // likeDecrease: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..b6816b4ae --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,39 @@ +import React from 'react'; +import ChatEntry from './ChatEntry'; +import TimeStamp from './TimeStamp'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + return ( + + ) +} + +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, + // likeDecrease: PropTypes.func.isRequired, + updateLike: PropTypes.func.isRequired, +} + +export default ChatLog; \ No newline at end of file From dd3489f7b2539a953ed72f4a7581c5b418525461 Mon Sep 17 00:00:00 2001 From: Paige Date: Sun, 30 Jul 2023 12:58:06 -0400 Subject: [PATCH 2/3] resolved all pull comments --- src/App.js | 5 ++--- src/components/ChatEntry.js | 4 +--- src/components/ChatLog.js | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/App.js b/src/App.js index 7c86fdf72..ac469d331 100644 --- a/src/App.js +++ b/src/App.js @@ -7,13 +7,12 @@ import chatMessages from './data/messages.json'; const App = () => { const [chatEntries, setChatEntries] = useState(chatMessages) - // this works bc we are setting the state of the page in like 21 which will rerender the page(app component) everytime the buttone is pressed. const likeCount = chatEntries.filter((entry) => entry.liked).length const updateLike = (chatEntryId) => { const updatedEntries = chatEntries.map((entry) => { if (entry.id === chatEntryId) { - entry.liked = !entry.liked; + return { ...entry, liked: !entry.liked}; } return entry; }) @@ -24,7 +23,7 @@ const App = () => { return (
-

Chat 🪵 {likeCount}

+

Chat 🪵 {likeCount} 🤍s

diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index bfe9db8ce..bdcaafd12 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -5,7 +5,6 @@ import PropTypes from 'prop-types'; const ChatEntry = (props) => { const heart = props.liked ? '🤍' : '❤️'; - console.log(heart) const handleLikeButton = () => { props.updateLike(props.id); @@ -16,7 +15,7 @@ const ChatEntry = (props) => {

{props.sender}

{props.body}

-

{props.timeStamp}

+

{props.timeStamp} years ago

@@ -30,7 +29,6 @@ ChatEntry.propTypes = { timeStamp: PropTypes.string.isRequired, liked: PropTypes.bool.isRequired, updateLike: PropTypes.func.isRequired, - // likeDecrease: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index b6816b4ae..ccb2ec33a 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -1,6 +1,5 @@ import React from 'react'; import ChatEntry from './ChatEntry'; -import TimeStamp from './TimeStamp'; import './ChatLog.css'; import PropTypes from 'prop-types'; @@ -13,7 +12,7 @@ const ChatLog = (props) => { id={entry.id} sender={entry.sender} body={entry.body} - timeStamp={entry.time} + timeStamp={entry.timeStamp} liked={entry.liked} updateLike={props.updateLike} /> From 6d46e9e15f1780517412ef584e3ff015346dff8f Mon Sep 17 00:00:00 2001 From: Paige Date: Sun, 30 Jul 2023 13:25:11 -0400 Subject: [PATCH 3/3] more fixes --- src/App.js | 2 +- src/components/ChatEntry.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index ac469d331..d70fddb77 100644 --- a/src/App.js +++ b/src/App.js @@ -23,7 +23,7 @@ const App = () => { return (
-

Chat 🪵 {likeCount} 🤍s

+

Chat 🪵 {likeCount} ❤️s

diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index bdcaafd12..484910e46 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -4,7 +4,7 @@ import './ChatEntry.css'; import PropTypes from 'prop-types'; const ChatEntry = (props) => { - const heart = props.liked ? '🤍' : '❤️'; + const heart = props.liked ? '❤️' : '🤍'; const handleLikeButton = () => { props.updateLike(props.id);