-
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
fc98b1a
commit 37bce69
Showing
7 changed files
with
118 additions
and
143 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import { Todo } from '../../types/Todo'; | ||
|
||
interface Props { | ||
todo: Todo; | ||
onSelectTodo: (todo: Todo) => void; | ||
selectedTodo: Todo | null; | ||
} | ||
|
||
export const TodoItem: React.FC<Props> = ({ | ||
todo, | ||
onSelectTodo, | ||
selectedTodo, | ||
}) => { | ||
const { id, title, completed } = todo; | ||
|
||
return ( | ||
<tr data-cy="todo" key={todo.id}> | ||
<td className="is-vcentered">{todo.id}</td> | ||
{completed ? ( | ||
<> | ||
<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">{title}</p> | ||
</td> | ||
</> | ||
) : ( | ||
<> | ||
<td className="is-vcentered"></td> | ||
<td className="is-vcentered is-expanded"> | ||
<p className="has-text-danger">{title}</p> | ||
</td> | ||
</> | ||
)} | ||
|
||
<td className="has-text-right is-vcentered"> | ||
<button | ||
data-cy="selectButton" | ||
className="button" | ||
type="button" | ||
onClick={() => onSelectTodo(todo)} | ||
> | ||
{selectedTodo?.id === id ? ( | ||
<span className="icon"> | ||
<i className="far fa-eye-slash" /> | ||
</span> | ||
) : ( | ||
<span className="icon"> | ||
<i className="far fa-eye" /> | ||
</span> | ||
)} | ||
</button> | ||
</td> | ||
</tr> | ||
); | ||
}; |
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 './TodoItem'; |
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 |
---|---|---|
|
@@ -5,29 +5,24 @@ import { getUser } from '../../api'; | |
import { Todo } from '../../types/Todo'; | ||
|
||
interface Props { | ||
selectedTodo: Todo | null; | ||
setModalVisible: React.Dispatch<React.SetStateAction<boolean>>; | ||
todo: Todo; | ||
onClose: () => void; | ||
} | ||
|
||
export const TodoModal: React.FC<Props> = ({ | ||
selectedTodo, | ||
setModalVisible, | ||
}) => { | ||
export const TodoModal: React.FC<Props> = ({ todo, onClose }) => { | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const [user, setUser] = useState<User | null>(null); | ||
|
||
useEffect(() => { | ||
if (selectedTodo) { | ||
getUser(selectedTodo.userId).then(selectedUser => { | ||
setUser(selectedUser); | ||
setLoading(false); | ||
}); | ||
} | ||
}, [selectedTodo]); | ||
getUser(todo.userId).then(selectedUser => { | ||
setUser(selectedUser); | ||
setLoading(false); | ||
}); | ||
}, [todo.userId]); | ||
|
||
return ( | ||
<div className="modal is-active" data-cy="modal"> | ||
<div className="modal-background" /> | ||
<div className="modal-background" onClick={onClose} /> | ||
{loading ? ( | ||
<Loader /> | ||
) : ( | ||
|
@@ -37,21 +32,20 @@ export const TodoModal: React.FC<Props> = ({ | |
className="modal-card-title has-text-weight-medium" | ||
data-cy="modal-header" | ||
> | ||
{`Todo #${selectedTodo?.id}`} | ||
{`Todo #${todo.id}`} | ||
</div> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
<button | ||
type="button" | ||
className="delete" | ||
data-cy="modal-close" | ||
onClick={() => setModalVisible(false)} | ||
onClick={onClose} | ||
/> | ||
</header> | ||
<div className="modal-card-body"> | ||
<p className="block" data-cy="modal-title"> | ||
{selectedTodo?.title} | ||
{todo.title} | ||
</p> | ||
{selectedTodo?.completed ? ( | ||
{todo.completed ? ( | ||
<p className="block" data-cy="modal-user"> | ||
<strong className="has-text-success">Done</strong> | ||
{' by '} | ||
|
@@ -70,40 +64,3 @@ export const TodoModal: React.FC<Props> = ({ | |
</div> | ||
); | ||
}; | ||
|
||
// <div className="modal is-active" data-cy="modal"> | ||
// <div className="modal-background" /> | ||
// | ||
// {true ? ( | ||
// <Loader /> | ||
// ) : ( | ||
// <div className="modal-card"> | ||
// <header className="modal-card-head"> | ||
// <div | ||
// className="modal-card-title has-text-weight-medium" | ||
// data-cy="modal-header" | ||
// > | ||
// Todo #2 | ||
// </div> | ||
// | ||
// {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
// <button type="button" className="delete" data-cy="modal-close" /> | ||
// </header> | ||
// | ||
// <div className="modal-card-body"> | ||
// <p className="block" data-cy="modal-title"> | ||
// quis ut nam facilis et officia qui | ||
// </p> | ||
// | ||
// <p className="block" data-cy="modal-user"> | ||
// {/* <strong className="has-text-success">Done</strong> */} | ||
// <strong className="has-text-danger">Planned</strong> | ||
// | ||
// {' by '} | ||
// | ||
// <a href="mailto:[email protected]">Leanne Graham</a> | ||
// </p> | ||
// </div> | ||
// </div> | ||
// )} | ||
// </div>; |
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,5 @@ | ||
export enum Filter { | ||
All = 'all', | ||
Active = 'active', | ||
Completed = 'completed', | ||
} |