forked from njsh4261/swpp-react-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathTodoList.js
More file actions
51 lines (45 loc) · 1.47 KB
/
Copy pathTodoList.js
File metadata and controls
51 lines (45 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React,{Component} from 'react';
import Todo from '../../components/Todo/todo';
import './TodoList.css';
import TodoDetail from '../../components/TodoDetail/TodoDetail';
import NewTodo from '../TodoList/NewTodo/NewTodo';
import { NavLink } from 'react-router-dom';
class TodoList extends Component{
state={
todos:[
{ id:1, title: 'SWPP', content:'take swpp class',done: true},
{ id:2, title: 'Movie', content:'watch movie',done: false},
{ id:3, title: 'Dinner', content:'eat dinner',done: false},
],
selectedTodo:null,
}
clickTodoHandler = td=>
{
if(this.state.selectedTodo===td)
{
this.setState({selectedTodo:null});
}
else{
this.setState({selectedTodo:td});
}
}
render()
{
const todos= this.state.todos.map((td)=>{
return (<Todo key={td.id} title={td.title} done={td.done} clicked={()=>this.clickTodoHandler(td)} />);
})
let todoDetail=null;
if(this.state.selectedTodo){
todoDetail=<NewTodo title={this.state.selectedTodo.title} content={this.state.selectedTodo.content}/>
}
return(
<div className='TodoList'>
<div className='title'>{this.props.title}</div>
<div className='todos'>{todos}</div>
{todoDetail}
<NavLink to='/new-todo' exact>New Todo</NavLink>
</div>
);
}
}
export default TodoList;