Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C22 Sphinx - Aleida Vieyra #37

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

C22 Sphinx - Aleida Vieyra #37

wants to merge 5 commits into from

Conversation

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

Really good job on this project Aleida! It shows you have a good understanding of React and state!

Comment on lines +11 to +21
const toggleLikeBtnClick= (id) => {
// Refactoring to incorporate func passing state update
setEntries(entries => entries.map(entry=>{
if (entry.id == id){
return {...entry, liked: !entry.liked};
}
else{
return entry;
}
}));
};

Choose a reason for hiding this comment

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

Nice work on this function! By passing this down to your individual chat messages you are now able to have a single source of truth!

Comment on lines +13 to +19
setEntries(entries => entries.map(entry=>{
if (entry.id == id){
return {...entry, liked: !entry.liked};
}
else{
return entry;
}

Choose a reason for hiding this comment

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

Suggested change
setEntries(entries => entries.map(entry=>{
if (entry.id == id){
return {...entry, liked: !entry.liked};
}
else{
return entry;
}
setEntries(entries => entries.map(entry => {
if (entry.id == id) {
return {...entry, liked: !entry.liked};
} else {
return entry;
}

}));
};

const totalLikesCount = entries.reduce((count, entry) => (entry.liked? count+1: count), 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 function!

Comment on lines +25 to +38
const identifyAllChatMembers = () => {
const senders = [...new Set(entries.map(entry => entry.sender))];
let participant1 = '';
let participant2 = '';
for (const sender of senders) {
if (!participant1) {
participant1 = sender;
}
else if (participant1 && !participant2) {
participant2 = sender;
}
};
return `${participant1} and ${participant2}`;
};
Copy link

@mikellewade mikellewade Jan 4, 2025

Choose a reason for hiding this comment

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

Essentially we are just getting the sender values of the first and second message objects in the list of messages. Instead of looping through the messages and making a set from their senders we could simply access them and then store in a string like so:

const participant1 = entries[0].sender;
const participant2 = entries[1].sender;
const chatTitle = `${participant1} and ${participant2}`;

EDIT: I see now that your method would work in cases where the maybe the first two messages are from a single user. Double texting, I could never! haha

Comment on lines +51 to +54
<ChatLog
entries={entries}
onLikeBtnToggle={toggleLikeBtnClick}
/>

Choose a reason for hiding this comment

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

perf!

Comment on lines +6 to +14
const chatComponents = entries.map((entry) => {
return(
<ChatEntry
{...entry}
onLikeToggle={onLikeBtnToggle}
key={entry.id}
/>
);
});

Choose a reason for hiding this comment

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

okay spread syntax! 😍

Comment on lines +26 to +35
ChatLog.propTypes = {
// Implement
entries: PropTypes.arrayOf(PropTypes.shape({
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired
})).isRequired,
onLikeBtnToggle: PropTypes.func.isRequired,
};

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}/>
</p>
<button className='like' onClick={likeButtonClicked}>{liked? '❤️': '🤍'}</button>

Choose a reason for hiding this comment

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

Suggested change
<button className='like' onClick={likeButtonClicked}>{liked? '❤️': '🤍'}</button>
<button className='like' onClick={likeButtonClicked}>{liked ? '❤️': '🤍'}</button>

Copy link

@mikellewade mikellewade Jan 4, 2025

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>

Comment on lines +30 to +35
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.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.

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