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

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

Conversation

taniabarkovskya
Copy link

Copy link

@Daniil-102 Daniil-102 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!

return () => {
clearTimeout(timeoutId);
};
}, [error]);

Choose a reason for hiding this comment

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

React Hook useEffect has a missing dependency: 'handleErrorClose'. Either include it or remove the dependency array

Copy link

@VolodymyrKirichenko VolodymyrKirichenko 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 🔥

setErrorTodos(ErrorType.NoErrors);
}, []);

const visibleTodos = todos.filter(todo => {

Choose a reason for hiding this comment

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

useMemo?

src/App.tsx Outdated
Comment on lines 45 to 47
const activeTodosCount = todos.filter(todo => !todo.completed).length;

const completedTodos = 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.

the same, useMemo?

src/App.tsx Outdated
Comment on lines 62 to 126
const onAddTodo = async (newTodo: Omit<Todo, 'id'>): Promise<void> => {
try {
const createdTodo = await createTodo(newTodo);

setTodos(currentTodos => [...currentTodos, createdTodo]);
} catch (error) {
setErrorTodos(ErrorType.Add);
throw error;
}
};

const onDeleteTodo = async (todoId: number) => {
setLoadingTodosIds(currentIds => [...currentIds, todoId]);
try {
await deleteTodo(todoId);
setTodos(currentTodos => currentTodos.filter(todo => todo.id !== todoId));
} catch (error) {
setErrorTodos(ErrorType.Delete);
throw error;
} finally {
setLoadingTodosIds(currentIds => currentIds.filter(id => id !== todoId));
}
};

const onDeleteAllCompleted = () => {
completedTodos.forEach(completedTodo => {
onDeleteTodo(completedTodo.id);
});
};

const onUpdateTodo = async (newTodo: Todo) => {
setLoadingTodosIds(currentIds => [...currentIds, newTodo.id]);
try {
const updatedTodo = await updateTodo(newTodo);

setTodos(currentTodos =>
currentTodos.map(todo => {
return todo.id === updatedTodo.id ? updatedTodo : todo;
}),
);
} catch (error) {
setErrorTodos(ErrorType.Update);
throw error;
} finally {
setLoadingTodosIds(currentIds =>
currentIds.filter(id => id !== newTodo.id),
);
}
};

const onUpdateToggleAll = () => {
todos.forEach(todo => {
if (todos.length === completedTodos.length) {
onUpdateTodo({ ...todo, completed: false });

return;
}

if (todo.completed === false) {
onUpdateTodo({ ...todo, completed: true });

return;
}
});
};

Choose a reason for hiding this comment

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

useCallback for all the cases?

src/App.tsx Outdated
onUpdateToggleAll={onUpdateToggleAll}
/>

{todos.length > 0 && (

Choose a reason for hiding this comment

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

better option(it will be converted to boolean value)

Suggested change
{todos.length > 0 && (
{!!todos.length && (

{Object.values(FilterType).map(filter => (
<a
key={filter}
href={`#/${filter === FilterType.All ? '' : filter.toLowerCase()}`}

Choose a reason for hiding this comment

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

better or no?what do u think? 🤔

Suggested change
href={`#/${filter === FilterType.All ? '' : filter.toLowerCase()}`}
href={`#/${filter !== FilterType.All && filter.toLowerCase()}`}

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