Skip to content

C22 - Sphinx -Tatiana Trofimova#40

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

C22 - Sphinx -Tatiana Trofimova#40
Nerpassevera wants to merge 3 commits intoAda-C22:mainfrom
Nerpassevera:main

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

<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>

<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