-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
c867b63
commit fea7cd5
Showing
14 changed files
with
439 additions
and
146 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,50 @@ | ||
import { useContext } from 'react'; | ||
import { TodoContext } from '../../context/TodoContext'; | ||
import { Status, TodoContextType } from '../../types/types'; | ||
import classNames from 'classnames'; | ||
|
||
export const Footer: React.FC = () => { | ||
const { | ||
counterTodos, | ||
setStatus, | ||
status, | ||
counterCompletedTodos, | ||
clearCompleted, | ||
} = useContext(TodoContext) as TodoContextType; | ||
|
||
return ( | ||
<footer className="todoapp__footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{counterTodos} items left | ||
</span> | ||
|
||
<nav className="filter" data-cy="Filter"> | ||
{Object.values(Status).map(statusValue => ( | ||
<a | ||
key={statusValue} | ||
href={`#/${statusValue.toLocaleLowerCase()}`} | ||
className={classNames('filter__link', { | ||
selected: status === statusValue, | ||
})} | ||
data-cy={`FilterLink${statusValue}`} | ||
onClick={() => { | ||
setStatus(statusValue); | ||
}} | ||
> | ||
{statusValue} | ||
</a> | ||
))} | ||
</nav> | ||
|
||
<button | ||
type="button" | ||
className="todoapp__clear-completed" | ||
data-cy="ClearCompletedButton" | ||
disabled={counterCompletedTodos === 0} | ||
onClick={clearCompleted} | ||
> | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useContext, useState } from 'react'; | ||
import { TodoContext } from '../../context/TodoContext'; | ||
import { TodoContextType } from '../../types/types'; | ||
import classNames from 'classnames'; | ||
|
||
export const Header: React.FC = () => { | ||
const [query, setQuery] = useState(''); | ||
const { addTodo, todos, counterCompletedTodos, toggleAllTodo, inputRef } = | ||
useContext(TodoContext) as TodoContextType; | ||
|
||
const reset = () => { | ||
setQuery(''); | ||
}; | ||
|
||
const handleQueryChange = (newValue: string) => { | ||
setQuery(newValue); | ||
}; | ||
|
||
const handleSubmit = (event: React.FormEvent) => { | ||
event.preventDefault(); | ||
|
||
if (!query.trim()) { | ||
return; | ||
} | ||
|
||
addTodo({ | ||
id: 0, | ||
title: query.trim(), | ||
completed: false, | ||
}); | ||
|
||
reset(); | ||
}; | ||
|
||
return ( | ||
<header className="todoapp__header"> | ||
{todos.length !== 0 && ( | ||
<button | ||
type="button" | ||
className={classNames('todoapp__toggle-all', { | ||
active: counterCompletedTodos === todos.length, | ||
})} | ||
data-cy="ToggleAllButton" | ||
onClick={toggleAllTodo} | ||
/> | ||
)} | ||
|
||
<form onSubmit={handleSubmit}> | ||
<input | ||
data-cy="NewTodoField" | ||
type="text" | ||
className="todoapp__new-todo" | ||
placeholder="What needs to be done?" | ||
value={query} | ||
onChange={event => { | ||
handleQueryChange(event.target.value); | ||
}} | ||
ref={inputRef} | ||
/> | ||
</form> | ||
</header> | ||
); | ||
}; |
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 './Header'; |
Oops, something went wrong.