Skip to content

Possum - Esmeralda Arreguin-Martinez#11

Open
esmerarre wants to merge 9 commits intoAda-C24:mainfrom
esmerarre:main
Open

Possum - Esmeralda Arreguin-Martinez#11
esmerarre wants to merge 9 commits intoAda-C24:mainfrom
esmerarre:main

Conversation

@esmerarre
Copy link
Copy Markdown

No description provided.


const ChatEntry = (props) => {

const chatDisplay = props.sender === 'Vladimir' ? '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 job writing logic to determine the class to apply to the component so that the components show up with 'local' vs 'remote' styles.

import TimeStamp from './TimeStamp';
import PropTypes from 'prop-types';

const ChatEntry = (props) => {
Copy link
Copy Markdown

@yangashley yangashley Dec 22, 2025

Choose a reason for hiding this comment

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

Destructuring props can be a matter of preference. I prefer to destructure props so that I don't need to type props. every time I want to get an attribute from the object.

Destructuring props also has some benefits:

  • you know every possible prop right away.
  • you know when a prop is being unused, in order to remove it.
  • knowing which props are being used will also remind you what you need to validate

Ultimately, you'll adapt what you do depending on what your team does.

<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<p>{props.body}</p>
<p className="entry-time"><TimeStamp time={props.timeStamp} /></p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good work using the provided TimeStamp component.

import ChatEntry from './ChatEntry';
import PropTypes from 'prop-types';

const ChatLog = (props) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Like my comment above in ChatEntry, I prefer to destructure props.

const getChatEntries = (entries) => {
return 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.

Nitpick: incorrect white spacing

Suggested change
key= {entry.id}
key={entry.id}

Take care to check your style using a linter or fix up the issues while you're writing the code so that your work conforms to convention and guidelines.

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
import entriesData from './data/messages.json';
import { useState } from 'react';

const countTotalLikes = entriesData => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❗️👀 Functions that are only used within a specific component, like countTotalLikes is only used inside the App component on line 33, should be defined inside the component to make the code more readable because it keeps related logic together.

Therefore, this function should be defined in the App component (like you do with handleLikes on line 18).

Comment thread src/App.jsx
Comment on lines +8 to +11
if (!entry.liked) {
return acc;
}
return acc + 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A more concise way to write this looks like:
return acc + (entry.liked ? 1 : 0);

Comment thread src/App.jsx
Comment on lines +19 to +20
setEntriesData(entryData => {
return entryData.map(entry => {
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
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={entryData} onLikeEntry={handleLikes}></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.

Prefer to have opening tag, closing tag, and props all on separate lines to help with readability. React doesn't care how you write the component so the key is to be consistent in your project.

Also since ChatLog doesn't render any child elements or content within its opening and closing tags, you can use a self closing tag here.

Suggested change
<ChatLog entries={entryData} onLikeEntry={handleLikes}></ChatLog>
<ChatLog
entries={entryData}
onLikeEntry={handleLikes}>
/>

Comment thread src/App.jsx
<div id="App">
<header>
<h1>Application title</h1>
<h2>{countTotalLikes(entryData)} ❤️s</h2>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❗️ ^^ above on line 32, you should have changed the title so that the header rendered "Chat between Vladimir and Estragon"

Can you think of a way to dynamically get the senders' names without hardcoding "Vladimir" and "Estragon" here?

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