Skip to content

Dragonfly -- Solhee J.#32

Open
ellenjin wants to merge 3 commits intoAda-C23:mainfrom
ellenjin:main
Open

Dragonfly -- Solhee J.#32
ellenjin wants to merge 3 commits intoAda-C23:mainfrom
ellenjin:main

Conversation

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

Solhee, nice work on your React Chatlog project!

import { useState } from 'react';

const App = () => {
const [messageData, setMessageData] = useState(messagesData);

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 +9 to +18
const toggleLiked = (messageId) => {
const messages = messageData.map(message => {
if (message.id === messageId) {
return { ...message, liked: !message.liked };
} else {
return message; // message like status not changed
}
});
setMessageData(messages);
};

Choose a reason for hiding this comment

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

Great to see you 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 readability.

});
setMessageData(messages);
};
const totalLikes = messageData.filter(message => message.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>React Chatlog</h1>
<section id="heartWidget">{totalLikes} ❤️s</section>

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 +30
<ChatLog
entries={messageData}
onLikeToggle={toggleLiked}
></ChatLog>

Choose a reason for hiding this comment

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

Formatting your component like this is one way to maintain readability! ⭐️🫡

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

Choose a reason for hiding this comment

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

Nice work 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 = () => {
const ChatEntry = ({id, sender, body, timeStamp, liked, onLikeToggle}) => {

Choose a reason for hiding this comment

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

Suggested change
const ChatEntry = ({id, sender, body, timeStamp, liked, onLikeToggle}) => {
const ChatEntry = ({ id, sender, body, timeStamp, liked, onLikeToggle }) => {

Comment on lines +6 to +9
const likeButtonClicked = () => {
onLikeToggle(id);
};
const heartColor = liked ? '❤️' : '🤍';

Choose a reason for hiding this comment

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

👍🏿

Comment on lines +12 to +16
<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}></TimeStamp>

Choose a reason for hiding this comment

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

🫡

<p className="entry-time">
<TimeStamp time={timeStamp}></TimeStamp>
</p>
<button className="like" onClick={likeButtonClicked}>{heartColor}</button>

Choose a reason for hiding this comment

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

The button function could also be implemented like so:

<button  className='like'  onClick={()  => likeButtonClicked(id)}>{liked  ?  '❤️':  '🤍'}</button>

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