-
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 #1184
base: master
Are you sure you want to change the base?
solution #1184
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 mostly 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:
-
Critical Functionality Issue: The
removeComment
function is using the post'sid
instead of the comment'sid
for deletion. This is a critical issue as it affects the core functionality of your application. Please update the function to usecomment.id
for the deletion process. -
Typo in Prop Name: There is a consistent typo in the prop name
choosenPost
. It should be corrected tochosenPost
to ensure consistency and avoid potential bugs. -
Email Input Type: The
type
for the email input should beemail
instead oftext
. This change will provide built-in validation for email format, enhancing user experience. -
Initialization of
hasNoPosts
: ThehasNoPosts
variable is not correctly initialized. Ensure it is assigned as a boolean expression to function correctly.
These issues are important to resolve to ensure the application functions correctly and maintains a high standard of code quality. Once these are addressed, your code will be in great shape! Keep up the good work, and feel free to reach out if you have any questions or need further guidance. 😊
✨ 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.
const hasNoPosts = | ||
selectedUser && !postsIsLoading && !hasPostsError && !posts.length; |
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 hasNoPosts
variable is not correctly initialized. It should be a boolean expression, but currently, it is missing the assignment operator =
. It should be const hasNoPosts = selectedUser && !postsIsLoading && !hasPostsError && !posts.length;
.
src/App.tsx
Outdated
{!postsIsLoading && posts.length > 0 && ( | ||
<PostsList | ||
posts={posts} | ||
choosenPost={chosenPost} |
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.
There is a typo in the prop name choosenPost
. It should be chosenPost
to match the state variable name and maintain consistency.
src/components/NewCommentForm.tsx
Outdated
<input | ||
value={email} | ||
onChange={handleEmailChange} | ||
type="text" |
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 type
for the email input should be email
instead of text
. This will provide built-in validation for email format and improve user experience.
src/components/PostDetails.tsx
Outdated
type="button" | ||
className="delete is-small" | ||
aria-label="delete" | ||
onClick={() => removeComment(id)} |
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 removeComment
function is using the post's id
instead of the comment's id
for deletion. This will cause incorrect behavior as it attempts to delete the post instead of the comment. Change onClick={() => removeComment(id)}
to onClick={() => removeComment(comment.id)}
to fix this issue.
src/components/PostsList.tsx
Outdated
|
||
type Props = { | ||
posts: Post[]; | ||
choosenPost: Post | 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.
There is a typo in the prop name choosenPost
. It should be chosenPost
to match the standard spelling and maintain consistency across the codebase.
src/components/PostsList.tsx
Outdated
|
||
export const PostsList: React.FC<Props> = ({ | ||
posts, | ||
choosenPost, |
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 prop choosenPost
is misspelled. It should be chosenPost
to align with the correct spelling and ensure consistency with other parts of the application.
src/components/PostsList.tsx
Outdated
type="button" | ||
data-cy="PostButton" | ||
className={cn('button is-link', { | ||
'is-light': choosenPost?.id !== post.id, |
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 usage of choosenPost
here should be corrected to chosenPost
to match the corrected prop name.
src/components/PostsList.tsx
Outdated
'is-light': choosenPost?.id !== post.id, | ||
})} | ||
onClick={() => | ||
onSelect(choosenPost?.id === post.id ? null : post) |
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 to update choosenPost
to chosenPost
in this line to reflect the corrected prop name.
src/components/PostsList.tsx
Outdated
onSelect(choosenPost?.id === post.id ? null : post) | ||
} | ||
> | ||
{choosenPost?.id === post.id ? 'Close' : 'Open'} |
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.
Update choosenPost
to chosenPost
in this line to maintain consistency with the corrected prop name.
src/components/UserSelector.tsx
Outdated
const currentUser = e.target as HTMLAnchorElement; | ||
|
||
if (currentUser.tagName === 'A') { | ||
const userId = +currentUser.href.split('-').slice(-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.
Parsing the user ID from the href
attribute using split('-').slice(-1)[0]
is fragile and depends on the URL structure. Consider using a data attribute to store the user ID directly on the element, which would be more reliable and easier to maintain.
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 work on implementing the code! 🎉 While there are a few areas for improvement, the overall structure and functionality are solid. Here are some key points to consider:
-
Type Safety: Ensure that variables like
hasNoPosts
andhasPostsError
are initialized correctly as booleans or objects to enhance error handling flexibility. -
Error Handling: It's important to handle errors in functions like
addComment
andremoveComment
to prevent unhandled promise rejections. Consider usingtry...catch
blocks for better error management. -
Form Validation: In the
NewCommentForm.tsx
, make sure the form is not reset if there are validation errors or if theaddComment
function fails. -
Event Handling: In the
UserSelector.tsx
, ensure that thehandleUserChange
function checks if the event target is an anchor element to avoid runtime errors. -
PropTypes: Consider adding
propTypes
to your components for better type-checking and to ensure that components receive the correct props.
These improvements will help you write more robust and maintainable code. Keep up the good work, and continue to learn and grow from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
const [selectedUser, setSelectedUser] = useState<User | null>(null); | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [postsIsLoading, setPostsIsLoading] = useState(false); | ||
const [hasPostsError, setHasPostsError] = useState(''); |
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 hasPostsError
state is initialized as a string. Consider initializing it as a boolean or an object to allow for more flexible error handling in the future.
const hasNoPosts = | ||
selectedUser && !postsIsLoading && !hasPostsError && !posts.length; |
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 hasNoPosts
variable should be explicitly initialized as a boolean. Consider using const hasNoPosts = Boolean(selectedUser && !postsIsLoading && !hasPostsError && !posts.length);
to ensure it is always a boolean value.
postId: post.id, | ||
}; | ||
|
||
addComment(newComment).finally(() => setIsSending(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 handling errors in the addComment
promise. Currently, errors from the addComment
function are not caught, which might lead to unhandled promise rejections.
}; | ||
|
||
addComment(newComment).finally(() => setIsSending(false)); | ||
reset(); |
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 reset()
function is called immediately after addComment
. Ensure that the form is not reset if there are validation errors or if the addComment
function fails.
export const PostDetails: React.FC<Props> = ({ post }) => { | ||
const [comments, setComments] = useState<Comment[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
const [hasError, setHasError] = useState(''); |
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 initializing hasError
as a boolean or an object to allow for more flexible error handling in the future.
const addComment = (newComment: CommentData & { postId: number }) => { | ||
return postComment(newComment).then(createdComment => { | ||
setComments(curr => [...curr, createdComment]); | ||
}); |
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 addComment
function to manage potential errors from the postComment
API call.
const removeComment = (commentId: number) => { | ||
return deleteComment(commentId).then(() => | ||
setComments(curr => curr.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.
Consider adding error handling for the removeComment
function to manage potential errors from the deleteComment
API call.
const handleUserChange = ( | ||
e: React.MouseEvent<HTMLDivElement, MouseEvent>, | ||
) => { | ||
const currentUser = e.target as HTMLAnchorElement; |
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 handleUserChange
function assumes that the event target is always an anchor element. Consider adding a check to ensure currentUser
is an anchor element before accessing its attributes to prevent potential runtime errors.
DEMO