-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 solution #2684
base: master
Are you sure you want to change the base?
add solution #2684
Changes from 5 commits
de4a8fc
b88fcb2
e586c1a
9f9390f
b91cc60
706481f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
import React, { Dispatch, SetStateAction } from 'react'; | ||
import { Filters } from '../../types/Filters'; | ||
|
||
<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> | ||
type Props = { | ||
query: string; | ||
setQuery: Dispatch<SetStateAction<string>>; | ||
setFilter: Dispatch<SetStateAction<Filters>>; | ||
}; | ||
|
||
<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> | ||
); | ||
export const TodoFilter: React.FC<Props> = props => { | ||
const { query, setQuery, setFilter } = props; | ||
|
||
return ( | ||
<form className="field has-addons"> | ||
<p className="control"> | ||
<span className="select"> | ||
<select | ||
data-cy="statusSelect" | ||
onChange={e => setFilter(e.target.value as Filters)} | ||
> | ||
<option value={Filters.All}>All</option> | ||
<option value={Filters.Active}>Active</option> | ||
<option value={Filters.Completed}>Completed</option> | ||
</select> | ||
Comment on lines
+21
to
+23
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. we can show these options using 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. It's good idea, but I don't know how to use map to the enum object Filters: enum Filters { 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.
You can use |
||
</span> | ||
</p> | ||
|
||
<p className="control is-expanded has-icons-left has-icons-right"> | ||
<input | ||
data-cy="searchInput" | ||
type="text" | ||
className="input" | ||
placeholder="Search..." | ||
value={query} | ||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => | ||
setQuery(event.target.value) | ||
} | ||
/> | ||
<span className="icon is-left"> | ||
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
|
||
{query && ( | ||
<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> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,100 +1,77 @@ | ||||||
import React from 'react'; | ||||||
import React, { Dispatch, SetStateAction } from 'react'; | ||||||
import cn from 'classnames'; | ||||||
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[]; | ||||||
selectTodoId: Dispatch<SetStateAction<number | null>>; | ||||||
selectedTodoId: number | 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> = props => { | ||||||
const { todos, selectTodoId, selectedTodoId } = props; | ||||||
|
||||||
<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"> | ||||||
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> | ||||||
</th> | ||||||
<th>Title</th> | ||||||
<th> </th> | ||||||
</tr> | ||||||
</thead> | ||||||
|
||||||
<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> | ||||||
|
||||||
<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.length === 0 ? ( | ||||||
<tr> | ||||||
<td colSpan={4}>No data</td> | ||||||
</tr> | ||||||
) : ( | ||||||
todos.map(todo => ( | ||||||
<tr data-cy="todo" className="" key={todo.id}> | ||||||
<td className="is-vcentered">{todo.id}</td> | ||||||
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.
Suggested change
let's remove redundant class name 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. forgot to use 'has-background-info-light' class if todo is selected |
||||||
<td className="is-vcentered"> | ||||||
{todo.completed && ( | ||||||
<span className="icon" data-cy="iconCompleted"> | ||||||
<i className="fas fa-check" /> | ||||||
</span> | ||||||
)} | ||||||
</td> | ||||||
<td className="is-vcentered is-expanded"> | ||||||
<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" | ||||||
onClick={() => selectTodoId(todo.id)} | ||||||
> | ||||||
<span className="icon"> | ||||||
<i | ||||||
className={cn( | ||||||
'far', | ||||||
todo.id === selectedTodoId ? 'fa-eye-slash' : 'fa-eye', | ||||||
)} | ||||||
/> | ||||||
</span> | ||||||
</button> | ||||||
</td> | ||||||
</tr> | ||||||
)) | ||||||
)} | ||||||
</tbody> | ||||||
</table> | ||||||
); | ||||||
}; |
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.
let's move
completed, active, all
to the enumThere 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.
enum Filters already exists in types folder: enum Filters {
All = 'all',
Active = 'active',
Completed = 'completed',
}