Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Svidruk committed Oct 22, 2024
1 parent 5b88b71 commit bc36c1e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
10 changes: 9 additions & 1 deletion src/components/ErrorNotification/ErrorNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import { FC, useEffect } from 'react';
import { ErrorMessages } from '../../types/ErrorMessages';
import cn from 'classnames';

Expand All @@ -11,6 +11,14 @@ export const ErrorNotification: FC<Props> = ({
errorMessage,
onResetError,
}) => {
useEffect(() => {
const timerId = setTimeout(() => {
onResetError();
}, 3000);

return () => clearTimeout(timerId);
}, [errorMessage]);

Check warning on line 20 in src/components/ErrorNotification/ErrorNotification.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

React Hook useEffect has a missing dependency: 'onResetError'. Either include it or remove the dependency array. If 'onResetError' changes too often, find the parent component that defines it and wrap that definition in useCallback

return (
<div
data-cy="ErrorNotification"
Expand Down
18 changes: 10 additions & 8 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ export const Header: FC<Props> = ({

return (
<header className="todoapp__header">
{todos.length > 0 && <button
type="button"
className={cn('todoapp__toggle-all', {
active: areAllCompleted,
})}
data-cy="ToggleAllButton"
onClick={onToggleAll}
/>}
{todos.length > 0 && (
<button
type="button"
className={cn('todoapp__toggle-all', {
active: areAllCompleted,
})}
data-cy="ToggleAllButton"
onClick={onToggleAll}
/>
)}

<form onSubmit={handleSubmit}>
<input
Expand Down
16 changes: 4 additions & 12 deletions src/hooks/useTodos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const useTodos = () => {

const handleErrorMessage = (error: ErrorMessages) => {
setErrorMessage(error);
setTimeout(handleErrorReset, 3000);
};

useEffect(() => {
Expand All @@ -36,7 +35,7 @@ export const useTodos = () => {
addTodo(newTodo)
.then(todo => {
setTodos(currentTodos => [...currentTodos, todo]);
setNewTitle('')
setNewTitle('');
})
.catch(() => handleErrorMessage(ErrorMessages.UNABLE_TO_ADD_TODO))
.finally(() => {
Expand Down Expand Up @@ -68,7 +67,9 @@ export const useTodos = () => {
updateTodo(id, updatedTodo)
.then(todo => {
setTodos(currentTodos =>
currentTodos.map(t => (t.id === id ? { ...t, ...todo } : t)),
currentTodos.map(updatedTodo =>

Check failure on line 70 in src/hooks/useTodos.ts

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

'updatedTodo' is already declared in the upper scope on line 63 column 41
updatedTodo.id === id ? { ...updatedTodo, ...todo } : updatedTodo,
),
);
setEditedTodoId(null);
})
Expand All @@ -84,10 +85,6 @@ export const useTodos = () => {
const handleCompletedDelete = () => {
const completedTodos = todos.filter(todo => todo.completed);
setIsReceivingAnswer(true);
setLoadingTodoIds(currentIds => [
...currentIds,
...completedTodos.map(todo => todo.id),
]);

Promise.all(
completedTodos.map(completedTodo => handleTodoDelete(completedTodo.id)),
Expand All @@ -102,11 +99,6 @@ export const useTodos = () => {
: todos.filter(todo => !todo.completed);

setIsReceivingAnswer(true);
setLoadingTodoIds(currentIds => [
...currentIds,
...todosToUpdate.map(todo => todo.id),
]);

Promise.all(
todosToUpdate.map(todo =>
handleTodoUpdate(todo.id, { completed: newStatus }),
Expand Down

0 comments on commit bc36c1e

Please sign in to comment.