-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: master
Are you sure you want to change the base?
add task solution #1225
Conversation
There was a problem hiding this 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:
-
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 theselectedUser
andposts
states on component mount, which might not be the intended behavior. This could lead to unexpected behavior if the component is re-mounted.
- The
-
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.
- Consider adding error handling for server responses, especially in the
-
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.
- The import statement for
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'; |
There was a problem hiding this comment.
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
useEffect(() => { | ||
setSelectedUser(null); | ||
setPosts([]); | ||
}, []); |
There was a problem hiding this comment.
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
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); | ||
}); | ||
}; |
There was a problem hiding this comment.
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.
src/components/NewCommentForm.tsx
Outdated
event.preventDefault(); | ||
|
||
setNameError(!name); | ||
setEmailError(!email); |
There was a problem hiding this comment.
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.
src/components/NewCommentForm.tsx
Outdated
.finally(() => { | ||
setIsLoading(false); | ||
}); |
There was a problem hiding this comment.
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.
src/components/PostDetails.tsx
Outdated
const handleCommentDeleteButton = (commentId: number) => { | ||
setComments(comments.filter(comment => comment.id !== commentId)); | ||
|
||
client.delete(`/comments/${commentId}`); |
There was a problem hiding this comment.
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.
src/components/PostDetails.tsx
Outdated
</div> | ||
|
||
<div className="block"> | ||
<Loader /> | ||
{isSideBarLoading && <Loader />} |
There was a problem hiding this comment.
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.
src/components/UserSelector.tsx
Outdated
<div className="dropdown-trigger"> | ||
<button | ||
type="button" | ||
className="button" | ||
aria-haspopup="true" | ||
aria-controls="dropdown-menu" | ||
onClick={() => setIsDropdownOpen(prev => !prev)} | ||
onBlur={() => setIsDropdownOpen(false)} |
There was a problem hiding this comment.
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.
src/components/UserSelector.tsx
Outdated
useEffect(() => { | ||
client.get<User[]>(`/users`).then(setUsers); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 inApp.tsx
resets theselectedUser
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'; |
There was a problem hiding this comment.
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.
useEffect(() => { | ||
setSelectedUser(null); | ||
}, []); |
There was a problem hiding this comment.
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,}$/; |
There was a problem hiding this comment.
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.
const handleCommentDeleteButton = (commentId: number) => { | ||
setIsDeleteButtonLoading(true); | ||
|
||
client | ||
.delete(`/comments/${commentId}`) | ||
.catch(() => setIsError(true)) | ||
.finally(() => { | ||
setIsDeleteButtonLoading(false); | ||
}); | ||
|
||
setComments(comments.filter(comment => comment.id !== commentId)); |
There was a problem hiding this comment.
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.
DEMO LINK