Conversation
kelsey-steven-ada
left a comment
There was a problem hiding this comment.
Really nice work! Let me know if you have any questions on the feedback.
| }; | ||
|
|
||
| const getTotalLikes = () => { | ||
| return messages.filter(message => message.liked).length; |
There was a problem hiding this comment.
Great work calculating the likes count from the chatsData! Since we don't need the contents of the array we create with filter, another option is to use a higher order function like array.reduce to take our list of messages and reduce it down to a single value.
// This could be returned from a helper function
// totalLikes is a variable that accumulates a value as we loop over each entry in chatEntries
const likesCount = chatEntries.reduce((totalLikes, currentMessage) => {
// If currentMessage.liked is true add 1 to totalLikes, else add 0
return (totalLikes += currentMessage.liked ? 1 : 0);
}, 0); // The 0 here sets the initial value of totalLikes to 0| prevMessages.map(message => | ||
| message.id === messageId | ||
| ? { ...message, liked: !message.liked } | ||
| : message |
There was a problem hiding this comment.
Great use of map, the ternary operator, and the spread operator to simplify copying data and updating the liked value where necessary!
| <span className="widget"> | ||
| {totalLikes} ❤️s | ||
| </span> |
There was a problem hiding this comment.
span is not a semantic element, so we should avoid it unless necessary for styling. Since this is a chunk of user facing text, we should use <p> and style it as we'd like with CSS.
| const handleLikeClick = () => { | ||
| onToggleLike(id); | ||
| }; |
There was a problem hiding this comment.
I like this pattern of sending just the id to onToggleLike since it keeps all the state management and message object creation confined to App.
| <section className="chat-log"> | ||
| {entries.map(entry => ( | ||
| <ChatEntry | ||
| key={entry.id} |
There was a problem hiding this comment.
Nice use of the entry.id for the key values since our messages have unique ids!
|
|
||
| const ChatEntry = () => { | ||
| return ( | ||
| <div className="chat-entry local"> |
There was a problem hiding this comment.
I know this was in the scaffold, but since div is not a semantic element, I would consider something like article as the outermost tag on a ChatEntry.
No description provided.