-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
add task solution #2744
Open
Dorosh90
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
Dorosh90: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
add task solution #2744
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
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 |
---|---|---|
@@ -1,14 +1,59 @@ | ||
/* eslint-disable max-len */ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import 'bulma/css/bulma.css'; | ||
import '@fortawesome/fontawesome-free/css/all.css'; | ||
|
||
import { TodoList } from './components/TodoList'; | ||
import { TodoFilter } from './components/TodoFilter'; | ||
import { TodoModal } from './components/TodoModal'; | ||
import { Loader } from './components/Loader'; | ||
import { Todo } from './types/Todo'; | ||
import { getTodos } from './api'; | ||
|
||
export const App: React.FC = () => { | ||
const [loader, setLoader] = useState(true); | ||
const [allTodos, setAllTodos] = useState<Todo[]>([]); | ||
const [filteredTodos, setFilteredTodos] = useState<Todo[]>([]); | ||
const [filter, setFilter] = useState(''); | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
|
||
useEffect(() => { | ||
getTodos() | ||
.then(todos => { | ||
setAllTodos(todos); | ||
setFilteredTodos(todos); | ||
}) | ||
.finally(() => setLoader(false)); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const filterTodosList = () => { | ||
let result = allTodos; | ||
|
||
switch (filter) { | ||
case 'active': | ||
result = allTodos.filter(todo => !todo.completed); | ||
break; | ||
|
||
case 'completed': | ||
result = allTodos.filter(todo => todo.completed); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
if (searchQuery) { | ||
result = result.filter(todo => | ||
todo.title.toLowerCase().includes(searchQuery.toLowerCase()), | ||
); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
setFilteredTodos(filterTodosList()); | ||
}, [filter, allTodos, searchQuery]); | ||
|
||
return ( | ||
<> | ||
<div className="section"> | ||
|
@@ -17,18 +62,18 @@ export const App: React.FC = () => { | |
<h1 className="title">Todos:</h1> | ||
|
||
<div className="block"> | ||
<TodoFilter /> | ||
<TodoFilter | ||
currentFilter={filter} | ||
setFilter={setFilter} | ||
query={searchQuery} | ||
setQuery={setSearchQuery} | ||
/> | ||
</div> | ||
|
||
<div className="block"> | ||
<Loader /> | ||
<TodoList /> | ||
</div> | ||
{loader ? <Loader /> : <TodoList todos={filteredTodos} />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
</div> | ||
</div> | ||
</div> | ||
|
||
<TodoModal /> | ||
</> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,30 +1,57 @@ | ||
export const TodoFilter = () => ( | ||
<form className="field has-addons"> | ||
<p className="control"> | ||
<span className="select"> | ||
<select data-cy="statusSelect"> | ||
<option value="all">All</option> | ||
<option value="active">Active</option> | ||
<option value="completed">Completed</option> | ||
</select> | ||
</span> | ||
</p> | ||
interface Props { | ||
currentFilter: string; | ||
setFilter: (filter: string) => void; | ||
query: string; | ||
setQuery: (q: string) => void; | ||
} | ||
|
||
<p className="control is-expanded has-icons-left has-icons-right"> | ||
<input | ||
data-cy="searchInput" | ||
type="text" | ||
className="input" | ||
placeholder="Search..." | ||
/> | ||
<span className="icon is-left"> | ||
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
export const TodoFilter: React.FC<Props> = ({ | ||
currentFilter, | ||
setFilter, | ||
query, | ||
setQuery, | ||
}) => { | ||
return ( | ||
<form className="field has-addons"> | ||
<p className="control"> | ||
<span className="select"> | ||
<select | ||
value={currentFilter} | ||
data-cy="statusSelect" | ||
onChange={e => setFilter(e.currentTarget.value)} | ||
> | ||
<option value="all">All</option> | ||
<option value="active">Active</option> | ||
<option value="completed">Completed</option> | ||
</select> | ||
</span> | ||
</p> | ||
|
||
<span className="icon is-right" style={{ pointerEvents: 'all' }}> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
<button data-cy="clearSearchButton" type="button" className="delete" /> | ||
</span> | ||
</p> | ||
</form> | ||
); | ||
<p className="control is-expanded has-icons-left has-icons-right"> | ||
<input | ||
value={query} | ||
data-cy="searchInput" | ||
type="text" | ||
className="input" | ||
placeholder="Search..." | ||
onChange={event => setQuery(event.currentTarget.value)} | ||
/> | ||
<span className="icon is-left"> | ||
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
|
||
{query.length > 0 && ( | ||
<span className="icon is-right" style={{ pointerEvents: 'all' }}> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
<button | ||
data-cy="clearSearchButton" | ||
type="button" | ||
className="delete" | ||
onClick={() => setQuery('')} | ||
/> | ||
</span> | ||
)} | ||
</p> | ||
</form> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,100 +1,87 @@ | ||
import React from 'react'; | ||
import { useState } from 'react'; | ||
import { Todo } from '../../types/Todo'; | ||
import classNames from 'classnames'; | ||
import { TodoModal } from '../TodoModal'; | ||
|
||
export const TodoList: React.FC = () => ( | ||
<table className="table is-narrow is-fullwidth"> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th> | ||
<span className="icon"> | ||
<i className="fas fa-check" /> | ||
</span> | ||
</th> | ||
<th>Title</th> | ||
<th> </th> | ||
</tr> | ||
</thead> | ||
interface Props { | ||
todos: Todo[]; | ||
} | ||
|
||
<tbody> | ||
<tr data-cy="todo" className=""> | ||
<td className="is-vcentered">1</td> | ||
<td className="is-vcentered" /> | ||
<td className="is-vcentered is-expanded"> | ||
<p className="has-text-danger">delectus aut autem</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button data-cy="selectButton" className="button" type="button"> | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
<tr data-cy="todo" className="has-background-info-light"> | ||
<td className="is-vcentered">2</td> | ||
<td className="is-vcentered" /> | ||
<td className="is-vcentered is-expanded"> | ||
<p className="has-text-danger">quis ut nam facilis et officia qui</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button data-cy="selectButton" className="button" type="button"> | ||
<span className="icon"> | ||
<i className="far fa-eye-slash" /> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
export const TodoList: React.FC<Props> = ({ todos }) => { | ||
const [isTodoModal, setIsTodoModal] = useState<null | number>(null); | ||
|
||
<tr data-cy="todo" className=""> | ||
<td className="is-vcentered">1</td> | ||
<td className="is-vcentered" /> | ||
<td className="is-vcentered is-expanded"> | ||
<p className="has-text-danger">delectus aut autem</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button data-cy="selectButton" className="button" type="button"> | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
const handleCloseModal = () => { | ||
setIsTodoModal(null); | ||
}; | ||
|
||
<tr data-cy="todo" className=""> | ||
<td className="is-vcentered">6</td> | ||
<td className="is-vcentered" /> | ||
<td className="is-vcentered is-expanded"> | ||
<p className="has-text-danger"> | ||
qui ullam ratione quibusdam voluptatem quia omnis | ||
</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button data-cy="selectButton" className="button" type="button"> | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
return ( | ||
<div className="block"> | ||
<table className="table is-narrow is-fullwidth"> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th> | ||
<span className="icon"> | ||
<i className="fas fa-check" /> | ||
</span> | ||
</th> | ||
<th>Title</th> | ||
<th> </th> | ||
</tr> | ||
</thead> | ||
|
||
<tr data-cy="todo" className=""> | ||
<td className="is-vcentered">8</td> | ||
<td className="is-vcentered"> | ||
<span className="icon" data-cy="iconCompleted"> | ||
<i className="fas fa-check" /> | ||
</span> | ||
</td> | ||
<td className="is-vcentered is-expanded"> | ||
<p className="has-text-success">quo adipisci enim quam ut ab</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button data-cy="selectButton" className="button" type="button"> | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
<tbody> | ||
{todos.map(todo => { | ||
return ( | ||
<tr data-cy="todo" className="" key={todo.id}> | ||
<td className="is-vcentered">{todo.id}</td> | ||
<td className="is-vcentered"> | ||
{todo.completed && ( | ||
<span className="icon" data-cy="iconCompleted"> | ||
<i className="fas fa-check"></i> | ||
</span> | ||
)} | ||
</td> | ||
<td className="is-vcentered is-expanded"> | ||
<p | ||
className={classNames({ | ||
'has-text-success': todo.completed, | ||
'has-text-danger': !todo.completed, | ||
})} | ||
> | ||
{todo.title} | ||
</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button | ||
data-cy="selectButton" | ||
className="button" | ||
type="button" | ||
onClick={() => setIsTodoModal(todo.id)} | ||
> | ||
<span className="icon"> | ||
<i | ||
className={classNames('far', { | ||
'fa-eye': todo.id !== isTodoModal, | ||
' fa-eye-slash': todo.id === isTodoModal, | ||
})} | ||
></i> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
{isTodoModal && ( | ||
<TodoModal | ||
todoId={isTodoModal} | ||
todos={todos} | ||
onClose={handleCloseModal} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
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.
The
filter
switch statement should include a case for 'all' to ensure that all todos are displayed when this filter is selected. Currently, the default case does not handle this explicitly, which might lead to unexpected behavior.