-
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 #1200
base: master
Are you sure you want to change the base?
add task solution #1200
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 pull request! 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 proceed:
-
Typo in State Variable Names: The state variable
writeCommen
and its settersetWriteCommen
should be corrected towriteComment
andsetWriteComment
respectively. Consistency in naming is crucial for code readability and maintenance. -
Error Handling: The use of
setInterval
to reset error states is not ideal as it could lead to unexpected behavior. It's recommended to usesetTimeout
to clear the error after a specific duration. -
Function Naming: The function
removeDelete
should be renamed toremoveComment
to better reflect its purpose and improve code clarity. -
Type Safety: Ensure that functions like
setPosts
andsetPost
have explicit type definitions to enhance type safety and prevent potential runtime errors. -
PropTypes and Error Handling: The absence of
propTypes
andtry-catch
blocks for error handling are significant oversights. These are essential for maintaining robust and error-free code. -
State Initialization and Key Generation: Initializing state with props and generating keys on render can lead to issues and should be revised according to best practices.
Please address these issues to ensure the code meets the core requirements and functions as expected. Once these changes are made, we can move forward with the approval. Keep up the great work, and don't hesitate to reach out if you need any help! 😊
✨ 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
const [comments, setComments] = useState<Comment[]>([]); | ||
const [loadingComments, setLoadingComments] = useState(false); | ||
const [errorLoadComments, setErrorLoadComments] = useState<boolean>(false); | ||
const [writeCommen, setWriteCommen] = useState<boolean>(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.
There is a typo in the state variable name writeCommen
. It should be writeComment
to maintain consistency and clarity in your code.
src/App.tsx
Outdated
setInterval(() => { | ||
setErrorLoadPosts(false); | ||
}, 3000); |
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 setInterval
to reset the error state might not be the best approach. Consider using setTimeout
instead to clear the error after a specific duration, as setInterval
will repeatedly execute the callback function.
src/App.tsx
Outdated
setInterval(() => { | ||
setErrorLoadComments(false); | ||
}, 3000); |
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 previous comment, using setInterval
to reset the error state might not be ideal. Consider using setTimeout
to clear the error after a specific duration.
} | ||
|
||
setLoadingNewComment(true); | ||
if (postId) { |
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 the case where postId
is undefined more explicitly. Currently, the function does nothing if postId
is undefined, which might lead to confusion or unexpected behavior.
src/components/PostDetails.tsx
Outdated
writeCommen, | ||
setWriteCommen, | ||
}) => { | ||
function removeDelete(comment: 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.
Consider renaming the function removeDelete
to removeComment
for better clarity and to accurately reflect its functionality.
src/components/PostDetails.tsx
Outdated
setComments: (comments: Comment[]) => void; | ||
loadingComments: boolean; | ||
errorLoadComments: boolean; | ||
writeCommen: boolean; |
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 state variable name writeCommen
. It should be writeComment
to maintain consistency and clarity in your code.
src/components/PostsList.tsx
Outdated
openPostDetails: number; | ||
setOpenPostDetails: (openPostDetails: number) => void; | ||
getCommentsPost: (post: Post) => void; | ||
setWriteCommen: (writeCommen: boolean) => void; |
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 state variable name setWriteCommen
. It should be setWriteComment
to maintain consistency and clarity in your code.
src/components/UserSelector.tsx
Outdated
setUserSelected: (userSelected: User) => void; | ||
getPostUser: (user: User) => void; | ||
setOpenPostDetails: (openPostDetails: number) => void; | ||
setWriteCommen: (writeCommen: boolean) => void; |
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 state variable name setWriteCommen
. It should be setWriteComment
to maintain consistency and clarity in your code.
src/components/UserSelector.tsx
Outdated
getPostUser: (user: User) => void; | ||
setOpenPostDetails: (openPostDetails: number) => void; | ||
setWriteCommen: (writeCommen: boolean) => void; | ||
setPosts: ([]) => void; |
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 setPosts
function should have a more explicit type definition, such as (posts: Post[]) => void
, to ensure type safety.
src/components/UserSelector.tsx
Outdated
setOpenPostDetails: (openPostDetails: number) => void; | ||
setWriteCommen: (writeCommen: boolean) => void; | ||
setPosts: ([]) => void; | ||
setPost: (post: null) => void; |
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 setPost
function should have a more explicit type definition, such as (post: Post | null) => void
, to ensure type safety.
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 Pull Request has been reviewed and approved! 🎉 While there are several areas for improvement, the decision to approve is made to help you move forward with your learning journey. Here are some key points to consider for future enhancements:
-
Type Safety: Ensure that all functions, props, and state setters have explicit type definitions. This will enhance type safety and prevent potential runtime errors.
-
Error Handling: Consider adding error handling for API requests across various functions (
getUsers
,getPosts
,createComment
,deleteComment
, etc.). Implementing.catch()
blocks with detailed error messages or logging will help manage potential errors gracefully and aid in debugging. -
Accessibility: Improve accessibility by adding aria-labels or other features to buttons and dropdowns, ensuring a better experience for users with assistive technologies.
-
User Feedback: Enhance user experience by providing notifications or messages, especially in cases like comment deletion failures.
-
Validation: Implement regex checks for email validation to ensure inputs are valid before form submission.
These improvements will not only enhance the functionality and robustness of your code but also provide a better 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! ✨
.catch(() => { | ||
setErrorLoadPosts(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.
Consider adding more detailed error messages or logging within the .catch()
block to aid in debugging and provide more context about the error.
.catch(() => { | ||
setErrorLoadComments(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.
Similar to the previous comment, consider adding more detailed error messages or logging within the .catch()
block to aid in debugging and provide more context about the error.
const [users, setUsers] = useState<User[]>([]); | ||
const [userSelected, setUserSelected] = useState<User | null>(null); | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [post, setPost] = useState<Post | null>(null); | ||
const [loadingPosts, setLoadingPosts] = useState(false); | ||
const [errorLoadPosts, setErrorLoadPosts] = useState<boolean>(false); | ||
const [openPostDetails, setOpenPostDetails] = useState<number>(0); | ||
const [comments, setComments] = useState<Comment[]>([]); | ||
const [loadingComments, setLoadingComments] = useState(false); | ||
const [errorLoadComments, setErrorLoadComments] = useState<boolean>(false); | ||
const [writeComment, setWriteComment] = useState<boolean>(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 all state setters have explicit type definitions to enhance type safety and prevent potential runtime errors.
export const getComments = (postId: number) => { | ||
return client.get<Comment[]>(`/comments?postId=${postId}`); | ||
}; |
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 getComments
function to manage potential errors gracefully.
}: Omit<Comment, 'id'>) => { | ||
return client.post<Comment>(`/comments`, { postId, name, email, body }); | ||
}; |
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 createComment
function to manage potential errors gracefully.
}) => { | ||
function removeComment(comment: Comment) { | ||
setComments([...comments.filter(commentary => commentary !== comment)]); | ||
deleteComment(comment.id).catch(() => setComments([...comments])); |
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 notification or message to inform the user if the comment deletion fails. This will improve user experience by providing feedback on the action.
function removeComment(comment: Comment) { | ||
setComments([...comments.filter(commentary => commentary !== comment)]); | ||
deleteComment(comment.id).catch(() => setComments([...comments])); | ||
} |
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 removeComment
function has an explicit return type definition to enhance type safety and prevent potential runtime errors.
<button | ||
type="button" | ||
data-cy="PostButton" | ||
className="button is-link" | ||
onClick={() => { | ||
setOpenPostDetails(0); | ||
setWriteComment(false); | ||
}} | ||
> | ||
Close | ||
</button> | ||
) : ( | ||
<button | ||
type="button" | ||
data-cy="PostButton" | ||
className="button is-link is-light" | ||
onClick={() => { | ||
setOpenPostDetails(id); | ||
getCommentsPost(post); | ||
setPost(post); | ||
setWriteComment(false); | ||
}} | ||
> | ||
Open | ||
</button> |
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 aria-labels or other accessibility features to the buttons to improve accessibility for users with assistive technologies.
export const PostsList: React.FC<Props> = ({ | ||
posts, | ||
setPost, | ||
openPostDetails, | ||
setOpenPostDetails, | ||
getCommentsPost, | ||
setWriteComment, | ||
}) => ( |
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 all functions and props have explicit type definitions to enhance type safety and prevent potential runtime errors.
export const UserSelector: React.FC<Props> = ({ | ||
users, | ||
userSelected, | ||
setUserSelected, | ||
getPostUser, | ||
setOpenPostDetails, | ||
setWriteComment, | ||
setPosts, | ||
setPost, | ||
}) => { |
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 all functions and props have explicit type definitions to enhance type safety and prevent potential runtime errors.
https://VictorKomara.github.io/react_dynamic-list-of-posts/