Skip to content
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

C22 - Sphinx -Tatiana Trofimova #40

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Nerpassevera
Copy link

No description provided.

Copy link

@yangashley yangashley left a comment

Choose a reason for hiding this comment

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

Nice job on react-chatlog!

const App = () => {
const [messagesData, setMessagesData] = useState(messages);
const [likesCounter, setLikesCounter] = useState(0);

Choose a reason for hiding this comment

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

We can calculate the number of likes from messagesData. Therefore we should remove the likesCounter state. When possible, we should prefer to not use state if we can calculate whatever value instead so that we don't introduce additional, unnecessary complexity.

}
});
});
setLikesCounter( (likesCounter) => likesCounter + likeAdjustment);

Choose a reason for hiding this comment

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

Instead of using state for likesCount, we should remove this state completely.

We can create a helper function that calls reduce that can get the count of all the likes from messages, like:

const getLikedCount = () => {
  return messages.reduce((totalLikes, message) => (totalLikes + message.liked), 0);
};

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Chat between {participants.join(' and ')}</h1>
<h2 className='heartWidget'>Likes: {likesCounter}</h2>

Choose a reason for hiding this comment

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

To have this element look like the provided wireframes, you would write:

<h2 className='heartWidget'>{likesCounter()} ❤️s</h2>

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Chat between {participants.join(' and ')}</h1>

Choose a reason for hiding this comment

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

While this bit of logic isn't complex and is concise, I still think it would be nice to write a helper function and invoke the helper function here. Maybe something like getChatParticipants

const App = () => {
const [messagesData, setMessagesData] = useState(messages);
const [likesCounter, setLikesCounter] = useState(0);
const [participants, setParticipants] = useState([]);

Choose a reason for hiding this comment

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

Do we need to keep track of participants by using state? Could you render the header on line 49 without it?

We should prefer to not use state when we don't absolutely need it.

<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<p>{body}</p>
<p className="entry-time">{TimeStamp(timeStamp)}</p>

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!

Comment on lines +23 to +26
return (
<div className='chat-log'>
{feed}
</div>

Choose a reason for hiding this comment

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

Nice job capturing the return value from invoking map in the variable feed and using that variable here. This is typical of what you'd see in industry!

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