Skip to content

Dragonfly - Sno Ochoa#39

Open
ra-choa wants to merge 2 commits intoAda-C23:mainfrom
ra-choa:main
Open

Dragonfly - Sno Ochoa#39
ra-choa wants to merge 2 commits intoAda-C23:mainfrom
ra-choa:main

Conversation

@ra-choa
Copy link

@ra-choa ra-choa commented Jun 26, 2025

No description provided.

Copy link

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

Your project was good, Sno! Nice work on completing React Chatlog!

Comment on lines +6 to +10
const calculateTotalLikes = (messages) => {
return messages.reduce((total, msg) => {
return total + (msg.liked ? 1 : 0);
}, 0);
};

Choose a reason for hiding this comment

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

Perfect use of the .reduce method here! I see that you moved this function outside of the App component as well. Since it isn't strongly tied to this file you could move it inside of its own utilities file. However, I think it's placement here is fine too!

};

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

Choose a reason for hiding this comment

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

Nice work on using the useState hook to initialize state for your App component.

Comment on lines +15 to +24
const toggleLike = (id) => {
const updatedMessages = messages.map((msg) => {
if (msg.id === id) {
return { ...msg, liked: !msg.liked };
} else {
return msg;
}
});
setMessages(updatedMessages);
};

Choose a reason for hiding this comment

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

Nice work on using .map to map over your entries! Very functional! Since you are using a simple conditional block here, we could make this more succinct by using a ternary instead like so:

const toggleLike = (id) =>
  setEntries(PrevEntries => PrevEntries.map(entry =>
    entry.id === id ? { ...entry, liked: !entry.liked } : entry
  ));

When you find yourself with simple checks like these, more often than not a ternary could be implemented instead for conciseness but still maintaining readability.

<header>
<h1>Application title</h1>
<h1>React Chatlog</h1>
<h2>{totalLikes} ❤️s</h2>

Choose a reason for hiding this comment

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

⭐️

<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={messages} onLikeToggle={toggleLike} />

Choose a reason for hiding this comment

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

Nice work here! 🫡 You may see conventions where you put the props for a component on separate lines like so:

<ChatLog 
entries={entries} 
onToggleLike={toggleLike} 
/>

This is one way to make components with many props more readable!

import ChatEntry from './ChatEntry';
import PropTypes from 'prop-types';

const ChatLog = (props) => {

Choose a reason for hiding this comment

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

I see that you didn't de-structure your props, this could have the benefit of readily alerting you and other developers that the data you are working with comes from the props object and should be re-assigned or mutated.

Comment on lines +9 to +17
<ChatEntry
key={msg.id}
id={msg.id}
sender={msg.sender}
body={msg.body}
timeStamp={msg.timeStamp}
liked={msg.liked}
onLikeToggle={props.onLikeToggle}
/>

Choose a reason for hiding this comment

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

Since the names of the keys on entry are the same as the names your are setting on ChatEntry attributes/you are using all of the values in entry you could do something something like this to save you a few keystrokes:

const  chatComponents  =  entries.map((entry)  =>  {
  return(
    <ChatEntry
	{...entry}
	onLikeToggle={onLikeBtnToggle}
	key={entry.id}
	/>
  );
});

Though, what you have is more verbose! The suggestion I have above can be used when we want to use pass every key/value pair to the child component. If not, then we wouldn't follow the suggested pattern since it would be passing impertinent information to a component, putting it at risk to accidentally change a piece and be more bug prone.

Comment on lines +23 to +33
ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,
})
).isRequired,
onLikeToggle: PropTypes.func.isRequired,
};

Choose a reason for hiding this comment

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

Good job on including prop types for this component! Just a quick reminder: in React v19, PropTypes are deprecated. Moving forward, it's best to use TypeScript for type checking, as it's the recommended and more robust solution for ensuring type safety across your application.

import PropTypes from 'prop-types';

const ChatEntry = (props) => {
const heart = props.liked ? '❤️' : '🤍';

Choose a reason for hiding this comment

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

🫡

Comment on lines +9 to +18
<div className='chat-entry local'>
<h2 className='entry-name'>{props.sender}</h2>
<section className='entry-bubble'>
<p>{props.body}</p>
<p className='entry-time'>
<TimeStamp time={props.timeStamp} />
</p>
<button className='like' onClick={() => props.onLikeToggle(props.id)}>
{heart}
</button>

Choose a reason for hiding this comment

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

Good! You used your props here to make your presentational component dynamic!

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

Comments