-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 #1064
Open
pasha1932
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
pasha1932:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
solution #1064
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,74 @@ | ||
import { useContext } from 'react'; | ||
import { | ||
TodosContext, | ||
TodosDispatchContext, | ||
} from '../TodoAppContext/TodoAppContext'; | ||
import classNames from 'classnames'; | ||
import { TodoStatus } from '../../types/TodoStatus'; | ||
|
||
export const Footer: React.FC = () => { | ||
const { todos, filterStatus } = useContext(TodosContext); | ||
const dispatch = useContext(TodosDispatchContext); | ||
const uncomletedTodos = todos.filter(todo => !todo.completed); | ||
|
||
return ( | ||
<footer className="todoapp__footer" data-cy="Footer"> | ||
<span className="todo-count" data-cy="TodosCounter"> | ||
{uncomletedTodos.length + ' items left'} | ||
</span> | ||
|
||
{/* Active link should have the 'selected' class */} | ||
<nav className="filter" data-cy="Filter"> | ||
<a | ||
href="#/" | ||
className={classNames('filter__link', { | ||
selected: filterStatus === TodoStatus.All, | ||
})} | ||
data-cy="FilterLinkAll" | ||
onClick={() => | ||
dispatch({ type: 'filterBy', payload: TodoStatus.All }) | ||
} | ||
> | ||
All | ||
</a> | ||
|
||
<a | ||
href="#/active" | ||
className={classNames('filter__link', { | ||
selected: filterStatus === TodoStatus.Active, | ||
})} | ||
data-cy="FilterLinkActive" | ||
onClick={() => | ||
dispatch({ type: 'filterBy', payload: TodoStatus.Active }) | ||
} | ||
> | ||
Active | ||
</a> | ||
|
||
<a | ||
href="#/completed" | ||
className={classNames('filter__link', { | ||
selected: filterStatus === TodoStatus.Completed, | ||
})} | ||
data-cy="FilterLinkCompleted" | ||
onClick={() => | ||
dispatch({ type: 'filterBy', payload: TodoStatus.Completed }) | ||
} | ||
> | ||
Completed | ||
</a> | ||
</nav> | ||
|
||
{/* this button should be disabled if there are no completed todos */} | ||
<button | ||
type="button" | ||
className="todoapp__clear-completed" | ||
data-cy="ClearCompletedButton" | ||
disabled={todos.length === uncomletedTodos.length} | ||
onClick={() => dispatch({ type: 'deleteCompletedTodos' })} | ||
> | ||
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,73 @@ | ||
import { useContext, useEffect, useRef, useState } from 'react'; | ||
import { | ||
TodosContext, | ||
TodosDispatchContext, | ||
} from '../TodoAppContext/TodoAppContext'; | ||
import classNames from 'classnames'; | ||
import { Todo } from '../../types/Todo'; | ||
|
||
export const Header: React.FC = () => { | ||
const [title, setTitle] = useState(''); | ||
const dispatch = useContext(TodosDispatchContext); | ||
const { todos } = useContext(TodosContext); | ||
const [isSubmitting, setIsSubmitting] = useState(false); | ||
const completedTodosLength = todos.filter(el => el.completed).length; | ||
const field = useRef<HTMLInputElement>(null); | ||
|
||
useEffect(() => { | ||
field.current?.focus(); | ||
}, [isSubmitting, todos]); | ||
|
||
const handleAdd = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
setIsSubmitting(true); | ||
|
||
if (!title.trim()) { | ||
return; | ||
} | ||
|
||
const newTodo: Todo = { | ||
id: +new Date(), | ||
title: title.trim(), | ||
completed: false, | ||
}; | ||
|
||
dispatch({ | ||
type: 'addTodo', | ||
payload: newTodo, | ||
}); | ||
setTitle(''); | ||
setIsSubmitting(false); | ||
}; | ||
|
||
return ( | ||
<header className="todoapp__header"> | ||
{/* this button should have `active` class only if all todos are completed */} | ||
{todos.length !== 0 && ( | ||
<button | ||
type="button" | ||
className={classNames('todoapp__toggle-all', { | ||
active: todos.length === completedTodosLength, | ||
})} | ||
data-cy="ToggleAllButton" | ||
onClick={() => { | ||
dispatch({ type: 'toggleAllStatuses' }); | ||
}} | ||
/> | ||
)} | ||
|
||
{/* Add a todo on form submit */} | ||
<form onSubmit={handleAdd}> | ||
<input | ||
data-cy="NewTodoField" | ||
type="text" | ||
className="todoapp__new-todo" | ||
placeholder="What needs to be done?" | ||
ref={field} | ||
value={title} | ||
onChange={e => setTitle(e.target.value)} | ||
/> | ||
</form> | ||
</header> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
don't forget to remove all logs