Skip to content

Possum-Divya#30

Open
divya42536 wants to merge 3 commits intoAda-C24:mainfrom
divya42536:main
Open

Possum-Divya#30
divya42536 wants to merge 3 commits intoAda-C24:mainfrom
divya42536:main

Conversation

@divya42536
Copy link
Copy Markdown

No description provided.

import PropTypes from 'prop-types';

const ChatEntry = () => {
const ChatEntry = ({ id, sender, body, timeStamp, liked, onLike }) => {
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 job destructuring your props.

Destructuring props also has some benefits:

  • you know every possible prop right away.
  • you know when a prop is being unused, in order to remove it.
  • knowing which props are being used will also remind you what you need to validate

// Replace the outer tag name with a semantic element that fits our use case
<replace-with-relevant-semantic-element className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className="chat-entry">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It was an optional enhancement, but how could you determine if a chat was from a 'local' sender vs a 'remote' sender so that the chat bubbles would have different styles applied to it?

If you have time to re-visit this project for React.js review, it would be good practice to try applying local vs. remote classes to the components so they render differently depending on who sent the message.

<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<p>{body}</p>
<p className="entry-time"><TimeStamp time={timeStamp}></TimeStamp></p>
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 job using the provided TimeStamp component.

onLike={onLike}
/>
))}
</ul>
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 use the ul element here. The children of the ul element are li, but your project does not use any li elements.

This isn't a semantic use of the ul element since it doesn't include li.

Consider using a different element like a section element.

timeStamp={entry.timeStamp}
liked={entry.liked}
onLike={onLike}
/>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Another common way you'll see components organized using map is to store the result into a variable we use in the JSX result:

  const chatEntries = entries.map((entry) => {
    return (
      <ChatEntry
        // your props
      />
    );
  });

  return <div>{chatEntries}</div>;

Comment thread src/App.jsx
Comment on lines +17 to +18
setEntryData(preventryData =>
preventryData.map(entry =>
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 job using the callback-style for updating the state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your variable name has a small issue with camelCase

Suggested change
setEntryData(preventryData =>
preventryData.map(entry =>
setEntryData(prevEntryData =>
prevEntryData.map(entry =>

Comment thread src/App.jsx
};

const countTotalLikes = (entryData) => {
return entryData.reduce((total, entry) => total + (entry.liked ? 1 : 0), 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👀 Notice that you calculate the value of the total likes by checking if the liked attribute for an entry is true or false. Therefore, your message objects do not need a likeCount attribute (like what you added in messages.json).

Comment thread src/App.jsx
<header>
<h1>Application title</h1>
<h1>Chat between Vladimir and Estragon</h1>
<h2>{totalLikes} ❤️s</h2>
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 directly invoke countTotalLikes here, instead of creating the variable totalLikes on line 25.

Suggested change
<h2>{totalLikes} ❤️s</h2>
<h2>{countTotalLikes(entryData)} ❤️s</h2>

Comment thread src/App.jsx
<div id="App">
<header>
<h1>Application title</h1>
<h1>Chat between Vladimir and Estragon</h1>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you think of a way to dynamically get the senders' names without hardcoding "Vladimir" and "Estragon" here?

Comment thread src/App.jsx
return { ...entry, liked: !entry.liked };
};

const countTotalLikes = (entryData) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A more descriptive name for this function might be getTotalLikes which would convey to others that this function returns a total count of the likes.

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