-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sphinx_Olga_Karaivanska #41
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Your project lets me know that you have a goo understanding of React and useState
!
const senders = Array.from(new Set(initialMessages.map(initialMessage => initialMessage.sender))); | ||
const chatHeader = `Chat between ${senders.join(' and ')}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, very concise yet still readable!
const toggleLike = (id) => { | ||
setMessages((prevMessages) => | ||
prevMessages.map((message) => | ||
message.id === id | ||
? { ...message, liked: !message.liked } | ||
: message | ||
) | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on this function! By passing this down to your individual chat messages you are now able to have a single source of truth!
const getTotalLikes = () => { | ||
return messages.filter((message) => message.liked).length; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also do this with the reduce method like so:
const totalLikes = chatMessages.reduce((count, message) => count + (message.liked ? 1 : 0), 0);
</header> | ||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<ChatLog entries={messages} toggleLike={toggleLike} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐️
|
||
const ChatEntry = () => { | ||
const ChatEntry = ({ sender, body, timeStamp, liked, onLikeToggle, type }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructing, love to see it!
sender={entry.sender} | ||
body={entry.body} | ||
timeStamp={entry.timeStamp} | ||
liked={entry.liked} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the names of the keys on entry
are the same as the names your are setting on ChatEntry
attributes/you are using all of the values in entry
you could do something something like this to save you a few keystrokes:
const chatComponents = entries.map((entry) => {
return(
<ChatEntry
{...entry}
onLikeToggle={onLikeBtnToggle}
key={entry.id}
/>
);
});
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, | ||
toggleLike: PropTypes.func.isRequired, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐️
@@ -4,188 +4,215 @@ | |||
"sender":"Vladimir", | |||
"body":"why are you arguing with me", | |||
"timeStamp":"2018-05-29T22:49:06+00:00", | |||
"liked": false | |||
"liked": false, | |||
"likeCount": 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you decided not to use the likeCount
since you noticed that we could just use liked
instead.
<p>{body}</p> | ||
<p className="entry-time"> | ||
<TimeStamp time={timeStamp} /> | ||
</p> | ||
<button className="like" onClick={onLikeToggle}> | ||
{liked ? '❤️' : '🤍'} | ||
</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
onLikeToggle: PropTypes.func.isRequired, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
No description provided.