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

Sphinx_Olga_Karaivanska #41

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

Sphinx_Olga_Karaivanska #41

wants to merge 3 commits into from

Conversation

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

Nice work! Your project lets me know that you have a goo understanding of React and useState!

Comment on lines +7 to +8
const senders = Array.from(new Set(initialMessages.map(initialMessage => initialMessage.sender)));
const chatHeader = `Chat between ${senders.join(' and ')}`;

Choose a reason for hiding this comment

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

Nice, very concise yet still readable!

Comment on lines +12 to +20
const toggleLike = (id) => {
setMessages((prevMessages) =>
prevMessages.map((message) =>
message.id === id
? { ...message, liked: !message.liked }
: message
)
);
};

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 +22 to +24
const getTotalLikes = () => {
return messages.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>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={messages} toggleLike={toggleLike} />

Choose a reason for hiding this comment

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

⭐️


const ChatEntry = () => {
const ChatEntry = ({ sender, body, timeStamp, liked, onLikeToggle, type }) => {

Choose a reason for hiding this comment

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

Destructing, love to see it!

Comment on lines +13 to +16
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
liked={entry.liked}

Choose a reason for hiding this comment

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

Since the names of the keys on entry are the same as the names your are setting on ChatEntry attributes/you are using all of the values in entry you could do something something like this to save you a few keystrokes:

  const chatComponents = entries.map((entry) => {
    return(
      <ChatEntry
        {...entry}
        onLikeToggle={onLikeBtnToggle}
        key={entry.id}
      />
    );
  });

Comment on lines +26 to +35
entries: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,
})
).isRequired,
toggleLike: PropTypes.func.isRequired,

Choose a reason for hiding this comment

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

⭐️

@@ -4,188 +4,215 @@
"sender":"Vladimir",
"body":"why are you arguing with me",
"timeStamp":"2018-05-29T22:49:06+00:00",
"liked": false
"liked": false,
"likeCount": 0

Choose a reason for hiding this comment

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

Seems like you decided not to use the likeCount since you noticed that we could just use liked instead.

Comment on lines +10 to +16
<p>{body}</p>
<p className="entry-time">
<TimeStamp time={timeStamp} />
</p>
<button className="like" onClick={onLikeToggle}>
{liked ? '❤️' : '🤍'}
</button>

Choose a reason for hiding this comment

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

Perfect!

Comment on lines +23 to +27
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