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

Solhee, nice work on your React Chatlog project!

Comment thread src/App.jsx
import { useState } from 'react';

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

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 thread src/App.jsx
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);
};
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 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.

Comment thread src/App.jsx
});
setMessageData(messages);
};
const totalLikes = messageData.filter(message => message.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 could also do this with the.reduce method like so:

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

Comment thread src/App.jsx
<header>
<h1>Application title</h1>
<h1>React Chatlog</h1>
<section id="heartWidget">{totalLikes} ❤️s</section>
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 +27 to +30
<ChatLog
entries={messageData}
onLikeToggle={toggleLiked}
></ChatLog>
Copy link
Copy Markdown

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
};
Copy link
Copy Markdown

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}) => {
Copy link
Copy Markdown

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 ? '❤️' : '🤍';
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 +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>
Copy link
Copy Markdown

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