Skip to content

C22 Sphinx Somy Cho #34

Open
PickledData wants to merge 3 commits intoAda-C22:mainfrom
PickledData:main
Open

C22 Sphinx Somy Cho #34
PickledData wants to merge 3 commits intoAda-C22:mainfrom
PickledData:main

Conversation

@PickledData
Copy link
Copy Markdown

Chatlog- React

Copy link
Copy Markdown

@mikellewade mikellewade left a 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!

Comment on lines +9 to +17
const handleLikeToggle = (id) => {
setChatMessages((prevMessages) =>
prevMessages.map((message) =>
message.id === id
? { ...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.

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 totalLikes = chatMessages.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.

You could also do this with the reduce method like so:

const totalLikes = chatMessages.reduce((count, message) => count + (message.liked ? 1 : 0), 0);

Comment on lines +20 to +21
const person1 = messages[0].sender;
const person2 = messages[1].sender;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens here if the first two messages from are texts from the same person?

Comment on lines +32 to +33
entries={chatMessages}
onToggleLike={handleLikeToggle}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⭐️

const chatEntryComponents = entries.map((entry) => {
return (
<ChatEntry
id={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.

⭐️

Comment on lines +9 to +13
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
liked={entry.liked}
Copy link
Copy Markdown

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}
      />
    );
  });

Just be mindful that this isn't as explicit as what you have.

Comment on lines +28 to +37
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,
onToggleLike: PropTypes.func.isRequired,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⭐️

Comment on lines +21 to +26
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,
onToggleLike: PropTypes.func.isRequired,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment on lines +10 to +14
<p>{body}</p>
<p className="entry-time">
<TimeStamp time={timeStamp}/>
</p>
<button className="like" onClick={() => onToggleLike(id)}>{liked ? '❤️' : '🤍'}</button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No notes, nice!

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className= {`chat-entry ${liked ? 'liked' :'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.

Not sure if this ternary is a mistake or not, seems like the liked part is messing up some of the CSS?

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