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

Solution #1342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #1342

wants to merge 2 commits into from

Conversation

Maas1m
Copy link

@Maas1m Maas1m commented Feb 5, 2025

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great effort on your project! 🎉 While there are several areas that need improvement, the decision to approve your pull request is made to encourage your learning journey. Here are some key points to address:

  1. Dynamic Data Handling:

    • Ensure that the user and comments data are correctly passed and used in components like UserInfo and CommentList. For instance, pass post.user to UserInfo and post.comments to CommentList.
    • Avoid hardcoding values like email addresses and comment content. Use props such as comment.email and comment.body to dynamically render data.
  2. Key Prop in Lists:

    • Add a unique key prop to elements rendered in a list using .map(). Use identifiers like post.id and comment.id to help React efficiently update the UI.
  3. Function Implementation:

    • Correct the getCommentsById function to return an array of comments related to a specific post using filter instead of find.

These improvements are crucial for the functionality and maintainability of your code. Make sure to review these comments and apply the necessary changes to enhance your project. Keep up the good work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +12 to +14
function getCommentsById(commentId) {
return commentsFromServer.find(comment => comment.id === commentId) || null;
}

Choose a reason for hiding this comment

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

The function getCommentsById is incorrectly implemented. It should return an array of comments for a given post ID, not a single comment. Consider using filter instead of find to collect all comments associated with a specific post.

const posts = postsFromServer.map(post => ({
...post,
user: getUserById(post.userId),
comments: getCommentsById(post.id),

Choose a reason for hiding this comment

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

The comments property for each post is currently set to a single comment object due to the incorrect implementation of getCommentsById. This should be an array of comments.

Comment on lines 11 to 13

Choose a reason for hiding this comment

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

The email address is hardcoded as '[email protected]'. It should be dynamically set using comment.email to ensure the correct email is displayed for each comment.

Comment on lines 18 to 20
dolorum voluptas laboriosam quisquam ab totam beatae et aut
aliquid optio assumenda voluptas velit itaque quidem voluptatem
tempore cupiditate in itaque sit molestiae minus dolores magni

Choose a reason for hiding this comment

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

The comment body text is hardcoded. It should be dynamically set using comment.body to display the actual content of each comment.

Comment on lines 34 to 36

Choose a reason for hiding this comment

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

The email address is hardcoded as '[email protected]'. It should be dynamically set using comment.email to ensure the correct email is displayed for each comment.

Comment on lines 18 to 20
est rerum tempore vitae sequi sint nihil reprehenderit dolor beatae ea
dolores neque fugiat blanditiis voluptate porro vel nihil molestiae ut
reiciendis qui aperiam non debitis possimus qui neque nisi nulla

Choose a reason for hiding this comment

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

The post body content is hardcoded. It should be dynamically set using post.body to display the actual content of the post.


<hr />

<b data-cy="NoCommentsMessage">No comments yet <CommentList comments={commentsFromServer} /></b>

Choose a reason for hiding this comment

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

The commentsFromServer variable is not defined within the component. You should use post.comments to pass the correct comments related to the post to the CommentList component.

<>
<div className="PostList">
{posts.map(post => (
<PostInfo post={post} />

Choose a reason for hiding this comment

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

Each child in a list should have a unique key prop to help React identify which items have changed, are added, or are removed. Consider using post.id as the key.

@@ -1 +1,5 @@
export const UserInfo = () => <>Put the user here</>;
export const UserInfo = () =>

Choose a reason for hiding this comment

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

The UserInfo component should accept a user prop to display the user's information. Modify the component to take user as a parameter: export const UserInfo = ({ user }) => ....

Comment on lines +2 to +3
<a className="UserInfo" href={`mailto:${user.email}`}>
{user.name}

Choose a reason for hiding this comment

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

The user variable is not defined. It should be passed as a prop to the UserInfo component to dynamically render the user's email and name.

Copy link

@VitaliyBondarenko1982 VitaliyBondarenko1982 left a comment

Choose a reason for hiding this comment

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

Demo link not works.
Looks like wasn't any deploys for this repo.
https://github.com/Maas1m/react_static-list-of-posts-js/actions

Please check comments and make sure app works and looks correctly.
Fix linter warnings and tests before next re-request and make sure demo link works.

</div>
</div>

<div className="CommentInfo">

Choose a reason for hiding this comment

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

why do you need two same CommentInfo blocks?

<p>
{' Posted by '}

<UserInfo user={user} />

Choose a reason for hiding this comment

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

user is not defined here
Screenshot 2025-02-06 at 14 33 38

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.

3 participants