Skip to content

Crow -Sophie#35

Open
SophieQA wants to merge 4 commits intoAda-C24:mainfrom
SophieQA:main
Open

Crow -Sophie#35
SophieQA wants to merge 4 commits intoAda-C24:mainfrom
SophieQA:main

Conversation

@SophieQA
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mikellewade mikellewade left a comment

Choose a reason for hiding this comment

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

@SophieQA, overall great work on your React Chatlog. I only had a few points of feedback.

Comment thread src/App.jsx


const App = () => {
const [entries, setEntries] = useState(messages);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/App.jsx
Comment on lines +10 to +12
const toggleLiked = (id) => {
setEntries((prev) => prev.map((m) => (m.id === id ? { ...m, liked: !m.liked } : m)));
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The only piece of feedback I have here is that your naming for the message object, m, is not descriptive of the data that it is holding. This will give room to miscommunication and require more cognitive load on the reader's part to decipher what the shape of the object is. I would suggest for you to choose a name more descriptive like message.

Comment thread src/App.jsx
setEntries((prev) => prev.map((m) => (m.id === id ? { ...m, liked: !m.liked } : m)));
};

const likeCount = entries.filter((m) => m.liked).length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You'll see that there are a number of ways to implement this logic. Though this is functionally sound, I will say that if I see the .filter method I would assume that you would be working an array of data more in-depth. For simply counting the number of liked messages I would opt for something like .reduce instead.

Find more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

Comment thread src/App.jsx
<div id="App">
<header>
<h1>Application title</h1>
<div className="likes-count">{likeCount} ❤️s</div>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/App.jsx
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={entries} onToggleLiked={toggleLiked} />
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment on lines +27 to +38
ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,
})
).isRequired,
onToggleLiked: PropTypes.func.isRequired,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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


return (
<section className="chat-log">
{chatEntries}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

import TimeStamp from './TimeStamp';

const ChatEntry = () => {
const ChatEntry = ({ id, sender, body, timeStamp, liked, onToggleLiked }) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent formatting.

Comment on lines +26 to +31
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool,
onToggleLiked: PropTypes.func,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great work on these proptypes, remember that they have been sunsetted in React and that will be using other type checking frameworks like Typescript.

</p>
<button
className="like"
onClick={() => onToggleLiked && onToggleLiked(id)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@SophieQA, not sure why you have onToggleLiked && onToggleLiked(id) as the return value here. You are essentially writing a function that returns true. Simply need to have a function to receive the automatically passed in event and then make a call to onToggleLiked with the appropriate id. You can remove the onToggleLiked function object.

Suggested change
onClick={() => onToggleLiked && onToggleLiked(id)}
onClick={() => onToggleLiked(id)}

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