-
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
Solution #1186
base: master
Are you sure you want to change the base?
Solution #1186
Conversation
Two tests failed: 'should not request posts from API' and 'should not request comments from API' It works properly, i don't know what the problem is. |
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! Your code is generally well-structured and meets many of the task requirements. However, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Error Handling: It's important to provide more detailed error messages or log errors to help with debugging. The current generic message 'Something went wrong' doesn't offer enough information for troubleshooting. This applies to both the general error handling and specific cases like when adding a comment fails.
-
State Management: Ensure that
setIsLoading(false)
is called correctly in theloadSelectedUserPosts
function to reset the loading state, even if no user is selected. Additionally, review the logic aroundsetIsLoading(true)
andselectedUser
to ensure it behaves as expected. -
Event Handling: Consider using
onClick
instead ofonMouseDown
for user selection to avoid unexpected behavior. Also, review theonBlur
andonClick
handlers for managing the dropdown's open state to prevent issues like the dropdown closing when clicking inside it. -
Naming Conventions: The state variable
setisFormOpened
should be renamed tosetIsFormOpened
to maintain consistent camelCase naming conventions. -
Duplicate Attributes: The
data-cy="PostDetails"
attribute is duplicated. Please ensure this is intentional or remove the duplicate to avoid confusion. -
Promise Error Handling: Ensure that the
onAddComment
promise handles errors appropriately. Currently, it resets the comment body and stops loading but doesn't handle potential errors from the promise. -
CSS and Media Queries: Review the media query combining
print
andscreen
with a minimum width to ensure it targets the intended devices. Additionally, consider adding comments or documentation for the.tile
class to explain its purpose or usage.
Addressing these issues will improve the functionality, maintainability, and user experience of your application. Keep up the great work, and I'm confident you'll have these resolved 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.
@@ -18,6 +18,35 @@ | |||
} | |||
} | |||
|
|||
.tile { |
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 a comment or documentation for the .tile
class to explain its purpose or usage, especially since it contains nested styles and media queries.
src/App.scss
Outdated
} | ||
} | ||
|
||
@media print, screen and (min-width: 769px) { |
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 media query here combines print
and screen
with a minimum width. Ensure this is intentional, as it might affect both screen and print styles. If the intention is to target only screens, consider using @media screen and (min-width: 769px)
.
src/App.tsx
Outdated
if (selectedUser === user) { | ||
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.
The condition if (selectedUser === user)
is used to set setIsLoading(false)
. This might not be necessary since setIsLoading(true)
is called right before setting the selected user. Consider reviewing this logic to ensure it behaves as expected.
className={cn('tile is-parent is-8-desktop Sidebar', { | ||
'Sidebar--open': selectedPost, | ||
})} |
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 className
for the sidebar uses classnames
to conditionally apply Sidebar--open
. Ensure that selectedPost
is the correct condition for opening the sidebar. If there are other conditions or states that should affect this, consider adding them.
.then(() => setCommentBody('')) | ||
.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.
Ensure that the onAddComment
promise handles errors appropriately. Currently, it only resets the comment body and stops loading, but it doesn't handle potential errors from the promise.
src/hooks/useComments.ts
Outdated
commentsService | ||
.getComments(selectedPostId) | ||
.then(setComments) | ||
.catch(() => setErrorMessage('Something went wrong')) |
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 providing more detailed error messages or logging the error to help with debugging. The current message 'Something went wrong' is generic and may not provide enough information for troubleshooting.
src/hooks/useComments.ts
Outdated
.catch(error => { | ||
setErrorMessage('Something went wrong'); | ||
|
||
throw error; |
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.
Similar to the comment above, consider logging the error or providing a more specific error message to help with debugging when adding a comment fails.
.getUserPosts(selectedUserId) | ||
.then(setPosts) | ||
.catch(() => setErrorMessage('Something went wrong')) | ||
.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.
The setIsLoading(false)
should be called before the return
statement in the loadSelectedUserPosts
function to ensure that the loading state is correctly reset even if no user is selected.
src/hooks/usePosts.ts
Outdated
postsService | ||
.getUserPosts(selectedUserId) | ||
.then(setPosts) | ||
.catch(() => setErrorMessage('Something went wrong')) |
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 providing more detailed error messages or logging the error to help with debugging. The current message 'Something went wrong' is generic and may not provide enough information for troubleshooting.
src/hooks/useUsers.ts
Outdated
|
||
setUsers(preparedUsers); | ||
}) | ||
.catch(() => setErrorMessage('Something went wrong')); |
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 providing more detailed error messages or logging the error to help with debugging. The current message 'Something went wrong' is generic and may not provide enough information for troubleshooting.
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.
Your code has been reviewed and is approved! 🎉 While there are some areas for improvement, such as enhancing error handling, ensuring proper state management, and improving accessibility, the overall structure and functionality are solid. Please take the time to address the feedback provided to enhance your code quality and user experience. Keep up the great work and continue learning from these insights!
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
.tile { | ||
align-items: stretch; | ||
min-height: min-content; | ||
flex: 1 1 0; |
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 .tile
class uses flex: 1 1 0;
, which might not behave as expected if the parent container is not a flex container. Ensure that the parent of .tile
is a flex container to utilize flex properties effectively.
className={cn('tile is-parent is-8-desktop Sidebar', { | ||
'Sidebar--open': selectedPost, | ||
})} |
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 classnames
library is used correctly to conditionally apply the Sidebar--open
class. However, ensure that the selectedPost
variable is correctly initialized and managed to avoid unexpected behavior when toggling the sidebar's open state.
onAddComment(newComment) | ||
.then(() => setCommentBody('')) | ||
.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.
Ensure that the onAddComment
function handles errors appropriately. Currently, the finally
block resets the loading state, but it might be beneficial to handle errors explicitly to inform the user if the comment submission fails.
delete button | ||
</button> | ||
</div> | ||
useEffect(() => setIsFormOpened(false), [selectedPost]); |
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 form state when the selectedPost
changes. Ensure that this behavior is intended, as it will close the comment form whenever a new post is selected.
{!isLoading && errorMessage && ( | ||
<div className="notification is-danger" data-cy="CommentsError"> | ||
{errorMessage} | ||
</div> | ||
)} |
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 a retry mechanism or additional user feedback when an error occurs while loading comments. This can improve user experience by providing options to recover from errors.
.catch(() => { | ||
setErrorMessage('Unable to add a comment'); | ||
}); |
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.
Similar to the loadComments function, consider providing more detailed error messages or logging for the addComment function to improve error handling and user feedback.
postsService | ||
.getUserPosts(selectedUserId) | ||
.then(setPosts) | ||
.catch(() => setErrorMessage('Unable to load posts')) |
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 providing more detailed error messages or logging the error details to help with debugging and improving user feedback.
import { Post } from '../types'; | ||
import * as postsService from '../api/posts'; | ||
|
||
export const usePosts = (selectedUserId: number = 0) => { |
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 default value for selectedUserId
is set to 0. Ensure that this default value is appropriate for your application's logic, as it might lead to unintended behavior if not handled correctly.
|
||
setUsers(preparedUsers); | ||
}) | ||
.catch(() => setErrorMessage('Unable to load users')); |
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 providing more detailed error messages or logging the error details to help with debugging and improving user feedback.
const preparedUsers = res.map(user => { | ||
const { id, name, email, phone } = user; | ||
|
||
return { | ||
id, | ||
name, | ||
email, | ||
phone, | ||
}; | ||
}); |
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 preparedUsers
mapping seems redundant if it only extracts and returns the same properties without modification. Consider simplifying this by directly setting setUsers(res)
unless there's a specific reason for this transformation.
DEMO PAGE