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 task solution #1225

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

add task solution #1225

wants to merge 4 commits into from

Conversation

kovaden414
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! While your code is generally well-structured and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. State Management and UI Consistency:

    • The handleCommentDeleteButton function updates the UI before confirming the deletion from the server, which can lead to inconsistencies. Please ensure the UI is updated only after a successful server response.
    • The useEffect hook resets the selectedUser and posts states on component mount, which might not be the intended behavior. This could lead to unexpected behavior if the component is re-mounted.
  2. Error Handling:

    • Consider adding error handling for server responses, especially in the finally block, to display appropriate messages to the user if operations like comment submission or deletion fail.
    • The Loader component is used for loading indication, but there is no loading state for the delete operation. Adding this will improve user feedback.
  3. Code Quality and Best Practices:

    • The import statement for classnames is duplicated. Please remove the redundant import to clean up the code.
    • In NewCommentForm.tsx, enhance email validation by using a regex pattern to check for valid email formats.

Addressing these issues will ensure your code is robust and meets the task requirements. Keep up the great work, and I'm confident you'll have this ready in no time! 😊

✨ 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
import { Post } from './types/Post';
import { useEffect, useState } from 'react';
import { User } from './types/User';
import classNames from 'classnames';

Choose a reason for hiding this comment

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

The import statement for classnames is duplicated. It is imported on line 2 and again on line 16. You should remove one of these imports to avoid redundancy.

src/App.tsx Outdated
Comment on lines 30 to 33
useEffect(() => {
setSelectedUser(null);
setPosts([]);
}, []);

Choose a reason for hiding this comment

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

The useEffect hook resets the selectedUser and posts states when the component mounts. If this is not the intended behavior, you might want to reconsider this logic. This could lead to unexpected behavior if the component is re-mounted.

src/App.tsx Outdated
Comment on lines 35 to 48
const addPosts = (userId: number) => {
setIsLoading(true);
setIsError(false);

<div
className="notification is-danger"
data-cy="PostsLoadingError"
>
Something went wrong!
</div>
client
.get<Post[]>(`/posts?userId=${userId}`)
.then(fetchedPosts => {
setPosts(fetchedPosts);
})
.catch(() => setIsError(true))
.finally(() => {
setIsLoading(false);
});
};

Choose a reason for hiding this comment

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

In the addPosts function, consider setting the selectedUser state when fetching posts for a specific user. This will ensure that the UI reflects the currently selected user.

event.preventDefault();

setNameError(!name);
setEmailError(!email);

Choose a reason for hiding this comment

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

Currently, the email validation only checks if the email field is empty. Consider adding a regex pattern to validate the email format and set emailError accordingly.

Comment on lines 51 to 53
.finally(() => {
setIsLoading(false);
});

Choose a reason for hiding this comment

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

Consider adding error handling for the server response in the finally block. This will help in displaying appropriate messages to the user if the comment submission fails due to server issues.

Comment on lines 26 to 29
const handleCommentDeleteButton = (commentId: number) => {
setComments(comments.filter(comment => comment.id !== commentId));

client.delete(`/comments/${commentId}`);

Choose a reason for hiding this comment

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

The handleCommentDeleteButton function removes the comment from the UI before confirming the deletion from the server. Consider handling the server response before updating the UI to ensure consistency. You might also want to handle any errors that occur during the deletion process.

</div>

<div className="block">
<Loader />
{isSideBarLoading && <Loader />}

Choose a reason for hiding this comment

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

The Loader component is used to indicate loading, but there is no loading state for the delete operation. Consider adding a loading state to handle this scenario and provide feedback to the user.

<div className="dropdown-trigger">
<button
type="button"
className="button"
aria-haspopup="true"
aria-controls="dropdown-menu"
onClick={() => setIsDropdownOpen(prev => !prev)}
onBlur={() => setIsDropdownOpen(false)}

Choose a reason for hiding this comment

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

Using onBlur to close the dropdown might lead to premature closing if the user interacts with the dropdown items. Consider using an onClick event outside the dropdown to close it instead.

Comment on lines 26 to 29
useEffect(() => {
client.get<User[]>(`/users`).then(setUsers);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Choose a reason for hiding this comment

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

The useEffect hook should include setUsers in its dependency array to avoid potential issues with stale closures. Although setUsers is a stable function from React's useState, it's a good practice to include all dependencies.

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 your submission! 🎉 While the code is generally well-structured and meets most of the task requirements, there are a few critical issues that need attention:

  • UI Consistency: The handleCommentDeleteButton function updates the UI before confirming deletion from the server, which can lead to inconsistencies. Consider updating the UI only after a successful server response to ensure reliability.

  • State Management: The useEffect hook in App.tsx resets the selectedUser state on component mount, which might not be the intended behavior. This could lead to unexpected behavior if the component is re-mounted, so please review this logic.

  • Code Quality: There is a duplicated import of classnames that should be removed to clean up the code.

  • Email Validation: The regex pattern for email validation is a good practice, but ensure it covers all valid email formats. Testing with various email formats can help ensure robustness.

Despite these issues, the decision to approve is made to help you move forward with your learning. Please review the comments and address these issues in future iterations to enhance your code quality and functionality. 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! ✨

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/indent */
import classNames from 'classnames';

Choose a reason for hiding this comment

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

The import statement for classnames is duplicated. Please remove this redundant import to clean up the code.

Comment on lines +29 to +31
useEffect(() => {
setSelectedUser(null);
}, []);

Choose a reason for hiding this comment

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

The useEffect hook resets the selectedUser state on component mount. This might not be the intended behavior and could lead to unexpected behavior if the component is re-mounted. Consider reviewing this logic.

event.preventDefault();

setNameError(!name);
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

Choose a reason for hiding this comment

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

The regex pattern for email validation is a good practice. However, ensure that it covers all valid email formats as per the task requirements. Consider testing with various email formats to ensure robustness.

Comment on lines +31 to +41
const handleCommentDeleteButton = (commentId: number) => {
setIsDeleteButtonLoading(true);

client
.delete(`/comments/${commentId}`)
.catch(() => setIsError(true))
.finally(() => {
setIsDeleteButtonLoading(false);
});

setComments(comments.filter(comment => comment.id !== commentId));

Choose a reason for hiding this comment

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

The handleCommentDeleteButton function updates the UI to remove a comment before confirming the deletion from the server. This can lead to inconsistencies if the server request fails. Consider updating the UI only after a successful server response.

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