Skip to content

chat log -- Yasiel#36

Open
YasielLopez wants to merge 1 commit into
Ada-C23:mainfrom
YasielLopez:main
Open

chat log -- Yasiel#36
YasielLopez wants to merge 1 commit into
Ada-C23:mainfrom
YasielLopez:main

Conversation

@YasielLopez
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work! Let me know if you have any questions on the feedback.

Comment thread src/App.jsx
};

const getTotalLikes = () => {
return messages.filter(message => message.liked).length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/App.jsx
Comment on lines +11 to +14
prevMessages.map(message =>
message.id === messageId
? { ...message, liked: !message.liked }
: message
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of map, the ternary operator, and the spread operator to simplify copying data and updating the liked value where necessary!

Comment thread src/App.jsx
Comment on lines +30 to +32
<span className="widget">
{totalLikes} ❤️s
</span>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +6 to +8
const handleLikeClick = () => {
onToggleLike(id);
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the entry.id for the key values since our messages have unique ids!


const ChatEntry = () => {
return (
<div className="chat-entry local">
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants