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

task done #877

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

task done #877

wants to merge 4 commits into from

Conversation

pos1bl
Copy link

@pos1bl pos1bl commented Aug 3, 2023

Copy link

@IvanFesenko IvanFesenko 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. Some improvements required

src/App.tsx Outdated
Comment on lines 58 to 60
setComments(prevComments => prevComments
.filter(comment => comment.id !== id));
postService.deleteComment(id);

Choose a reason for hiding this comment

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

What happens when postService.deleteComment - will catch an error?

Comment on lines 20 to 25
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [text, setText] = useState('');
const [nameError, setNameError] = useState(false);
const [emailError, setEmailError] = useState(false);
const [textError, setTextError] = useState(false);

Choose a reason for hiding this comment

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

My assumption it shoud be 2 states instead of 6

Suggested change
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [text, setText] = useState('');
const [nameError, setNameError] = useState(false);
const [emailError, setEmailError] = useState(false);
const [textError, setTextError] = useState(false);
const [formFieds, setFormFieds] = useState({
name: '',
email: '',
text: '',
});
const [errorMessage, setErrorMessage] = useState('');

Copy link
Author

Choose a reason for hiding this comment

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

image
its a bad idea to create errorMessage, because we would use it 3 times.

Copy link
Author

Choose a reason for hiding this comment

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

and about object, if i change only name, it will rerender all object. to my mind, its better to use 3 useStates.

Choose a reason for hiding this comment

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

and about object, if i change only name, it will rerender all object. to my mind, its better to use 3 useStates.

FYI: You probably meant that we will change the entire object stored in the state, but that's not a problem. we do not render an object. we render the component (jsx that is written below), and re-create every variable (including) functions during the render. Having different states would be useful if you use memorization hooks with different variables in the dependency arrays.

Comment on lines 45 to 59
if (!name.trim()) {
setNameError(true);
}

if (!email.trim()) {
setEmailError(true);
}

if (!text.trim()) {
setTextError(true);
}

if (!name.trim() || !email.trim() || !text.trim()) {
return;
}

Choose a reason for hiding this comment

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

Create separate variables instead of 6 times calls trim()

@@ -14,24 +98,33 @@ export const NewCommentForm: React.FC = () => {
name="name"
id="comment-author-name"
placeholder="Name Surname"
className="input is-danger"
value={name}
onChange={(event) => handleNameChange(event.target.value)}

Choose a reason for hiding this comment

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

Instead of additiona callback get target.value in handleNameChange
Fix all similar cases

Suggested change
onChange={(event) => handleNameChange(event.target.value)}
onChange={handleNameChange}

Comment on lines 76 to 78
return (
<article className="message is-small" data-cy="Comment">
<div className="message-header">

Choose a reason for hiding this comment

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

Dont forget about key prop

Comment on lines 45 to 46
return (
<tr data-cy="Post">

Choose a reason for hiding this comment

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

Same here

Comment on lines 54 to 60
<a
href={`#user-${user.id}`}
onClick={() => handleSelect(user)}
className={classNames(
'dropdown-item',
{ 'is-active': selectedUser?.id === user.id },
)}

Choose a reason for hiding this comment

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

And here

@pos1bl pos1bl requested a review from IvanFesenko August 3, 2023 13:51
src/App.tsx Outdated
Comment on lines 17 to 26
const [users, setUsers] = useState<User[]>([]);
const [posts, setPosts] = useState<Post[]>([]);
const [comments, setComments] = useState<Comment[]>([]);
const [selectedUser, setSelectedUser] = useState<User | null>(null);
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const [isCmntsLoading, setIsCmntsLoading] = useState(false);
const [isCmntsError, setIsCmntsError] = useState(false);
const [isWriting, setIsWriting] = useState(false);

Choose a reason for hiding this comment

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

there are too many states and logic in App.tsx
try to move part of them to other components

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

const nameValidate = !name.trim;

Choose a reason for hiding this comment

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

Suggested change
const nameValidate = !name.trim;
const isNameValide = !!name.trim;

for boolean values, it's better to use such names

Comment on lines 20 to 25
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [text, setText] = useState('');
const [nameError, setNameError] = useState(false);
const [emailError, setEmailError] = useState(false);
const [textError, setTextError] = useState(false);

Choose a reason for hiding this comment

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

and about object, if i change only name, it will rerender all object. to my mind, its better to use 3 useStates.

FYI: You probably meant that we will change the entire object stored in the state, but that's not a problem. we do not render an object. we render the component (jsx that is written below), and re-create every variable (including) functions during the render. Having different states would be useful if you use memorization hooks with different variables in the dependency arrays.

@pos1bl pos1bl requested a review from TarasHoliuk August 4, 2023 10:39
Copy link

@volodymyr-soltys97 volodymyr-soltys97 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 improve your code

Comment on lines 53 to 54
{users.map(user => (
<a

Choose a reason for hiding this comment

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

Use a destructuring for user

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Well done 🔥

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