Skip to content

C24 Crow Tatiana Chatlog#21

Open
FluenceMind wants to merge 3 commits intoAda-C24:mainfrom
FluenceMind:main
Open

C24 Crow Tatiana Chatlog#21
FluenceMind wants to merge 3 commits intoAda-C24:mainfrom
FluenceMind:main

Conversation

@FluenceMind
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

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

@FluenceMind, nice work on the project! I had a couple of questions for you that you will find in the PR review.

Comment thread src/App.jsx
import entriesData from "./data/messages.json";

const App = () => {
const [entries, setEntries] = useState(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.

Comment thread src/App.jsx
const App = () => {
const [entries, setEntries] = useState(entriesData);

const likedCount = entries.reduce((sum, e) => sum + (e.liked ? 1 : 0), 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great work, @FluenceMind. Though you will find a number of implementations for this, the .reduce method is the one I would prefer for the given case.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Given that this function is not dependent on any piece of data that is locally scoped to our component you could opt to move its definition outside of the component and into, say, its own file.

Comment thread src/App.jsx
function handleToggleLike(entryId) {
setEntries((prev) =>
prev.map((e) =>
e.id === entryId ? { ...e, liked: !e.liked } : e
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very succinct, however I would encourage you to use a more descriptive variable name than just e. For someone looking to understand the function e doesn't readily explain what its structure and content may be—resulting in more cognitive load from the reader.

Comment thread src/App.jsx
<div id="App">
<header>
<h1>Application title</h1>
<p className="liked-count">{likedCount} ❤️s</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.

An alternative could be to call the function here instead of assigning the value to a variable earlier in the code, especially since the variable is not being leveraged in any other way.

Comment thread src/App.jsx
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={entries} onToggleLike={handleToggleLike} />
Copy link
Copy Markdown

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 +7
const showLikeButton =
typeof id === "number" && typeof onToggleLike === "function";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@FluenceMind, also wondering the reason for having this logic for deciding if the like button will be shown based off the typing for the mentioned props?

<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<p>{body}</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.

Suggested change

<p>{body}</p>

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

Comment on lines +20 to +22
{showLikeButton && (
<button className="like" onClick={() => onToggleLike(id)}>
{liked ? "❤️" : "🤍"}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agnostic of the reason, love see you implementing this! This is essentially how you have functionality like having a submit button appear only when the form is filled out correctly.

Comment on lines +31 to +36
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
id: PropTypes.number,
liked: PropTypes.bool,
onToggleLike: PropTypes.func,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great work on these proptypes, remember that they have been sunsetted in React and that will be using other type checking frameworks like Typescript.

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