diff --git a/frontend/components/App.js b/frontend/components/App.js index 38b7a2f5..8bfab102 100644 --- a/frontend/components/App.js +++ b/frontend/components/App.js @@ -1,10 +1,80 @@ import React from 'react' +import TodoList from './TodoList' +import TodoForm from './Form' + + export default class App extends React.Component { + constructor(){ + super(); + this.state = { + todos:[ + { + name: 'Organize Garage', + id: 1528817077286, + completed: false + }, + { + name: 'Bake Cookies', + id: 1528817084358, + completed: false + } + ] + } + } + + handleAdd = (task) => { + + const newTodo = { + name: task, + id:Date.now(), + completed: false + } + + this.setState({ + ...this.state, + todos: [...this.state.todos, newTodo] + }); + } + + handleClear = () => { + this.setState({ + ...this.state, + todos:this.state.todos.filter(todo => { + return (todo.completed === false) + }) + }) + } + + handleToggle = (clickedId) => { + + this.setState({ + ...this.state, + todos: this.state.todos.map(todo => { + if(todo.id=== clickedId){ + return {...todo, + completed: !todo.completed + } + } + return todo; + }) + + }) + } + render() { + const {todos} = this.state + return (
- Todo App +

Todos

+ + + + + + +
) } diff --git a/frontend/components/Form.js b/frontend/components/Form.js index 30fbc48d..7065fc1f 100644 --- a/frontend/components/Form.js +++ b/frontend/components/Form.js @@ -1,11 +1,28 @@ import React from 'react' -export default class Form extends React.Component { - render() { - return ( -
- Form -
- ) +export default class TodoForm extends React.Component{ + constructor(){ + super(); + this.state = { + input:'' + } + } + handleSubmit= (e)=> { + e.preventDefault(); + this.props.handleAdd(this.state.input); + } + + handleChange = (e) => { + this.setState({ + ...this.State, + input: e.target.value + }) + } + + render(){ + return(
+ + +
) } } diff --git a/frontend/components/Todo.js b/frontend/components/Todo.js index ca86f981..ad544683 100644 --- a/frontend/components/Todo.js +++ b/frontend/components/Todo.js @@ -1,11 +1,10 @@ import React from 'react' export default class Todo extends React.Component { - render() { - return ( -
- Todo -
- ) + handleClick =() => { + this.props.handleToggle(this.props.todo.id); } + render(){ + return(
  • {this.props.todo.name} {this.props.todo.completed?completed : }
  • ) + }; } diff --git a/frontend/components/TodoList.js b/frontend/components/TodoList.js index 95410373..172776da 100644 --- a/frontend/components/TodoList.js +++ b/frontend/components/TodoList.js @@ -1,11 +1,13 @@ import React from 'react' - -export default class TodoList extends React.Component { - render() { - return ( -
    - TodoList -
    - ) +import Todo from './Todo' +export default class TodoList extends React.Component{ + render(){ + return( ) } }