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

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

solution #901

wants to merge 6 commits into from

Conversation

vlkzmn
Copy link

@vlkzmn vlkzmn commented Aug 21, 2023

Copy link

@Anastasiia-Svintsova Anastasiia-Svintsova left a comment

Choose a reason for hiding this comment

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

Almost done!

src/App.tsx Outdated
.catch(() => setErrorMessage(`Can't load posts from ${user.name}`))
.finally(() => setLoading(false));
}
}, [user]);

Choose a reason for hiding this comment

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

The errorMessage value is missing in the dependencies

Suggested change
}, [user]);
}, [user, errorMessage]);

Copy link
Author

@vlkzmn vlkzmn Aug 21, 2023

Choose a reason for hiding this comment

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

Hi! don't understand why

.then(setComments)
.catch(() => setCommentsLoadError("Can't load comments for current post"))
.finally(() => setLoading(false));
}, [post]);

Choose a reason for hiding this comment

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

Add correct dependencies here

Copy link
Author

Choose a reason for hiding this comment

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

don't understand why

Choose a reason for hiding this comment

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

and then you dont need extra dependencies here

>
<div className="message-header">
<a href={`mailto:${comment.email}`} data-cy="CommentAuthor">
{comment.name}

Choose a reason for hiding this comment

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

Don't forget about the destructuring

Copy link
Author

Choose a reason for hiding this comment

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

I think that destructuring is not needed here, at the top of the code there is an object with which there will be a conflict

Choose a reason for hiding this comment

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

you dont need whole obj here, so you can easily to make it here

Copy link
Author

Choose a reason for hiding this comment

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

And what do you suggest to do?

const [userName, setUserName] = useState('Choose a user');
const dropdownSelect = useRef<HTMLDivElement>(null);

function handleSelectUser(user: User) {

Choose a reason for hiding this comment

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

Use arrow functions for better readability


export const UserSelector: React.FC<Props> = ({ users, onSetUser }) => {
const [dropdown, setDropdown] = useState(false);
const [userName, setUserName] = useState('Choose a user');

Choose a reason for hiding this comment

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

The initial value should be null if there is no user. And add a conditional rendering instead

Suggested change
const [userName, setUserName] = useState('Choose a user');
const [userName, setUserName] = useState(null);

Copy link
Author

Choose a reason for hiding this comment

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

I have initial value user === null in app.tsx
Here initial value 'Choose a user', and I don't need conditional rendering
What is the meaning of this action?

Choose a reason for hiding this comment

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

just logically that user name can't be choose a user
Here can be name or nothing, in our case null
image


export const UserSelector: React.FC<Props> = ({ users, onSetUser }) => {
const [dropdown, setDropdown] = useState(false);
const [userName, setUserName] = useState('Choose a user');

Choose a reason for hiding this comment

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

just logically that user name can't be choose a user
Here can be name or nothing, in our case null
image

Comment on lines 40 to 53
function handleDeleteComment(commentId: number) {
client.delete(`/comments/${commentId}`)
.then(() => {
setComments(
current => current?.filter(item => item.id !== commentId) || null,
);
setCommentsDelError([]);
})
.catch(() => setCommentsDelError(current => [...current, commentId]));
}

const handleAddNewComment = (newComment: Comment) => {
setComments(current => (current ? [...current, newComment] : [newComment]));
};

Choose a reason for hiding this comment

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

Use a consistent approach.

Or arrow functions, or function declaration

Copy link
Author

@vlkzmn vlkzmn Aug 21, 2023

Choose a reason for hiding this comment

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

#901 (comment)
В цьому компоненті ми робимо dropdown, тобто іметуємо select, а в select ми ж робимо перший option ось так,
<option value="0" disabled>Choose a user...</option>
це що теж не логічно, і тут таж історія. Є змінна userName, стартове значення 'Choose a user' яке логічно відносится до назви змінної, потім це значення змінюється на обране, та й ще умовний рендерінг не треба використовувати. Якщо це зауваження тільки про логічне що змінна не може мати таке значення, то я вважаю що це зайве.

@vlkzmn vlkzmn requested a review from sTorba24 August 21, 2023 17:26
Copy link

@maxim2310 maxim2310 left a comment

Choose a reason for hiding this comment

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

Great job overall! Just couple tiny things needs to be fixed before approval)

Comment on lines 22 to 32
if (commentsLoadError) {
setCommentsLoadError('');
}

if (comments) {
setComments(null);
}

if (addNewComment) {
setAddNewComment(false);
}

Choose a reason for hiding this comment

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

why do you need to reset this value here, better to create a separate func for this and do it in add func after clicking on submit but not on re rendering component

.then(setComments)
.catch(() => setCommentsLoadError("Can't load comments for current post"))
.finally(() => setLoading(false));
}, [post]);

Choose a reason for hiding this comment

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

and then you dont need extra dependencies here

>
<div className="message-header">
<a href={`mailto:${comment.email}`} data-cy="CommentAuthor">
{comment.name}

Choose a reason for hiding this comment

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

you dont need whole obj here, so you can easily to make it here

@vlkzmn
Copy link
Author

vlkzmn commented Aug 21, 2023

#901 (comment)
You suggest destructuring?

@vlkzmn
Copy link
Author

vlkzmn commented Aug 21, 2023

#901 (comment)
#901 (comment)
Цей фрагмент коду завантажує список коментів при виборі чи зміні поста, він не має відношення до додавання нового поста, яке correct чи extra dependencies ви маєте на увазі?

@vlkzmn vlkzmn requested a review from maxim2310 August 21, 2023 18:47
Copy link

@anastasiia-tilikina anastasiia-tilikina 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 small issues in my comments.
and discuss other questions in the Slack chat. That would be faster and easier) 🙌 just tag mentors and ask your questions)

</p>
</div>

<div className="block">
{loading && (

Choose a reason for hiding this comment

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

use ternary operator here for conditional rendering


<p className="title is-4">Comments:</p>
{comments.map(comment => (

Choose a reason for hiding this comment

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

Suggested change
{comments.map(comment => (
{comments.map(({name, email, id, body})=> (

you can easily destructure your obj like this

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.

None yet

5 participants