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

Zoisite - Jackie Aponte #104

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

Zoisite - Jackie Aponte #104

wants to merge 6 commits into from

Conversation

japonte08
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! I do see a test failing. Did you get a chance to look into why it's failing?

Good work getting the local and remote conversation feature.

I made a couple suggestions about coding patterns that I think are important to recognize and follow for React.

Let me know if you have questions about my review comments.

Comment on lines +8 to +9
const localUser = chatMessages[0].sender
const remoteUser = chatMessages[1].sender

Choose a reason for hiding this comment

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

What if textMessage[0] and textMessage[1] were both messages from the same person? How else could you find a way to get the names of the senders?

const localUser = chatMessages[0].sender
const remoteUser = chatMessages[1].sender

const [chatData, setChatData] = useState(chatMessages);

Choose a reason for hiding this comment

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

👍 nice job setting up state for chat messages.

Comment on lines +25 to +30
let totalLikes = 0
for (const message of chatData) {
if (message.liked) {
totalLikes +=1
};
};

Choose a reason for hiding this comment

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

We can use the reduce method to calculate the total likes too:

  const totalLikes = () => { 
    return chatData.reduce((total, text) => {
      return text.liked ? total + 1 : total;
    }, 0)
  };

Comment on lines +41 to +42
chatData={chatData}
onUpdateChat={onUpdateChat}>

Choose a reason for hiding this comment

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

👍

Comment on lines +13 to +20
const onUpdateChat = (updatedChat) => {
const messages = chatData.map(chat => {
if (chat.id === updatedChat.id) {
return updatedChat;
} else {
return chat;
}
});

Choose a reason for hiding this comment

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

Rather than receiving a new entry with it's like status already changed here, rewrite this method to accept only an id. The logic about how to copy the message and change the liked status would be better if it was written in App.js, since the state must have all the information necessary to make a new message.

const onUpdateChat = id => {
const messages = chatData.map(chat => {
      if (chat.id === id){
        return {...chat, liked: !chat.liked};
      } 
      else {
        return chat;
      }
    });

Comment on lines +10 to +24
const ChatLogEntries = props.chatData.map((entry) => {
return (
<div key={entry.id}>
<ChatEntry
id={entry.id}
sender={entry.sender}
timeStamp={entry.timeStamp}
body={entry.body}
liked={entry.liked}
onUpdateChat={props.onUpdateChat}
chatEntry={entry.sender===props.chatData[0].sender ? 'chat-entry local' : 'chat-entry remote'}
></ChatEntry>
</div>
);
});

Choose a reason for hiding this comment

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

Small note that variables don't begin with a capital letter. The prop key should go on each ChatEntry, not on the entire div. When you have an array of components (like you have an array of ChatEntries), each component in the array gets a prop key.

Also, instead of writing a method ChatLogEntries to reference the return value from calling map() on props.chatData, it's more common to directly iterate over the chat entries in your component like this without using a variable:

const ChatLog = (props) => {
    return (
     <div>
        {props.entries.map((message) => (
            <ChatEntry 
                key={entry.id} // the key should go on each ChatEntry
                id={entry.id}
                sender={entry.sender}
                body={entry.body}
                timeStamp={entry.timeStamp}
                liked={entry.liked}
                onUpdateChat={props.onUpdateChat}
            />
        ))}
    </div>
    )
};

The logic on line 20 to determine the class name for remote or local should live in ChatEntry.js I think you can omit line 20 completely and have this logic live in the child component. I think this because each child component should know who its sender is and thus should be in charge of determining the class.

Comment on lines +10 to +24
const updatedChat = {
id: props.id,
sender: props.sender,
body: props.body,
timeStamp: props.timeStamp,
liked: !props.liked
};

props.onUpdateChat(updatedChat);
};

const heartColor = props.liked ? '❤️' : '🤍';

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className={props.chatEntry}>

Choose a reason for hiding this comment

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

Instead of getting the class 'remote' or 'local' from props, we can calculate it here.

<div className={props.sender === 'Estragon' ? 'chat-entry remote' : 'chat-entry local'}>

Comment on lines +36 to +40
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool,
onUpdateChat: PropTypes.func.isRequired

Choose a reason for hiding this comment

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

The PropType check is missing id and chatEntry that are passed into each ChatEntry component on lines 14 and 20 of ChatLog.js

Comment on lines +9 to +19
const onLikeButtonClick = () => {
const updatedChat = {
id: props.id,
sender: props.sender,
body: props.body,
timeStamp: props.timeStamp,
liked: !props.liked
};

props.onUpdateChat(updatedChat);
};

Choose a reason for hiding this comment

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

When you just pass in an id to props.onUpdateChat(), then this method can be refactored to just be one line:

const onLikeButtonClick = () => {
    props.onUpdateChat(props.id);
};

import PropTypes from 'prop-types';

const ChatEntry = (props) => {
const timeEntry=props.timeStamp

Choose a reason for hiding this comment

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

Nitpick - there should be whitespace around the equal sign. When we pass props to a component, then by convention we should omit the spaces around the equal sign, but when we're declaring variables we should have them.

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