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

Develop #1489

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

Develop #1489

wants to merge 6 commits into from

Conversation

Svidruk
Copy link

@Svidruk Svidruk commented Oct 22, 2024

Copy link

@hma-3 hma-3 left a comment

Choose a reason for hiding this comment

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

LGTM!
Have just a few suggestions below

Comment on lines 21 to 24
const handleErrorMessage = (error: ErrorMessages) => {
setErrorMessage(error);
setTimeout(handleErrorReset, 3000);
};
Copy link

Choose a reason for hiding this comment

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

don't forget to clear timeout

updateTodo(id, updatedTodo)
.then(todo => {
setTodos(currentTodos =>
currentTodos.map(t => (t.id === id ? { ...t, ...todo } : t)),
Copy link

Choose a reason for hiding this comment

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

[CHECKLIST] A variable name should describe what is stored in it (it's about your variable t)

Comment on lines 86 to 90
setIsReceivingAnswer(true);
setLoadingTodoIds(currentIds => [
...currentIds,
...completedTodos.map(todo => todo.id),
]);
Copy link

Choose a reason for hiding this comment

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

your function handleTodoDelete already has this logic

Comment on lines 104 to 108
setIsReceivingAnswer(true);
setLoadingTodoIds(currentIds => [
...currentIds,
...todosToUpdate.map(todo => todo.id),
]);
Copy link

Choose a reason for hiding this comment

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

your function handleTodoDelete already has this logic

same, but this time handleTodoUpdate

Comment on lines 56 to 63
{todos.length > 0 && <button
type="button"
className={cn('todoapp__toggle-all', {
active: areAllCompleted,
})}
data-cy="ToggleAllButton"
onClick={onToggleAll}
/>}
Copy link

Choose a reason for hiding this comment

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

wrap <button /> in brackets for better readability

Copy link

@igorkruz igorkruz 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 solution

Comment on lines 25 to 29
useEffect(() => {
getTodos()
.then(setTodos)
.catch(() => handleErrorMessage(ErrorMessages.UNABLE_TO_LOAD_TODO));
}, []);

Choose a reason for hiding this comment

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

Move the useEffect to the end of code
Placing useEffect at the end improves readability by letting developers first grasp the main logic before seeing side effects. This promotes clearer structure and consistency in the codebase.

Comment on lines 25 to 29
useEffect(() => {
getTodos()
.then(setTodos)
.catch(() => handleErrorMessage(ErrorMessages.UNABLE_TO_LOAD_TODO));
}, []);

Choose a reason for hiding this comment

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

It's better to move the logic inside the useEffect hook to a separate function, as it improves code readability, reusability, and makes testing easier. It also helps keep useEffect focused on side effects.

@Svidruk Svidruk requested a review from igorkruz October 24, 2024 11:09
Copy link

@igorkruz igorkruz 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.

3 participants