Skip to content
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 #1196

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Solution #1196

wants to merge 10 commits into from

Conversation

ab3MN
Copy link

@ab3MN ab3MN commented Nov 13, 2024

Copy link

@polosanya polosanya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Let's improve your code a bit

@@ -1,2 +1,3 @@
/build
/node_modules
/src

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of it? It is better not to ignore eslint

const [isFormOpen, setFormOpen] = useState(false);

useLayoutEffect(() => {
fetchComments();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pay attention to the warning
image

Comment on lines 63 to 65
{isLoading && <Loader />}

{!isLoading && CommentsView}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ternary operator can be used here

post: Post;
}

const PostListItem: FC<PostListItemProps> = memo(({ post }) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a separate directory for this component


<tbody>
{posts.map(post => (
<tr data-cy="Post" key={post.id}>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guees this element should be inside PostItem component

const [selectedPost, setSelectedPost] = useState<Post | null>(null);
const { posts, postsError, isLoadingPosts } = usePosts(selectedUser);

const handleSelectUser = async (user: User) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


export const useComments = (postId: number) => {
const [comments, setComments] = useState<Comment[]>([]);
const [isLoading, setLoading] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [isLoading, setLoading] = useState(false);
const [isLoading, setIsLoading] = useState(false);

export const useComments = (postId: number) => {
const [comments, setComments] = useState<Comment[]>([]);
const [isLoading, setLoading] = useState(false);
const [isError, setError] = useState('');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [isError, setError] = useState('');
const [error, setError] = useState('');

is prefix should be used only for boolean values

@ab3MN ab3MN requested a review from polosanya November 15, 2024 13:34
Copy link

@StasSokolov1 StasSokolov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix a few comments before approving, overall it looks good to me

Comment on lines 16 to 18
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [body, setBody] = useState('');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we combine these three states into one, so we don't need three function for updates of name, email, body

Comment on lines 45 to 76
const handleChangeName = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
setName(event.target.value);

if (nameError) {
setNameError('');
}
},
[nameError],
);

const handleChangeEmail = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
setEmail(event.target.value);

if (emailError) {
setEmailError('');
}
},
[emailError],
);

const handleChangeBody = useCallback(
(event: ChangeEvent<HTMLTextAreaElement>) => {
setBody(event.target.value);

if (bodyError) {
setBodyError('');
}
},
[bodyError],
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be only one function after combine

Copy link

@StasSokolov1 StasSokolov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants