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

Shelby Faulconer, Sea Turtles, C17 #99

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

Conversation

pickled-bot
Copy link

No description provided.

Copy link

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

First React project down! 🎉 I've left some feedback & suggestions, please take a look when you have time & reach out if there's anything I can clarify 😄

Comment on lines +25 to +33
const countLikes = () => {
let counter = 0;
for (let entry of entries) {
if (entry.liked) {
counter += 1;
};
};
return counter;
};

Choose a reason for hiding this comment

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

Great use of the existing data to calculate the total likes! Another option would be to use the array function reduce:

    return messageData.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 on lines +13 to +19
return {
id: entry.id,
sender: entry.sender,
body: entry.body,
timeStamp: entry.timeStamp,
liked: !entry.liked
};

Choose a reason for hiding this comment

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

Nice managing of data & making sure we make a new object when we need to alter a message in our list!

A best practice for copying over an object's values is to use the spread operator, then overwrite any key/value pairs we want to change:

// Use the spread operator to copy all of entry's values to a new object, 
// then overwrite the attribute liked with the opposite of entry's liked value
return {
    ...entry, 
    liked: !entry.liked
}

Comment on lines +7 to +8
const heartIcon = (props.liked) ? '❤️' : '🤍';
const messageAlign = (props.sender === 'Vladimir') ? 'remote' : 'local';

Choose a reason for hiding this comment

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

Ternary operators! 🎉

<button className="like">🤍</button>
<p>{props.body}</p>
<p className="entry-time"><TimeStamp time={props.timeStamp}/></p>
<button className="like" onClick={() => {props.setLiked(props.id)}}>{heartIcon}</button>

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 props.setLiked since it keeps all the state management and message object creation confined to App.

Comment on lines +22 to +26
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,

Choose a reason for hiding this comment

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

Nice use of Prop-Types and flagging those necessary for render with isRequired!. To help our future selves (or other folks we're working with) easily see what is allowed to be passed when creating an instance of a component, I suggest including all props that can be passed in, including functions such as setLiked.

Comment on lines +22 to +26
);
};

ChatLog.propTypes = {
entries: PropTypes.arrayOf(PropTypes.object).isRequired,

Choose a reason for hiding this comment

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

We can be even more specific with our PropTypes for validation. If we know that we need an array, and that array's objects need to hold certain data, we can check the objects as well! Inside arrayOf we can pass PropTypes.shape() with information about the object's shape. A modified example from stack overflow is below:

list: PropTypes.arrayOf(
    PropTypes.shape({
        id: PropTypes.number.isRequired,
        customTitle: PropTypes.string.isRequired,
        btnStyle:PropTypes.object,
    })
).isRequired,

Source: https://stackoverflow.com/questions/59038307/reactjs-proptypes-validation-for-array-of-objects

Similar to some of the feedback for ChatEntry's PropTypes, it would be good to list the function ChatLog accepts here 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