Skip to content

Conversation

@mell2022
Copy link

No description provided.

Copy link

@spitsfire spitsfire 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, Melley! There's some refactoring you could do to updateLike so that it updates the count of hearts, but also updates the chatData.

If you have any questions, please let me know.

Comment on lines +12 to +14
// console.log(id, ChatData);
// console.log(like);
// console.log(id.liked);

Choose a reason for hiding this comment

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

Remember to delete any commented out code or print statements used for debugging before turning in your final submission

Suggested change
// console.log(id, ChatData);
// console.log(like);
// console.log(id.liked);

Comment on lines +17 to +19
// console.log('newMessage');
// console.log(newMessage);
// console.log(like);

Choose a reason for hiding this comment

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

Suggested change
// console.log('newMessage');
// console.log(newMessage);
// console.log(like);

import React from 'react';
import React, { useState } from 'react';
import './App.css';
// import ChatEntry from './components/ChatEntry';

Choose a reason for hiding this comment

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

Suggested change
// import ChatEntry from './components/ChatEntry';

// console.log(like);
// console.log(id.liked);

const newMessage = ChatData.find((entry) => entry.id === id);

Choose a reason for hiding this comment

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

I think we can refactor this function so we aren't iterating twice. By separating the message out here, we now lose track of where it is in the data structure. So we have to iterate through a second time to put it back in.

Let's just do everything at once inside the bottom loop.

setChatData([...ChatData]);
if (like) {
setLikeCount(likeCount + 1);
console.log('setLikeCount');

Choose a reason for hiding this comment

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

Suggested change
console.log('setLikeCount');

}
if (!like) {
setLikeCount(likeCount - 1);
console.log('setLikeCount2');

Choose a reason for hiding this comment

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

Suggested change
console.log('setLikeCount2');

Comment on lines +7 to +10
// console.log('ChatEntry');
const onLikeButtonClick = () => {
// console.log('onLikeButtonClick');
// console.log(liked);

Choose a reason for hiding this comment

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

Suggested change
// console.log('ChatEntry');
const onLikeButtonClick = () => {
// console.log('onLikeButtonClick');
// console.log(liked);
const onLikeButtonClick = () => {

Comment on lines +12 to +20
const updatedMessage = {
id: id,
body: body,
sender: sender,
timeStamp: timeStamp,
liked: !liked,
};
updateMessage(updatedMessage.id, updatedMessage.liked);
};

Choose a reason for hiding this comment

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

This works just fine, and it's an example we show in Learn.

But consider that updateMessage has been given the responsibility to update the likes, right? Let updateMessage take care of it by reassigning liked. All onLikeButtonClick should do is grab the id that updateMessage needs and pass it through.

Comment on lines +23 to +24
// console.log(likeColor);
// console.log(onLikeButtonClick);

Choose a reason for hiding this comment

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

Suggested change
// console.log(likeColor);
// console.log(onLikeButtonClick);

// console.log(newMessage);
// console.log(like);
newMessage.liked = like;
setChatData([...ChatData]);

Choose a reason for hiding this comment

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

The newMessage is never put back into chatData, so the hearts in the ChatEntry components never change color, which is why one of the Wave 3 tests doesn't pass.

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