Skip to content

Dragonflies - Malik#27

Open
malikelmessiry wants to merge 5 commits intoAda-C23:mainfrom
malikelmessiry:main
Open

Dragonflies - Malik#27
malikelmessiry wants to merge 5 commits intoAda-C23:mainfrom
malikelmessiry:main

Conversation

@malikelmessiry
Copy link

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.

Malik, great work on your React Chatlog! ⭐️

Comment on lines +11 to +19
function toggleLike(id) {
const updatedEntries = entries.map(entry => {
if (entry.id === id) {
return { ...entry, liked: !entry.liked }
}
return entry;
});
setEntries(updatedEntries);
};

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(entries.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 some kind of readability.

setEntries(updatedEntries);
};

const totalLikes = entries.filter(entry => entry.liked).length;

Choose a reason for hiding this comment

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

You could also do this with the reduce method like so:

const  totalLikes  =  chatMessages.reduce((count,  message)  =>  count  + (message.liked ? 1 : 0),  0);

<header>
<h1>Application title</h1>
<h1>Chat Between Vladimir and Estragon</h1>
<h3>{totalLikes} ❤️s</h3>

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={entries} onToggleLike={toggleLike} />

Choose a reason for hiding this comment

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

🫡

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 propTypes from 'prop-types';

const ChatEntry = () => {
const ChatEntry = ({ id, sender, body, timeStamp, liked, onToggleLike }) => {

Choose a reason for hiding this comment

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

Nice work de-structuring your props! ⭐️

Comment on lines +7 to +10
const localOrRemote = sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote';

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

Choose a reason for hiding this comment

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

⭐️

Comment on lines +21 to +23
};

export default ChatLog; No newline at end of file

Choose a reason for hiding this comment

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

You didn’t include prop types for this component. While PropTypes is deprecated in React v19, it's still important to ensure consistent type safety across your application. Recall that React encourages you to adopt a type system like TypeScript to prevent type-related bugs and improve code reliability. @malikelmessiry

Comment on lines +24 to +28
sender: propTypes.string.isRequired,
body: propTypes.string.isRequired,
timeStamp: propTypes.string.isRequired,
liked: propTypes.bool.isRequired,
onToggleLike: propTypes.func

Choose a reason for hiding this comment

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

⭐️

Suggested change
sender: propTypes.string.isRequired,
body: propTypes.string.isRequired,
timeStamp: propTypes.string.isRequired,
liked: propTypes.bool.isRequired,
onToggleLike: propTypes.func
sender: propTypes.string.isRequired,
body: propTypes.string.isRequired,
timeStamp: propTypes.string.isRequired,
liked: propTypes.bool.isRequired,
onToggleLike: propTypes.func.isRequired

Comment on lines +11 to +15
<h2 className="entry-name">{sender}</h2>
<section className="entry-bubble">
<p>Replace with body of ChatEntry</p>
<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<p>{body}</p>
<p className="entry-time">
<TimeStamp time={timeStamp} />

Choose a reason for hiding this comment

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

Great job on interpolating your JS (props) into your JSX object return body and leveraging your TimeStamp component!

<p className="entry-time">
<TimeStamp time={timeStamp} />
</p>
<button className="like" onClick={() => onToggleLike(id)}>{liked ? '❤️' : '🤍'}</button>

Choose a reason for hiding this comment

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

👍🏿

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