Skip to content

C24 Possum Li Yan#23

Open
liygit15 wants to merge 5 commits intoAda-C24:mainfrom
liygit15:main
Open

C24 Possum Li Yan#23
liygit15 wants to merge 5 commits intoAda-C24:mainfrom
liygit15:main

Conversation

@liygit15
Copy link
Copy Markdown

No description provided.

import TimeStamp from './TimeStamp';

const ChatEntry = () => {
const ChatEntry = ({ id, sender, body, timeStamp, toggleLikeChoice, liked, color }) => {
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 job destructuring the variables instead of just passing props into the parameter list 👍

<section className={`entry-bubble ${color}`}>
<p>{body}</p>
<span className="entry-time">
<TimeStamp time={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.

Nice use of the TimeStamp component that was supplied.

<p>Replace with body of ChatEntry</p>
<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<article className={`chat-entry ${isLocal ? 'local' : 'remote'}`}>
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 computing the value of isLocal 👍

<span className="entry-time">
<TimeStamp time={timeStamp} />
</span>
<button className="like" onClick={() => toggleLikeChoice(id)}>{liked ? '❤️' : '🤍'}</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.

👍 Passing the id of this message lets the logic defined in the App component find the correct chat entry to update.

import './ChatLog.css';
import PropTypes from 'prop-types';

const ChatLog = ({ entries, toggleLikeChoice = () => {}, senderColors = {} }) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should pass a function as a prop to a child component just by variable name (like how you did for in the ChatEntry component.

We don't need to provide a default no-op function. We might use no-op functions when we build a library that other developers will use in their programs and that library surfaces an option for developer-supplied functions.

Here, if no function is passed then our component shouldn't work.

The functions passed as props are part of the component’s contract and the parent is responsible for passing it. If it’s missing, that’s a usage error rather than something to silently ignore.

Suggested change
const ChatLog = ({ entries, toggleLikeChoice = () => {}, senderColors = {} }) => {
const ChatLog = ({ entries, toggleLikeChoice, senderColors}) => {

const chatEntryComponents = entries.map(entry => {
return (
<ChatEntry
key={entry.id}
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 key attribute is important for React to be able to detect certain kinds of data changes in an efficient manner. We're also using the id for our own id prop, so it might feel redundant to pass both, but one is for our logic and one is for React internals.

Comment thread src/App.jsx
Comment on lines +15 to +24
setChatMessages(chatMessages => {
return chatMessages.map(message => {
if (message.id === id) {
return { ...message, liked: !message.liked };
} else {
return message;
}
});
});
};
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 job using the callback-style for updating the state.

Comment thread src/App.jsx
Comment on lines +28 to +29
const participants = Array.from(new Set(chatMessages.map(msg => msg.sender)));
const headerTitle = `Chat between ${participants.join(' and ')}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like that you dynamically calculate the participants names for the header. This could accommodate a situation where the senders are not named Vladimir or Estragon. How might you use participants to dynamically generate the keys for the SENDER_COLORS object on lines 6-9?

Comment thread src/App.jsx
<header>
<h1>Application title</h1>
<h1 className="header">{headerTitle}</h1>
<section id="heartWidget" className="widget">{countLikes} ❤️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.

section tags are recommended to have a heading within them. Use of an h2 around the like count would avoid validation warnings, as well as resemble the sample site more closely.

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