-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0da38f6
commit 809c804
Showing
4 changed files
with
83 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
import React from 'react'; | ||
|
||
import { Todo } from '../../types/Todo'; | ||
import { FilterOptions } from '../../types/FilterOptions'; | ||
import classNames from 'classnames'; | ||
|
||
type Props = { | ||
todos: Todo[]; | ||
onDelete: (todoId: number) => void; | ||
currentFilter: string; | ||
setCurrentFilter: (currentFilter: string) => void; | ||
loading: boolean; | ||
}; | ||
|
||
export const Footer: React.FC<Props> = ({ | ||
todos, | ||
onDelete, | ||
currentFilter, | ||
setCurrentFilter, | ||
loading, | ||
}) => { | ||
const activeTodos = todos.filter(todo => !todo.completed).length; | ||
|
||
const handleClearCompleted = () => { | ||
const completedTodoId = todos | ||
.filter(todo => todo.completed) | ||
.map(todo => todo.id); | ||
|
||
completedTodoId.forEach(todo => { | ||
onDelete(todo); | ||
}); | ||
}; | ||
|
||
return ( | ||
<footer className="todoapp__footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{`${activeTodos} items left`} | ||
</span> | ||
|
||
<nav className="filter" data-cy="Filter"> | ||
{Object.values(FilterOptions).map(option => ( | ||
<a | ||
key={option} | ||
href={`#/${option}`} | ||
className={classNames('filter__link', { | ||
selected: currentFilter === option, | ||
})} | ||
data-cy={`FilterLink${option}`} | ||
onClick={() => setCurrentFilter(option)} | ||
> | ||
{option} | ||
</a> | ||
))} | ||
</nav> | ||
|
||
<button | ||
type="button" | ||
className="todoapp__clear-completed" | ||
data-cy="ClearCompletedButton" | ||
onClick={() => handleClearCompleted()} | ||
disabled={todos.every(todo => !todo.completed) || loading} | ||
> | ||
Clear completed | ||
</button> | ||
</footer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Footer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters