-
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
sol #863
base: master
Are you sure you want to change the base?
sol #863
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.
Good job!
I found some issues, please check and fix them
Best regards
src/components/UserSelector.tsx
Outdated
setOpen(false); | ||
}; | ||
|
||
document.addEventListener('click', (event) => { |
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.
Adding event listeners directly to the document can lead to memory leaks. Instead, use useEffect to handle the adding and removing of event listeners within a component lifecycle.
@@ -1,3 +1,4 @@ | |||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
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 'any' type is being used, which is not recommended in TypeScript. It would be better to provide a specific type if possible to gain the benefits of using TypeScript.
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.
Any type is used only once, so we can send any data inside the body to server, in other functions generics are used.
|
||
setIsLoading(true); | ||
|
||
client.post<Comment>('/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.
You are not handling the error case when the api call fails. You should add a .catch block to handle any errors.
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 task to handle errors was optional, so I decided to skip it for simplicity)
(in fix added empty catch)
@@ -1,8 +1,70 @@ | |||
import React from 'react'; | |||
import classNames from 'classnames'; | |||
import React, { useState } from 'react'; |
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 import order should be organized. External libraries should be imported first, then internal files.
src/components/PostDetails.tsx
Outdated
|
||
setComments(comments.filter((c) => c.id !== comment.id)); | ||
|
||
client.delete(`/comments/${comment.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 delete operation should ideally be handled with error checks. It's good practice to handle .then() and .catch() for the promises.
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 task to handle errors was optional, so I decided to skip it for simplicity)
(in fix added simple catch)
}) => { | ||
const [comments, setComments] = useState<Comment[] | null>(null); | ||
const [IsLoading, setIsLoading] = useState(false); | ||
const [errorMsg, setErrorMsg] = 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 variable 'IsLoading' does not follow the camelCase naming convention. It should be renamed to 'isLoading'.
src/components/PostDetails.tsx
Outdated
</div> | ||
{errorMsg && !IsLoading && ( | ||
<div className="notification is-danger" data-cy="CommentsError"> | ||
Something went wrong |
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 error message is hardcoded which is not a good practice. Instead, display the error message returned from the API.
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 comment, but, I think, in example all values are hard coded with Something went wrong
. Changed to API message in fix.
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 work, approve ✅
return () => { | ||
document.removeEventListener('click', handleEvent); | ||
}; |
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.
👍
DEMO LINK