| 
 | 1 | +import React, { Component } from 'react';  | 
 | 2 | +import Todo from '../../components/Todo/Todo';  | 
 | 3 | +import TodoDetail from '../../components/TodoDetail/TodoDetail';  | 
 | 4 | +import "./TodoList.css";  | 
 | 5 | +import NewTodo from '../NewTodo/NewTodo';  | 
 | 6 | +import { NavLink } from 'react-router-dom';  | 
 | 7 | + | 
 | 8 | +class TodoList extends Component {  | 
 | 9 | +	state = {  | 
 | 10 | +		todos: [  | 
 | 11 | +			{ id: 1, title: 'SWPP', content: 'take swpp class', done: true},  | 
 | 12 | +			{ id: 2, title: 'Movie', content: 'watch movie', done: false },  | 
 | 13 | +			{ id: 3, title: 'Dinner', content: 'eat dinner', done: false },  | 
 | 14 | +		],  | 
 | 15 | +		selectedTodo: null,  | 
 | 16 | +	}  | 
 | 17 | + | 
 | 18 | +	render() {  | 
 | 19 | +		const todos = this.state.todos.map((td) => {  | 
 | 20 | +			return ( <Todo key={td.id} title={td.title} done={td.done} clicked={() => this.clickTodoHandler(td)}/> );  | 
 | 21 | +		});  | 
 | 22 | +		let todoDetail = null;  | 
 | 23 | +		if (this.state.selectedTodo) {  | 
 | 24 | +			todoDetail = <TodoDetail title={this.state.selectedTodo.title}  | 
 | 25 | +				content={this.state.selectedTodo.content} />  | 
 | 26 | +		}  | 
 | 27 | + | 
 | 28 | +		return (  | 
 | 29 | +			<div className='TodoList'>  | 
 | 30 | +				<div className='title'>{this.props.title}</div>  | 
 | 31 | +				<div className='todos'>{todos}</div>  | 
 | 32 | +				{todoDetail}  | 
 | 33 | +				<NavLink to='/new-todo' exact>New Todo</NavLink>  | 
 | 34 | +			</div>  | 
 | 35 | +		);  | 
 | 36 | +	}  | 
 | 37 | + | 
 | 38 | +	clickTodoHandler = td => {  | 
 | 39 | +		if (this.state.selectedTodo === td) {  | 
 | 40 | +			this.setState({selectedTodo: null});  | 
 | 41 | +		} else {  | 
 | 42 | +			this.setState({selectedTodo: td});  | 
 | 43 | +		}  | 
 | 44 | +	}  | 
 | 45 | +}  | 
 | 46 | + | 
 | 47 | + | 
 | 48 | + | 
 | 49 | +export default TodoList;  | 
0 commit comments