Skip to content

Possum - Amanda Thompson#29

Open
tthoaman wants to merge 1 commit intoAda-C24:mainfrom
tthoaman:main
Open

Possum - Amanda Thompson#29
tthoaman wants to merge 1 commit intoAda-C24:mainfrom
tthoaman:main

Conversation

@tthoaman
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.

Great work! Let me know if you have any questions on the feedback below =]

Comment thread src/App.jsx
);
};

const likeCount = messages.filter((e) => e.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 +8 to +14
const onClickLike = (id) => {
setMessages((prevMessages) =>
prevMessages.map((entry) =>
entry.id === id ? { ...entry, liked: !entry.liked } : 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 work ensuring we're creating a new array of messages to trigger the re-render after updating the liked value!

Comment thread src/App.jsx
<h1>Application title</h1>
<h1>Chat between Vladimir and Estragon</h1>
<section>
<span className="widget" id="heartWidget">{`${likeCount} ❤️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. It's great for when we need to dynamically lookup and affect a section of a larger text, but it should not be used to represent general text on a page.

  • How does React handle this text? Do we need to dynamically look up this element and change just a part of it or is it re-rendered with the complete text each time React triggers a re-render?
  • Since this is a chunk of text on the page, what HTML element or elements would better represent this subheading with the likes count?

<p className="entry-time">
<TimeStamp time={timeStamp} />
</p>
<button className="like" onClick={() => 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.

Comment on lines +23 to +25
<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.

We can increase the accessibility of our page by setting further attributes on elements, especially interactive elements. Below is an example of updates we could make to the button, check out the MDN docs for more info!

const heart = liked ? '❤️' : '🤍';

...

<button
  onClick={() => onToggleLike(id)}
  className="like"
  aria-label={heart}
  role="img"
>
  {heart}
</button>

Comment on lines +13 to +17
const sideClass = sender === 'Vladimir' ? 'local' : 'remote';
const colorClass = sender === 'Vladimir' ? 'red' : 'green';
return (
// 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>
<article className={`chat-entry ${sideClass}`}>
<h2 className="entry-name">{sender}</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.

Great use of ternary operators and interpolated strings to set the relevant CSS!

<section className="chat-log">
{entries.map((message) => (
<ChatEntry
key={message.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.

Great use of the unique message ids for the key value!


ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({
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 Prop-Types and flagging those necessary for render with isRequired, I love the use of PropTypes.shape to ensure the passed array has the necessary contents as well!

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