-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: master
Are you sure you want to change the base?
solution #1540
Conversation
There was a problem hiding this 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]); |
There was a problem hiding this comment.
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
There was a problem hiding this 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 => { |
There was a problem hiding this comment.
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
const activeTodosCount = todos.filter(todo => !todo.completed).length; | ||
|
||
const completedTodos = todos.filter(todo => todo.completed); |
There was a problem hiding this comment.
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
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; | ||
} | ||
}); | ||
}; |
There was a problem hiding this comment.
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 && ( |
There was a problem hiding this comment.
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)
{todos.length > 0 && ( | |
{!!todos.length && ( |
src/components/Footer/Footer.tsx
Outdated
{Object.values(FilterType).map(filter => ( | ||
<a | ||
key={filter} | ||
href={`#/${filter === FilterType.All ? '' : filter.toLowerCase()}`} |
There was a problem hiding this comment.
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? 🤔
href={`#/${filter === FilterType.All ? '' : filter.toLowerCase()}`} | |
href={`#/${filter !== FilterType.All && filter.toLowerCase()}`} |
DEMO LINK