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 #891

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

Solution #891

wants to merge 5 commits into from

Conversation

outofs
Copy link

@outofs outofs commented Aug 12, 2023

Copy link

@DanilWeda DanilWeda left a comment

Choose a reason for hiding this comment

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

Good! Check comments and try to write improvements.

src/App.tsx Outdated
Comment on lines 26 to 28
getUsers()
.then(setUsers)
.catch(() => setIsError(true));

Choose a reason for hiding this comment

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

If you are good with async/await try to rewrite this code. But its no required.

src/App.tsx Outdated
Comment on lines 32 to 42
setLoading(true);
setSelectedPost(null);

if (selectedUser) {
getPosts(selectedUser.id)
.then(setPosts)
.catch(() => setIsError(true))
.finally(() => setLoading(false));
} else {
setLoading(false);
}

Choose a reason for hiding this comment

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

Try to rewrite this code, without else. Loading starts every time when updating the user, maybe you can add a condition first of all?

src/App.tsx Outdated
Comment on lines 61 to 62
!selectedUser
&& (

Choose a reason for hiding this comment

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

Please note, if we receive a 0 in these conditions, it will be reflected on our page.
In this case, we know that the value is not 0. But if we have a small chance of it, use !! for the type conversions.

Example: !!!selectedUser &&

src/App.tsx Outdated

<Loader />
{
loading

Choose a reason for hiding this comment

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

The best way to name the param isLoading.

src/App.tsx Outdated
>
Something went wrong!
</div>
{posts.length === 0 && selectedUser && !isError && (

Choose a reason for hiding this comment

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

!post.length

</p>
</div>

<div className="block">
<Loader />
{loading

Choose a reason for hiding this comment

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

isLoading

<p className="title is-4" data-cy="NoCommentsMessage">
No comments yet
</p>
{!isError && !loading && comments.length !== 0 && (

Choose a reason for hiding this comment

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

Suggested change
{!isError && !loading && comments.length !== 0 && (
{!loading && !isError && !!comments.length && (

type="button"
className="delete is-small"
aria-label="delete"
onClick={() => deleteCommentHandler(comment.id)}

Choose a reason for hiding this comment

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

You can write a handler function for it.

className={classNames('button is-link', {
'is-light': post.id !== selectedPost?.id,
})}
onClick={() => toggleSelectedPostHandler(post)}

Choose a reason for hiding this comment

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

You can write a handler for it.

className={classNames('dropdown-item', {
'is-active': user.id === selectedUser?.id,
})}
onClick={() => selectUserHandler(user)}

Choose a reason for hiding this comment

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

You can write a handler for it.

@outofs outofs requested a review from DanilWeda August 16, 2023 17:10
Comment on lines +27 to +31
const [formFields, setFormFields] = useState<FormFields>({
name: '',
email: '',
text: '',
});

Choose a reason for hiding this comment

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

Good work!

Comment on lines 41 to 53
const changNameHandler = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
setName(event.target.value);
setNameError(false);
setFormFields(currFields => ({
...currFields,
name: event.target.value,
}));

setFormErrors(currErrors => ({
...currErrors,
isNameError: false,
}));
};

Choose a reason for hiding this comment

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

Try to use one handler function for all fields.

Comment on lines +34 to +36
isNameError: false,
isEmailError: false,
isTextError: false,

Choose a reason for hiding this comment

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

Use the initial state for this error obj, and then for the clear function.

Comment on lines +138 to +140
isNameError: false,
isEmailError: false,
isTextError: false,

Choose a reason for hiding this comment

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

This is the same object, use in this place initialErrorState, for example.

Comment on lines +132 to +134
name: '',
email: '',
text: '',

Choose a reason for hiding this comment

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

This is the same object, use in this place initialFormState, for example.

</div>
)}
{/* eslint-disable-next-line no-extra-boolean-cast */}
{!!!posts.length && selectedUser && !isError && (

Choose a reason for hiding this comment

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

?

Copy link

@MarianVolytskyi MarianVolytskyi left a comment

Choose a reason for hiding this comment

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

Interesting work)

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.

Check out @DanilWeda last review, some things are not fixed yet

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