-
Notifications
You must be signed in to change notification settings - Fork 117
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
Kunzite - Allie S. #107
base: main
Are you sure you want to change the base?
Kunzite - Allie S. #107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, Allie! You stuck with Learn's structure (ie, keeping a single source of truth with state and functions). Only real feedback I had was removal of unused code and a tweak to the ChatEntry HTML.
</main> | ||
</div> | ||
); | ||
// const [likesCount, setLikesCount] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this line of code since we aren't using it anymore
// const [likesCount, setLikesCount] = useState(0); |
const switchHeart = (updatedEntry) => { | ||
const updatedEntries = entries.map((entry) => { | ||
if (entry.id === updatedEntry.id) { | ||
// entry.liked = !entry.liked; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// entry.liked = !entry.liked; |
{/* Wave 01: Render one ChatEntry component */} | ||
|
||
{/* Wave 02: Render ChatLog component */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{/* Wave 01: Render one ChatEntry component */} | |
{/* Wave 02: Render ChatLog component */} |
liked: !props.liked, | ||
}; | ||
setLikePost(!likePost); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are updating the chat message data from entries
state using the switchHeart
. Because of this, we aren't really using likePost
or displaying it in our component.
Consider removing lines 8 and 18 completely
{/* <h2 className="entry-name">Replace with name of sender</h2> */} | ||
<h2 className="entry-name">{props.sender}</h2> | ||
<section className="entry-bubble"> | ||
{/* <p>Replace with body of ChatEntry</p> */} | ||
<p>{props.body}</p> | ||
{/* <p className="entry-time">Replace with TimeStamp component</p> */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{/* <h2 className="entry-name">Replace with name of sender</h2> */} | |
<h2 className="entry-name">{props.sender}</h2> | |
<section className="entry-bubble"> | |
{/* <p>Replace with body of ChatEntry</p> */} | |
<p>{props.body}</p> | |
{/* <p className="entry-time">Replace with TimeStamp component</p> */} | |
<h2 className="entry-name">{props.sender}</h2> | |
<section className="entry-bubble"> | |
<p>{props.body}</p> |
return ( | ||
<div className="chat-log" key={message.id}> | ||
<ChatEntry | ||
id={message.id} | ||
sender={message.sender} | ||
body={message.body} | ||
timeStamp={message.timeStamp} | ||
liked={message.liked} | ||
onUpdate={props.onUpdateHeart} | ||
></ChatEntry> | ||
</div> | ||
); | ||
}); | ||
return chatComponents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works! HTML-wise, it is creating a lot of extra div
elements that we could clean up by doing the following:
const chatComponents = entries.map((message, index) => {
return (
<ChatEntry
key={message.id}
id={message.id}
sender={message.sender}
body={message.body}
timeStamp={message.timeStamp}
liked={message.liked}
onUpdate={props.onUpdateHeart}
/>
);
});
return (
<div className="chat-log">
{chatComponents}
</div>
);
Now there is only one div
parent surrounding all the ChatEntry
components
No description provided.