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

Develop #1242

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

Develop #1242

wants to merge 9 commits into from

Conversation

taniavozniuk
Copy link

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:

  1. Naming Conventions: The prop setSelectedPosts should be renamed to setSelectedPost to ensure consistency and clarity in your code. This change is necessary in both App.tsx and PostsList.tsx.

  2. Error Handling: It's important to use try {..} catch blocks for error handling, especially when fetching data. This will improve clarity and error management in your components.

  3. Typo Correction: The state variable isFormVisiblem appears to be a typo. Please correct it to isFormVisible for better readability.

  4. Unused Props: The postId prop in NewCommentForm.tsx and setError prop in UserSelector.tsx are defined but not used. Consider removing them if they're unnecessary or ensure they're used appropriately.

These changes will enhance the functionality and maintainability of your code. Keep up the great work, and feel free to reach out if you have any questions! 😊

✨ 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
{posts.length > 0 && (
<PostsList
posts={posts}
setSelectedPosts={setPostId}

Choose a reason for hiding this comment

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

The prop setSelectedPosts should be renamed to setSelectedPost to follow the naming conventions for event handler functions and props in React.

Comment on lines +40 to +50
getPostByUserId(selectedUser)
.then(data => {
setPosts(data);
})
.catch(() => {
setError('Error');
setPosts([]);
})
.finally(() => {
setIsLoading(false);
});

Choose a reason for hiding this comment

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

Consider using a try {..} catch block for error handling when fetching posts. This approach is recommended for clarity and better error management.

commentLoading: boolean;
}

export const NewCommentForm: React.FC<NewCommentProps> = ({ onSubmit }) => {

Choose a reason for hiding this comment

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

The postId prop is defined in the NewCommentProps interface but is not used within the NewCommentForm component. Consider removing it if it's unnecessary, or ensure it's used appropriately if needed.

const selectedPost = posts.find(post => post.id === postId); // обраний пост
const [commentError, setCommentError] = useState(''); // помилка
const [commentLoading, setCommentLoading] = useState(false); // завантаження
const [isFormVisiblem, setIsFormVisiblem] = useState(false); // старн форми

Choose a reason for hiding this comment

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

The state variable isFormVisiblem seems to be a typo. Consider renaming it to isFormVisible for clarity and consistency.

Comment on lines +40 to +42
.catch(() => {
setCommentError('error');
})

Choose a reason for hiding this comment

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

Consider using a try {..} catch block for error handling when fetching comments. This approach is recommended for clarity and better error management.

Comment on lines +76 to +77
.catch(() => {
setCommentError('Error');

Choose a reason for hiding this comment

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

Ensure consistent error messages throughout the component. The error message here is 'Error', while elsewhere it's 'error'. Consistency helps with debugging and user experience.


interface PostProps {
posts: Post[];
setSelectedPosts: (post: Post | null) => void;

Choose a reason for hiding this comment

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

The prop setSelectedPosts should be renamed to setSelectedPost to reflect that it handles a single post selection. This change will improve code readability and consistency.

setError: (message: string) => void;
}

export const UserSelector: React.FC<UserProps> = ({

Choose a reason for hiding this comment

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

The setError prop is defined in the UserProps interface but is not used within the UserSelector component. Consider removing it if it's unnecessary, or ensure it's used appropriately if needed.

.then(() => fetch(BASE_URL + url, options))
.then(response => {
if (!response.ok) {
throw new Error();

Choose a reason for hiding this comment

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

Consider providing a descriptive error message when throwing an error for a non-OK response. This will help with debugging and understanding the nature of the error.

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 many of the issues from the previous review! 🎉 Your code is shaping up well, but there are still a few areas that need attention to enhance its quality and maintainability:

  1. Naming Conventions: Ensure consistency by renaming the selectedPosts prop to selectedPost across your components. This will help avoid confusion and align with naming conventions.

  2. Error Handling: While you've started incorporating try {..} catch blocks, make sure all asynchronous operations, especially API calls, are wrapped in these blocks. This includes functions like getCommentsByPostId, getPostByUserId, and getUsers.

  3. Unused Props: Review your components for any unused props like setError and postId. Remove them if they're unnecessary or ensure they're utilized effectively.

  4. Typo Correction: Correct the typo in the state variable setisFormVisible to setIsFormVisible for better readability.

  5. Error Messages: Consider providing more informative error messages in your throw new Error() statements to aid in debugging.

These improvements will not only enhance the robustness and clarity of your code but also help you grow as a developer. Keep up the good work, and make sure to address these points in future iterations to avoid similar issues. Happy coding! 🚀

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

Comment on lines +94 to +95
setSelectedPost={setPostId}
selectedPosts={postId}

Choose a reason for hiding this comment

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

The prop setSelectedPost is correctly named, but the prop selectedPosts should be renamed to selectedPost to ensure consistency and clarity in your code. This change is necessary to match the naming conventions and avoid confusion.

Comment on lines +40 to +50
getPostByUserId(selectedUser)
.then(data => {
setPosts(data);
})
.catch(() => {
setError('Error');
setPosts([]);
})
.finally(() => {
setIsLoading(false);
});

Choose a reason for hiding this comment

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

Consider wrapping the getPostByUserId call in a try {..} catch block for better error handling. This will improve clarity and error management in your component, as recommended in the previous review.

Comment on lines +4 to +6
interface NewCommentProps {
onSubmit: (newComment: { name: string; email: string; body: string }) => void;
}

Choose a reason for hiding this comment

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

The postId prop is defined but not used in this component. Consider removing it if it's unnecessary, or ensure it's used appropriately if needed.

const selectedPost = posts.find(post => post.id === postId); // обраний пост
const [commentError, setCommentError] = useState(''); // помилка
const [commentLoading, setCommentLoading] = useState(false); // завантаження
const [isFormVisible, setisFormVisible] = useState(false); // старн форми

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 state variable setisFormVisible. It should be corrected to setIsFormVisible for better readability and consistency.

Comment on lines +36 to +45
getCommentsByPostId(postId)
.then(data => {
setComment(data);
})
.catch(() => {
setCommentError('error');
})
.finally(() => {
setCommentLoading(false);
});

Choose a reason for hiding this comment

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

Consider wrapping the getCommentsByPostId call in a try {..} catch block for better error handling. This will improve clarity and error management in your component.

Comment on lines +7 to +9
export const getUsers = () => {
return client.get<User[]>('/users');
};

Choose a reason for hiding this comment

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

Consider adding error handling to the getUsers function. This will improve robustness and provide better feedback in case of failures when fetching users.

Comment on lines +12 to +14
export const getPostByUserId = (id: number) => {
return client.get<Post[]>(`/posts?userId=${id}`);
};

Choose a reason for hiding this comment

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

Consider adding error handling to the getPostByUserId function. This will improve robustness and provide better feedback in case of failures when fetching posts by user ID.

Comment on lines +17 to +19
export const getCommentsByPostId = (postId: number) => {
return client.get<Comment[]>(`/comments?postId=${postId}`);
};

Choose a reason for hiding this comment

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

Consider adding error handling to the getCommentsByPostId function. This will improve robustness and provide better feedback in case of failures when fetching comments by post ID.

Comment on lines +21 to +31
export const postCommentsByPostId = (
postId: number,
comment: Omit<Comment, 'id'>,
) => {
return client.post<Comment>(`/comments`, {
postId: postId,
name: comment.name,
email: comment.email,
body: comment.body,
});
};

Choose a reason for hiding this comment

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

Consider adding error handling to the postCommentsByPostId function. This will improve robustness and provide better feedback in case of failures when posting comments.

Comment on lines +33 to +35
export const deleteCommentsByPostId = (commentId: number) => {
return client.delete(`/comments/${commentId}`);
};

Choose a reason for hiding this comment

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

Consider adding error handling to the deleteCommentsByPostId function. This will improve robustness and provide better feedback in case of failures when deleting comments by post ID.

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