-
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
Develop #1242
base: master
Are you sure you want to change the base?
Develop #1242
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! There are a few critical issues that need to be addressed before we can approve the pull request:
-
Naming Conventions: The prop
setSelectedPosts
should be renamed tosetSelectedPost
to ensure consistency and clarity in your code. This change is necessary in bothApp.tsx
andPostsList.tsx
. -
Error Handling: It's important to use
try {..} catch
blocks for error handling, especially when fetching data. This will improve clarity and error management in your components. -
Typo Correction: The state variable
isFormVisiblem
appears to be a typo. Please correct it toisFormVisible
for better readability. -
Unused Props: The
postId
prop inNewCommentForm.tsx
andsetError
prop inUserSelector.tsx
are defined but not used. Consider removing them if they're unnecessary or ensure they're used appropriately.
These changes will enhance the functionality and maintainability of your code. Keep up the great work, and feel free to reach out if you have any questions! 😊
✨ 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
{posts.length > 0 && ( | ||
<PostsList | ||
posts={posts} | ||
setSelectedPosts={setPostId} |
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 setSelectedPosts
should be renamed to setSelectedPost
to follow the naming conventions for event handler functions and props in React.
getPostByUserId(selectedUser) | ||
.then(data => { | ||
setPosts(data); | ||
}) | ||
.catch(() => { | ||
setError('Error'); | ||
setPosts([]); | ||
}) | ||
.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.
Consider using a try {..} catch
block for error handling when fetching posts. This approach is recommended for clarity and better error management.
commentLoading: boolean; | ||
} | ||
|
||
export const NewCommentForm: React.FC<NewCommentProps> = ({ onSubmit }) => { |
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 postId
prop is defined in the NewCommentProps
interface but is not used within the NewCommentForm
component. Consider removing it if it's unnecessary, or ensure it's used appropriately if needed.
src/components/PostDetails.tsx
Outdated
const selectedPost = posts.find(post => post.id === postId); // обраний пост | ||
const [commentError, setCommentError] = useState(''); // помилка | ||
const [commentLoading, setCommentLoading] = useState(false); // завантаження | ||
const [isFormVisiblem, setIsFormVisiblem] = 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 state variable isFormVisiblem
seems to be a typo. Consider renaming it to isFormVisible
for clarity and consistency.
.catch(() => { | ||
setCommentError('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.
Consider using a try {..} catch
block for error handling when fetching comments. This approach is recommended for clarity and better error management.
.catch(() => { | ||
setCommentError('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.
Ensure consistent error messages throughout the component. The error message here is 'Error', while elsewhere it's 'error'. Consistency helps with debugging and user experience.
src/components/PostsList.tsx
Outdated
|
||
interface PostProps { | ||
posts: Post[]; | ||
setSelectedPosts: (post: 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 prop setSelectedPosts
should be renamed to setSelectedPost
to reflect that it handles a single post selection. This change will improve code readability and consistency.
setError: (message: string) => void; | ||
} | ||
|
||
export const UserSelector: React.FC<UserProps> = ({ |
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 setError
prop is defined in the UserProps
interface but is not used within the UserSelector
component. Consider removing it if it's unnecessary, or ensure it's used appropriately if needed.
.then(() => fetch(BASE_URL + url, options)) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new 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.
Consider providing a descriptive error message when throwing an error for a non-OK response. This will help with debugging and understanding the nature of the 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.
Great job on addressing many of the issues from the previous review! 🎉 Your code is shaping up well, but there are still a few areas that need attention to enhance its quality and maintainability:
-
Naming Conventions: Ensure consistency by renaming the
selectedPosts
prop toselectedPost
across your components. This will help avoid confusion and align with naming conventions. -
Error Handling: While you've started incorporating
try {..} catch
blocks, make sure all asynchronous operations, especially API calls, are wrapped in these blocks. This includes functions likegetCommentsByPostId
,getPostByUserId
, andgetUsers
. -
Unused Props: Review your components for any unused props like
setError
andpostId
. Remove them if they're unnecessary or ensure they're utilized effectively. -
Typo Correction: Correct the typo in the state variable
setisFormVisible
tosetIsFormVisible
for better readability. -
Error Messages: Consider providing more informative error messages in your
throw new Error()
statements to aid in debugging.
These improvements will not only enhance the robustness and clarity of your code but also help you grow as a developer. Keep up the good work, and make sure to address these points in future iterations to avoid similar issues. Happy coding! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
setSelectedPost={setPostId} | ||
selectedPosts={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.
The prop setSelectedPost
is correctly named, but the prop selectedPosts
should be renamed to selectedPost
to ensure consistency and clarity in your code. This change is necessary to match the naming conventions and avoid confusion.
getPostByUserId(selectedUser) | ||
.then(data => { | ||
setPosts(data); | ||
}) | ||
.catch(() => { | ||
setError('Error'); | ||
setPosts([]); | ||
}) | ||
.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.
Consider wrapping the getPostByUserId
call in a try {..} catch
block for better error handling. This will improve clarity and error management in your component, as recommended in the previous review.
interface NewCommentProps { | ||
onSubmit: (newComment: { name: string; email: string; body: string }) => 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 postId
prop is defined but not used in this component. Consider removing it if it's unnecessary, or ensure it's used appropriately if needed.
const selectedPost = posts.find(post => post.id === postId); // обраний пост | ||
const [commentError, setCommentError] = useState(''); // помилка | ||
const [commentLoading, setCommentLoading] = useState(false); // завантаження | ||
const [isFormVisible, setisFormVisible] = 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.
There is a typo in the state variable setisFormVisible
. It should be corrected to setIsFormVisible
for better readability and consistency.
getCommentsByPostId(postId) | ||
.then(data => { | ||
setComment(data); | ||
}) | ||
.catch(() => { | ||
setCommentError('error'); | ||
}) | ||
.finally(() => { | ||
setCommentLoading(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 wrapping the getCommentsByPostId
call in a try {..} catch
block for better error handling. This will improve clarity and error management in your component.
export const getUsers = () => { | ||
return client.get<User[]>('/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 adding error handling to the getUsers
function. This will improve robustness and provide better feedback in case of failures when fetching users.
export const getPostByUserId = (id: number) => { | ||
return client.get<Post[]>(`/posts?userId=${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.
Consider adding error handling to the getPostByUserId
function. This will improve robustness and provide better feedback in case of failures when fetching posts by user ID.
export const getCommentsByPostId = (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 to the getCommentsByPostId
function. This will improve robustness and provide better feedback in case of failures when fetching comments by post ID.
export const postCommentsByPostId = ( | ||
postId: number, | ||
comment: Omit<Comment, 'id'>, | ||
) => { | ||
return client.post<Comment>(`/comments`, { | ||
postId: postId, | ||
name: comment.name, | ||
email: comment.email, | ||
body: comment.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 to the postCommentsByPostId
function. This will improve robustness and provide better feedback in case of failures when posting comments.
export const deleteCommentsByPostId = (commentId: number) => { | ||
return client.delete(`/comments/${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 to the deleteCommentsByPostId
function. This will improve robustness and provide better feedback in case of failures when deleting comments by post ID.
DEMO LINK