-
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 0.01` #1208
base: master
Are you sure you want to change the base?
solution 0.01` #1208
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 you've made great progress, there are a few critical issues that need to be addressed to ensure the application functions correctly and meets the task requirements:
-
Typographical Errors: There are several typos in function and variable names, such as
setSelectedpost
,addCommetns
, andupdatedCommnets
. These should be corrected tosetSelectedPost
,addComments
, andupdatedComments
respectively, to maintain consistency and avoid potential bugs. -
State Management: The
emptyPosts
state is not reset when posts are successfully fetched, which could lead to incorrect UI behavior. Ensure to reset this state appropriately. -
Form Validation Logic: The logic for checking empty form inputs in the
hasEmptyForm
function is incorrect. It should use logical OR (||
) instead of logical AND (&&
) to ensure proper validation. -
Error Handling: Setting
setComments([])
in the catch block will clear all comments on error, which might not be the intended behavior. Consider revising this logic to preserve existing comments. -
PropTypes and Key Generation: The code lacks
propTypes
definitions for components, and keys are generated on render usingcomment.id
. These should be addressed to follow best practices.
Please address these issues to ensure the code meets the specified requirements and functions as expected. Keep up the great work, and don't hesitate to reach out if you need further assistance! 😊
✨ 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
|
||
<Loader /> | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [selectedPost, setSelectedpost] = useState<Post | null>(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 state setter function setSelectedpost
is inconsistently named. It should be setSelectedPost
to match the naming convention of selectedPost
and avoid potential bugs.
src/App.tsx
Outdated
users={users} | ||
userId={userId} | ||
setUserId={setUserId} | ||
setSelectedpost={setSelectedpost} |
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 setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the state variable naming.
src/App.tsx
Outdated
<PostsList | ||
posts={posts} | ||
selectedPost={selectedPost} | ||
setSelectedpost={setSelectedpost} |
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 setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the state variable naming.
<Loader /> | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [selectedPost, setSelectedpost] = useState<Post | null>(null); | ||
const [emptyPosts, setEmptyPosts] = useState(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 emptyPosts
state is not reset when posts are successfully fetched. Consider setting setEmptyPosts(false)
after setting posts to ensure the UI reflects the correct state.
src/components/NewCommentForm.tsx
Outdated
return doesEmpty; | ||
}; | ||
|
||
const addCommetns = async () => { |
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 function name addCommetns
. It should be corrected to addComments
to reflect its purpose accurately.
src/components/PostsList.tsx
Outdated
}) => { | ||
const handleButtonSwitch = (currentPost: Post) => { | ||
if (selectedPost && selectedPost.id === currentPost.id) { | ||
setSelectedpost(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 function setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the naming convention used for state variables and props.
src/components/PostsList.tsx
Outdated
if (selectedPost && selectedPost.id === currentPost.id) { | ||
setSelectedpost(null); | ||
} else { | ||
setSelectedpost(currentPost); |
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 function setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the naming convention used for state variables and props.
src/components/UserSelector.tsx
Outdated
users: User[]; | ||
userId: number | null; | ||
setUserId: React.Dispatch<React.SetStateAction<number | null>>; | ||
setSelectedpost: React.Dispatch<React.SetStateAction<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.
The prop setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the naming convention used for state variables and props.
src/components/UserSelector.tsx
Outdated
users, | ||
userId, | ||
setUserId, | ||
setSelectedpost, |
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 setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the naming convention used for state variables and props.
src/components/UserSelector.tsx
Outdated
setUserId(user.id); | ||
setUserName(user.name); | ||
setShowList(false); | ||
setSelectedpost(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 function setSelectedpost
should be renamed to setSelectedPost
to maintain consistency with the naming convention used for state variables and props.
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.
Review Summary
Great effort on addressing several issues from the previous review! 🎉 Here are some key points and areas for improvement:
-
Typographical Errors: You've successfully corrected typographical errors in function and variable names, such as
setSelectedPost
,addComments
, andupdatedComments
. This is crucial for maintaining code readability and functionality. -
State Management: The
emptyPosts
state is now reset when posts are successfully fetched, aligning with the task requirements. However, ensure that the conditionemptyPosts && posts.length === 0 && userId
is necessary and correctly managed. -
Form Validation Logic: The logic for checking empty form inputs should use logical OR (
||
) instead of logical AND (&&
) to ensure proper validation. This change will prevent form submission if any input is empty. -
Error Handling: While you've revised the error handling logic in the
addComments
function, settingsetComments([])
in the catch block might not be the intended behavior. Consider preserving existing comments and providing more context-specific error messages to enhance user experience. -
PropTypes and Key Generation: The code lacks
propTypes
definitions for components, which is essential for type-checking and maintaining robust code. Additionally, avoid generating keys on render usingcomment.id
. -
Unused Comments: Remember to remove any unused comments in the code to keep it clean and maintainable.
The decision to approve this pull request is made to help you move forward with your learning journey. Please review the comments and address these issues in future iterations to improve 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! ✨
<Loader /> | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [selectedPost, setSelectedPost] = useState<Post | null>(null); | ||
const [emptyPosts, setEmptyPosts] = useState(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 emptyPosts
state is not reset when posts are successfully fetched. Ensure to reset this state appropriately to avoid incorrect UI behavior.
|
||
<Loader /> | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [selectedPost, setSelectedPost] = useState<Post | null>(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.
Ensure that the function name setSelectedPost
is correctly spelled and matches its usage throughout the code.
setPosts(currentPosts); | ||
} | ||
} catch { | ||
setCatchError(true); |
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.
Setting setCatchError(true)
in the catch block will trigger an error notification, but consider revising this logic to preserve existing comments or provide more context-specific error handling.
</div> | ||
)} | ||
|
||
{emptyPosts && posts.length === 0 && userId && ( |
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 emptyPosts && posts.length === 0 && userId
might not be necessary if emptyPosts
is managed correctly. Ensure that the logic for displaying this message aligns with the application's requirements.
saveInputDataOnSuccess(); | ||
} catch { | ||
setLoadingError(true); | ||
setComments([]); |
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.
Setting setComments([])
in the catch block will clear all comments on error, which might not be the intended behavior. Consider revising this logic to preserve existing comments or handle errors more gracefully.
{ value: commentText, setError: setCommentTextError }, | ||
]; | ||
|
||
const allEmpty = inputs.every(input => !validateInput(input.value)); |
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 logic for checking empty form inputs in the allEmpty
variable is incorrect. It should use logical OR (||
) instead of logical AND (&&
) to ensure proper validation. This will ensure that the form is not submitted if any input is empty.
setComments(currentComments); | ||
} | ||
} catch { | ||
setLoadingError(true); |
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 error handling logic here does not inadvertently clear important data or state. Consider providing more context-specific error messages or handling.
if (deletedComment) { | ||
setTimeout(() => { | ||
setComments([...updatedComments, deletedComment]); | ||
setLoadingError(true); |
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.
Setting setLoadingError(true)
after attempting to restore a deleted comment might not be the intended behavior. Ensure that the error handling logic aligns with the application's requirements.
DEMO LINK
Implement the App with ability to show posts of a selected user. Each post can
be opened in the sidebar with its comments. There should delete a comment and a
form to add new comments.
Install Prettier Extention and use this VSCode settings to enable format on save.
utils/fetchClient.ts
and use it to interact with the API (tests expect that you each API request is sent after 300 ms delay);App
shows theUserSelector
and a paragraphNo user selected
in the main content block.UserSelector
as a dropdown using the given markup;<Loader>
while waiting for the API response;posts
loading fails;No posts yet
notification.Sidebar--open
class to the sidebar when a post is selected;Loader
is shown before comments are loaded;CommentsError
notification is show on loading error;NoComments
message is shown if the post does not have comments yet;Write a comment
button below the commentsname
andemail
after the successful submit but clear a comment text;Clear
button should also clear all errors;is-loading
class to the submit button while waiting for a response;API
to the end of the list;Add
andDelete
errors so the user can retry