Skip to content

Dragonfly - Olya Mateshov#34

Open
omatesh wants to merge 4 commits intoAda-C23:mainfrom
omatesh:main
Open

Dragonfly - Olya Mateshov#34
omatesh wants to merge 4 commits intoAda-C23:mainfrom
omatesh:main

Conversation

@omatesh
Copy link

@omatesh omatesh commented Jun 16, 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.

Olya, nice work on your React Chatlog project!

import ChatLog from './components/ChatLog';

const App = () => {
const [messageList, setMessageList] = useState(messagesData);

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 +19
const likeToggleFunc = (messageId) => {
const messages = messageList.map(message => {
if (message.id === messageId) {
return { ...message, liked: !message.liked };
} else {
return message;
}
});

setMessageList(messages);
};

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.

Comment on lines +21 to +23
const totalLikes = messageList
.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)  => {  
 return count  + (message.liked ? 1 : 0)
},  0);

As for the formatting, I think you could leave this code on a single since it isn't longer than 80 characters.

Suggested change
const totalLikes = messageList
.filter((message) => message.liked)
.length;
const totalLikes = messageList.filter((message) => message.liked).length;

Comment on lines +28 to +30
<h1>Chat between Vladimir and Estragon</h1>
<div>
{totalLikes} ❤️s

Choose a reason for hiding this comment

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

⭐️

Comment on lines +35 to +37
entries={messageList}
likeToggleFunc={likeToggleFunc}
localSender="Vladimir"

Choose a reason for hiding this comment

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

A couple of things here:

  • You have the data named messageList but then name the prop entries, is there a reason as to why you chose not to consistently name key in the prop object messageList? Though there is nothing technically wrong with what you have, for readability you will want to stick with consistent naming. It will help yourself and other developers keep track of what data is coming from where.

  • For your likeToggleFunc, I would name it something like onLikeToggle or onLike, this more readily communicates that the function will be used for an event.

  • You hard coded the local sender here, but what could be do to make this more dynamic? What would happen here if the messages no longer with Vladimir?

@omatesh

// Fill with correct proptypes
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
senderType: PropTypes.oneOf(['local', 'remote']).isRequired,

Choose a reason for hiding this comment

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

🫡

Comment on lines +6 to +8
const likeButtonClicked = () => {
props.likeToggleFunc(props.id);
};

Choose a reason for hiding this comment

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

⭐️

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className={props.senderType === 'local' ? 'chat-entry local' : 'chat-entry remote'}>

Choose a reason for hiding this comment

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

You could also assign this ternary logic to a variable before your return statement for readability. However, note that you have very similar logic here and in ChatLog.jsx. How could you refactor this logic to DRY up your components? @omatesh

<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<p>{props.body}</p>
<p className="entry-time">Time Sent: <TimeStamp time={props.timeStamp} /></p>

Choose a reason for hiding this comment

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

👍🏿

Comment on lines +16 to +17
<button className="like" onClick={likeButtonClicked}>
{props.liked ? '❤️' : '🤍'}

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={()  => props.likeToggleFunc(props.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