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

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

Conversation

antonina-klishch
Copy link

src/App.tsx Outdated
});
};

const removeComplatedTodos = (todosId: number[] | null) => {

Choose a reason for hiding this comment

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

Suggested change
const removeComplatedTodos = (todosId: number[] | null) => {
const removeCompletedTodos = (todosId: number[] | null) => {

src/App.tsx Outdated
setDeletedTodo(null);
});
});
}

Choose a reason for hiding this comment

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

set loading to false after this if block by default

Choose a reason for hiding this comment

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

by the way, why you need this if? you can trigger this function only if todosId array is not empty

src/App.tsx Outdated
const updateTodosAllStatus = (updatedTodos: Todo[]) => {
setErrorMessage('');
setIsLoading(true);
const changedTodoId: number[] = [];

Choose a reason for hiding this comment

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

pay attention to naming please

Suggested change
const changedTodoId: number[] = [];
const changedTodoIds: number[] = [];

src/App.tsx Outdated

setChangedTodo(changedTodoId);

const updatedTodoSirvice = updatedTodos.map(async (todo) => {

Choose a reason for hiding this comment

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

what is Sirvice?

src/App.tsx Outdated
Comment on lines 115 to 158
const updateTodosAllStatus = (updatedTodos: Todo[]) => {
setErrorMessage('');
setIsLoading(true);
const changedTodoId: number[] = [];

updatedTodos.forEach(updatedTodo => {
const similarTodo = todos.find(todo => todo.id === updatedTodo.id);

if (similarTodo && similarTodo.completed !== updatedTodo.completed) {
changedTodoId.push(similarTodo.id);
}
});

setChangedTodo(changedTodoId);

const updatedTodoSirvice = updatedTodos.map(async (todo) => {
try {
const todoChange = await todoService.updateTodo(todo);

return todoChange;
} catch (error) {
setErrorMessage(Message.NoUpdateTodo);

return todo;
}
});

Promise.all(updatedTodoSirvice)
.then((gettedTodos) => {
const gettedTodosId = gettedTodos.map(t => t.id);

setTodos(curT => curT.map(
item => (
gettedTodosId.includes(item.id)
? { ...item, completed: gettedTodos[0].completed }
: item
),
));
})
.finally(() => {
setIsLoading(false);
setChangedTodo(null);
});
};

Choose a reason for hiding this comment

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

this function should be refactored and simplified because it is hard to read. pay attention to naming

src/App.tsx Outdated
});
};

const removeTodoTitle = (todoId: number) => {

Choose a reason for hiding this comment

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

please memoize all functions what you passing to the child components

Choose a reason for hiding this comment

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

pay attention to this comment, use useMemo or useCallback for this purpose, it will optimize your code

src/App.tsx Outdated
Comment on lines 202 to 203
const visivleTodo = filterTodos(todos, todosStatus);
const activeTodos = todos.filter(todo => !todo.completed);

Choose a reason for hiding this comment

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

memoize

src/App.tsx Outdated
});
};

const removeTodoTitle = (todoId: number) => {

Choose a reason for hiding this comment

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

pay attention to this comment, use useMemo or useCallback for this purpose, it will optimize your code

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