-
Notifications
You must be signed in to change notification settings - Fork 2.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
8bf0f2b
commit c8c8022
Showing
5 changed files
with
252 additions
and
126 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
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,78 @@ | ||
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> | ||
|
||
<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> | ||
|
||
<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> | ||
); | ||
import React, { useEffect, useState } from 'react'; | ||
import { Todo } from '../../types/Todo'; | ||
import { getTodos } from '../../api'; | ||
|
||
type Props = { | ||
setTodos: React.Dispatch<React.SetStateAction<Todo[] | null>>; | ||
}; | ||
|
||
export const TodoFilter: React.FC<Props> = ({ setTodos }) => { | ||
const [qwerty, setQwerty] = useState(''); | ||
const [status, setStatus] = useState(''); | ||
|
||
useEffect(() => { | ||
getTodos().then(serverTodos => { | ||
let currentTodos: Todo[] | null = serverTodos.filter(todo => | ||
todo.title.toLocaleLowerCase().includes(qwerty.toLocaleLowerCase()), | ||
); | ||
|
||
switch (status) { | ||
case 'active': | ||
currentTodos = currentTodos.filter(todo => !todo.completed); | ||
break; | ||
case 'completed': | ||
currentTodos = currentTodos.filter(todo => todo.completed); | ||
break; | ||
} | ||
|
||
setTodos(currentTodos); | ||
}); | ||
}, [qwerty, status, setTodos]); | ||
|
||
return ( | ||
<form className="field has-addons"> | ||
<p className="control"> | ||
<span className="select"> | ||
<select | ||
data-cy="statusSelect" | ||
onChange={e => setStatus(e.target.value)} | ||
> | ||
<option value="all">All</option> | ||
<option value="active">Active</option> | ||
<option value="completed">Completed</option> | ||
</select> | ||
</span> | ||
</p> | ||
|
||
<p className="control is-expanded has-icons-left has-icons-right"> | ||
<input | ||
data-cy="searchInput" | ||
type="text" | ||
className="input" | ||
placeholder="Search..." | ||
value={qwerty} | ||
onChange={e => { | ||
setQwerty(e.target.value); | ||
}} | ||
/> | ||
<span className="icon is-left"> | ||
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
|
||
<span className="icon is-right" style={{ pointerEvents: 'all' }}> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
{qwerty && ( | ||
<button | ||
data-cy="clearSearchButton" | ||
type="button" | ||
className="delete" | ||
onClick={() => { | ||
setQwerty(''); | ||
}} | ||
/> | ||
)} | ||
</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,86 @@ | ||
import React from 'react'; | ||
import { Todo } from '../../types/Todo'; | ||
|
||
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> | ||
type Props = { | ||
todos: Todo[] | null; | ||
setModalVisible: React.Dispatch<React.SetStateAction<boolean>>; | ||
setSelectedTodo: React.Dispatch<React.SetStateAction<Todo | null>>; | ||
selectedTodo: Todo | null; | ||
}; | ||
|
||
<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> = ({ | ||
setModalVisible, | ||
todos, | ||
setSelectedTodo, | ||
selectedTodo, | ||
}) => { | ||
// console.log(todos); | ||
|
||
<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" /> | ||
function mapTodos() { | ||
return todos?.map(todo => ( | ||
<tr | ||
data-cy="todo" | ||
className={ | ||
selectedTodo?.id === todo.id ? 'has-background-info-light' : undefined | ||
} | ||
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" /> | ||
</span> | ||
</button> | ||
)} | ||
</td> | ||
</tr> | ||
|
||
<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 | ||
className={todo.completed ? 'has-text-success' : 'has-text-danger'} | ||
> | ||
{todo.title} | ||
</p> | ||
</td> | ||
<td className="has-text-right is-vcentered"> | ||
<button data-cy="selectButton" className="button" type="button"> | ||
<button | ||
data-cy="selectButton" | ||
className="button" | ||
type="button" | ||
onClick={() => { | ||
setModalVisible(true); | ||
setSelectedTodo(todo); | ||
}} | ||
> | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
<i | ||
className={ | ||
selectedTodo && selectedTodo.id === todo.id | ||
? 'far fa-eye-slash' | ||
: 'far fa-eye' | ||
} | ||
/> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
)); | ||
} | ||
|
||
<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"> | ||
return ( | ||
<table className="table is-narrow is-fullwidth"> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th> | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
<i className="fas fa-check" /> | ||
</span> | ||
</button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
</th> | ||
<th>Title</th> | ||
<th> </th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody>{mapTodos()}</tbody> | ||
</table> | ||
); | ||
}; |
Oops, something went wrong.