Skip to content

Conversation

@yingsgithub
Copy link

No description provided.

Copy link

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

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

Great job Ying! You passed all the tests and did a great job in developing PropTypes. I have left comments in your PR. Let me know if you have any questions!

Grade: 🟢

import ChatLog from './components/ChatLog';

const App = () => {
const [messages, setMessages] = React.useState([]);

Choose a reason for hiding this comment

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

If you add useState as an import, you wouldn't need to refer to the React object in order to use useState.

import React, { useState } from 'react';
  const [messages, setMessages] = useState([]);

Comment on lines +15 to +25
const heartToggling = (updatedMessage) => {
const updatedMessages = messages.map((message) => {
if (message.id === updatedMessage.id) {
return updatedMessage;
} else {
return message;
}
});

setMessages(updatedMessages);
};

Choose a reason for hiding this comment

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

Nice work managing the data and returning a brand new object!

Here's a refresher on updating state in React:

React components re-render whenever there is a change/update to state data. In this case, our data is an object and we are modifying values nested within that object.

Under the hood, React uses Object.is() to compare the previous state object with the one that's been provided viasetMessages(updatedMessages). Object.is() checks if the object has changed and more specifically if the object passed has a different reference in memory. In Javascript, changing the properties and/or values in an object does NOT change the object reference, which is why we must create a new version of our state object ( contains a copy of all the properties that weren't updated along with the properties/values that were).

Here is an article with more info: https://www.valentinog.com/blog/react-object-is/

remote = eachMessage.sender;
}
}
// console.log('App', local);

Choose a reason for hiding this comment

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

In industry, you'll be submitting PR's containing code you'd like your team members to have. In this case, is it necessary for your teammates to have this console.log ? If not, we can remove this line.

Comment on lines +35 to +41
const local = chatMessages[0].sender;
let remote;
for (const eachMessage of chatMessages) {
if (eachMessage.sender !== local) {
remote = eachMessage.sender;
}
}

Choose a reason for hiding this comment

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

Nice work differentiating the chat participants!

Comment on lines +8 to +18
// const updateMessage = (updatedMessage) => {
// //update only the current message
// const allMessages = [...props.messages];
// allMessages[index] = updatedMessage;
// props.setMessages(allMessages);
// };

//optional: decide local and remote~~~~~~~~~~~~~
// console.log('Log', props.local);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Choose a reason for hiding this comment

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

Please remove commented-out code in future PR's. This work could exist in a local branch.

let pastYear = parseInt(props.timeStamp.slice(0, 4));
// console.log(pastYear);
const agoTime = currentYear - pastYear;
console.log(props.sender);

Choose a reason for hiding this comment

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

Be sure to remove all print statements/console logs in PRs. Anything that we do locally to test our code should be left out of PRs.

Comment on lines +7 to +10
let currentYear = new Date().getFullYear();
let pastYear = parseInt(props.timeStamp.slice(0, 4));
// console.log(pastYear);
const agoTime = currentYear - pastYear;

Choose a reason for hiding this comment

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

Good work finding the year sent.

import "@testing-library/jest-dom/extend-expect";
import ChatLog from "./ChatLog";
import { render, screen } from "@testing-library/react";
import React from 'react';

Choose a reason for hiding this comment

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

Good catch on changing the single quotes! ESLinters are really finicky about style rules!

Comment on lines 56 to 63
ChatEntry.propTypes = {
//Fill with correct proptypes
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool,
heartToggling: PropTypes.func.isRequired,
};

Choose a reason for hiding this comment

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

👍

Comment on lines +14 to +33
const handleHeartClick = () => {
const messageUpdated = {
id: props.id,
sender: props.sender,
body: props.body,
timeStamp: props.timeStamp,
liked: !props.liked,
};
props.heartToggling(messageUpdated);
};

const button = props.liked ? (
<button onClick={handleHeartClick} className="like">
❤️
</button>
) : (
<button onClick={handleHeartClick} className="like">
🤍
</button>
);

Choose a reason for hiding this comment

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

Great work constructing the event handler and using conditional rendering to change the heart icon!

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