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

add dynamic list of post task #1206

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

Conversation

moskkat40
Copy link

@moskkat40 moskkat40 commented Dec 16, 2024

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.

Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the order of .then and .catch in the getCommentsByPostId function needs to be corrected to ensure proper error handling. Additionally, the return statement in PostDetails.tsx should return null when currentPost is not available. Lastly, please remove the unnecessary comments prop from NewCommentForm and correct the typo in resetAllFeilds. Once these issues are resolved, your code will be in great shape! Keep up the great work! 😊

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

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

src/App.tsx Outdated
Comment on lines 60 to 65
.getComments(postId)
.catch(() => setIsError(true))
.then(res => {
setComments(res);
setIsError(false);
})

Choose a reason for hiding this comment

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

The order of .then and .catch in the getCommentsByPostId function is incorrect. According to the checklist, .then should come before .catch to handle the resolved promise before handling any errors. Please switch the order of these methods to ensure proper error handling.

Comment on lines 29 to 33
function resetAllFeilds() {
setName('');
setEmail('');
setBody('');
}

Choose a reason for hiding this comment

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

There is a typo in the function name resetAllFeilds. It should be corrected to resetAllFields to maintain consistency and clarity in the code.

Comment on lines 30 to 31
if (!currentPost) {
return;

Choose a reason for hiding this comment

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

The return statement when currentPost is not available should return null instead of nothing. In React, components should return a valid React element or null to avoid rendering issues.

<NewCommentForm
addComment={addComment}
postId={currentPost.id}
comments={comments}

Choose a reason for hiding this comment

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

The comments prop is being passed to NewCommentForm, but this component does not require it. Please remove this prop to avoid unnecessary data passing.

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 job on addressing the issues from the previous review! 🎉 Your code now meets the task requirements and constraints. Here are some key points to focus on for further improvement:

  • Error Handling: Ensure the .catch block is placed before the .then block in the getCommentsByPostId function for better error handling.
  • Type Definitions: The addComment function should not expect a Promise<void> return type since it does not return a promise. Adjust the type definition accordingly.
  • Handling currentPost: Return null when currentPost is not found to prevent rendering issues.
  • Comment ID Handling: The id field should not be included when adding a new comment, as it should be generated by the backend.
  • Reset Functionality: The reset function in NewCommentForm is redundant given the resetAllFields function. Consider removing reset or using resetAllFields instead.

Your efforts to improve the code are commendable, and these adjustments will enhance the application's functionality and robustness. Keep up the great 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 +62 to +69
return servicesComments
.getComments(postId)
.then(res => {
setComments(res);
setIsError(false);
})
.catch(() => setIsError(true))
.finally(() => setLoading(''));

Choose a reason for hiding this comment

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

The .catch block should be placed before the .then block in the getCommentsByPostId function to ensure proper error handling. This will allow the function to handle errors before attempting to process the response.

};

const currentPost = useMemo(() => {
return posts.find((post: Post) => post.id === currentPostId);

Choose a reason for hiding this comment

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

Consider returning null when currentPost is not found. This will prevent potential issues when currentPost is used elsewhere in the code.

Comment on lines +25 to +27
function reset() {
setBody('');
}

Choose a reason for hiding this comment

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

The reset function only resets the body field, which is redundant given the resetAllFields function. Consider removing reset or using resetAllFields instead.

import { Comment } from '../types/Comment';

type Props = {
addComment: (a: Comment) => Promise<void>;

Choose a reason for hiding this comment

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

The addComment function should not expect a Promise<void> return type since it does not return a promise. Adjust the type definition accordingly.

email,
body,
postId,
id: 0,

Choose a reason for hiding this comment

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

The id field should not be included when adding a new comment, as it should be generated by the backend. Consider removing id: 0 from the addComment call.

type Props = {
comments: Comment[];
currentPost: Post;
addComment: (a: Comment) => Promise<void>;

Choose a reason for hiding this comment

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

The addComment function should not expect a Promise<void> return type since it does not return a promise. Adjust the type definition accordingly.

Comment on lines +30 to +31
if (!currentPost) {
return null;

Choose a reason for hiding this comment

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

Ensure that currentPost is handled correctly when it is not available by returning null. This prevents rendering issues when currentPost is undefined.

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Good job! 👍
Let's improve your code

  1. The comment cannot be only spaces
image
  1. Add the correct type to input of email
image

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.

Looks good.

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.

4 participants