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

sol #863

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

sol #863

wants to merge 3 commits into from

Conversation

GGsmou
Copy link

@GGsmou GGsmou commented Jul 23, 2023

Copy link

@juljaVysotska juljaVysotska 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!

I found some issues, please check and fix them

Best regards

setOpen(false);
};

document.addEventListener('click', (event) => {

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 */

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.

Copy link
Author

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', {

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.

Copy link
Author

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';

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.


setComments(comments.filter((c) => c.id !== comment.id));

client.delete(`/comments/${comment.id}`);

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.

Copy link
Author

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('');

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'.

</div>
{errorMsg && !IsLoading && (
<div className="notification is-danger" data-cy="CommentsError">
Something went wrong

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.

Copy link
Author

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.

Copy link

@And678 And678 left a comment

Choose a reason for hiding this comment

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

Good work, approve ✅

Comment on lines +39 to +41
return () => {
document.removeEventListener('click', handleEvent);
};
Copy link

Choose a reason for hiding this comment

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

👍

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.

4 participants