-
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 #1192
base: master
Are you sure you want to change the base?
Develop #1192
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 meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
State Management: The handling of
setIsPostLoaded
inApp.tsx
is misleading and could cause incorrect UI behavior. It should accurately reflect the loading status of posts. -
Function Defaults: Assigning default empty functions to
openForm
anddeleteComment
can lead to unexpected behavior. Ensure these functions are always provided when components are used. -
API Defaults: The use of default parameters like
userId = 0
andpostId = 0
inusers.ts
might lead to unintended API calls. Verify these defaults are intentional and handled correctly. -
Unrelated Code: The
deleteTodos
function inusers.ts
seems unrelated to the current context and should be removed if unnecessary. -
PropTypes and Error Handling: The absence of
propTypes
and lack oftry-catch
error handling are significant omissions that affect code robustness and documentation.
Please address these issues to enhance the functionality and reliability of your code. Keep up the great work, and I'm confident you'll tackle these challenges successfully! 😊
✨ 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 getPostsByCurrentUser = (user: User | null | undefined) => { | ||
setIsPostLoadError(false); | ||
setIsPostLoaded(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 setIsPostLoaded(true)
here might be misleading as it indicates that posts are already loaded. Consider setting this state to true
only when the posts have successfully loaded.
.getPostsByUser(user?.id) | ||
.then(setPosts) | ||
.catch(() => setIsPostLoadError(true)) | ||
.finally(() => setIsPostLoaded(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.
Setting setIsPostLoaded(false)
in the finally
block might not accurately reflect the loading status. Consider setting this state to false
only after the posts have been successfully loaded or if an error occurs.
src/api/users.ts
Outdated
export const deleteTodos = (todoId: number) => { | ||
return client.delete(`/todos/${todoId}`); | ||
}; |
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 deleteTodos
appears to be unrelated to the current context of users, posts, and comments. Consider removing it if it's not needed.
src/api/users.ts
Outdated
export const getPostsByUser = (userId = 0) => { | ||
return client.get<Post[]>(`/posts?userId=${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 default parameter userId = 0
might lead to unintended API calls if not handled properly. Ensure that this default value is intentional and that the API can handle requests with userId = 0
appropriately.
src/api/users.ts
Outdated
export const getCommentsByPost = (postId = 0) => { | ||
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.
The default parameter postId = 0
might lead to unintended API calls if not handled properly. Ensure that this default value is intentional and that the API can handle requests with postId = 0
appropriately.
src/components/PostItem.tsx
Outdated
setCurrentPost, | ||
currentPost, | ||
getCommentsByCurrentPost, | ||
openForm = () => {}, |
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.
Assigning a default empty function to openForm
might lead to unexpected behavior if not properly handled. Ensure that this function is always provided when the component is used.
src/components/PostItem.tsx
Outdated
|
||
type Props = { | ||
post: Post; | ||
key?: number; |
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 key
prop is defined in the Props
type but not used in the component. Consider removing it if it's not needed to avoid confusion.
src/components/PostsList.tsx
Outdated
setCurrentPost: (post: Post | null) => void; | ||
currentPost?: Post | null; | ||
getCommentsByCurrentPost: (post: Post) => void; | ||
openForm?: (isOpen: 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.
The openForm
prop is optional, but there is no default value provided in the PostItem
component. Ensure that this function is always provided when the component is used to avoid unexpected behavior.
<div className="dropdown-trigger"> | ||
<button | ||
type="button" | ||
className="button" | ||
aria-haspopup="true" | ||
aria-controls="dropdown-menu" | ||
onClick={handleDropdownClick} | ||
onBlur={() => setIsMenuShown(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.
Using onBlur
to close the dropdown might cause it to close unexpectedly if the user interacts with the dropdown items. Consider using a different approach, such as closing the dropdown when clicking outside of it.
onMouseDown={() => { | ||
handleUserClick(user); | ||
}} |
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 onMouseDown
to handle user selection might not be the best choice for accessibility. Consider using onClick
instead to ensure better accessibility and consistency with user expectations.
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! Almost done!
src/components/NewCommentForm.tsx
Outdated
|
||
const handleFormSubmit = (event: FormEvent) => { | ||
event.preventDefault(); | ||
if (!name) { |
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.
if (!name) { | |
if (!name.trim()) { |
src/components/NewCommentForm.tsx
Outdated
setNameError(true); | ||
} | ||
|
||
if (!email) { |
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.
if (!email) { | |
if (!email.trim()) { |
src/components/NewCommentForm.tsx
Outdated
setEmailError(true); | ||
} | ||
|
||
if (!message) { |
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.
if (!message) { | |
if (!message.trim()) { |
src/components/NewCommentForm.tsx
Outdated
setMessageError(true); | ||
} | ||
|
||
if (name && email && message) { |
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.
if (name && email && message) { | |
if (name.trim() && email.trim() && message.trim()) { |
src/components/UserSelector.tsx
Outdated
currentUser?: User | null; | ||
setCurrentPost: (post: Post | null) => void; | ||
setPosts: (posts: Post[]) => void; | ||
// setComments: (comments: Comment[]) => 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.
// setComments: (comments: Comment[]) => 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.
Almost done!
src/App.tsx
Outdated
dataFromServer.getUsers().then(setUsers); | ||
}, []); | ||
|
||
function addComment(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.
It is important to stick to one way of creating functions, fix it everywhere
function addComment(comment: Comment) { | |
const addComment = (comment: Comment) => { |
src/components/CommentItem.tsx
Outdated
<article className="message is-small" data-cy="Comment"> | ||
<div className="message-header"> | ||
<a href={`mailto:${comment?.email}`} data-cy="CommentAuthor"> | ||
{comment?.name} |
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.
Use destructuring for 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.
good job, but you need and you can try to remove the comment that user tries to delete immediately from the screen
https://mariana-vv.github.io/react_dynamic-list-of-posts/