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

Solution #1186

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

Solution #1186

wants to merge 3 commits into from

Conversation

Valeraom
Copy link

@Valeraom
Copy link
Author

Valeraom commented Oct 26, 2024

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.
The mentor told me to skip these tests.

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! 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:

  1. 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.

  2. State Management: Ensure that setIsLoading(false) is called correctly in the loadSelectedUserPosts function to reset the loading state, even if no user is selected. Additionally, review the logic around setIsLoading(true) and selectedUser to ensure it behaves as expected.

  3. Event Handling: Consider using onClick instead of onMouseDown for user selection to avoid unexpected behavior. Also, review the onBlur and onClick handlers for managing the dropdown's open state to prevent issues like the dropdown closing when clicking inside it.

  4. Naming Conventions: The state variable setisFormOpened should be renamed to setIsFormOpened to maintain consistent camelCase naming conventions.

  5. Duplicate Attributes: The data-cy="PostDetails" attribute is duplicated. Please ensure this is intentional or remove the duplicate to avoid confusion.

  6. 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.

  7. CSS and Media Queries: Review the media query combining print and screen 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 {

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) {

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
Comment on lines 34 to 36
if (selectedUser === user) {
setIsLoading(false);
}

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.

Comment on lines +97 to +99
className={cn('tile is-parent is-8-desktop Sidebar', {
'Sidebar--open': selectedPost,
})}

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.

Comment on lines +52 to +53
.then(() => setCommentBody(''))
.finally(() => setIsLoading(false));

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.

commentsService
.getComments(selectedPostId)
.then(setComments)
.catch(() => setErrorMessage('Something went wrong'))

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.

Comment on lines 36 to 39
.catch(error => {
setErrorMessage('Something went wrong');

throw error;

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));

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.

postsService
.getUserPosts(selectedUserId)
.then(setPosts)
.catch(() => setErrorMessage('Something went wrong'))

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.


setUsers(preparedUsers);
})
.catch(() => setErrorMessage('Something went wrong'));

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.

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.

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! ✨

Comment on lines +21 to +24
.tile {
align-items: stretch;
min-height: min-content;
flex: 1 1 0;

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.

Comment on lines +91 to +93
className={cn('tile is-parent is-8-desktop Sidebar', {
'Sidebar--open': selectedPost,
})}

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.

Comment on lines +51 to +53
onAddComment(newComment)
.then(() => setCommentBody(''))
.finally(() => setIsLoading(false));

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]);

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.

Comment on lines +31 to +35
{!isLoading && errorMessage && (
<div className="notification is-danger" data-cy="CommentsError">
{errorMessage}
</div>
)}

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.

Comment on lines +36 to +38
.catch(() => {
setErrorMessage('Unable to add a 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'))

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) => {

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'));

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.

Comment on lines +16 to +25
const preparedUsers = res.map(user => {
const { id, name, email, phone } = user;

return {
id,
name,
email,
phone,
};
});

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.

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.

3 participants