diff --git a/frontend/components/App.js b/frontend/components/App.js index 38b7a2f5..e39c962c 100644 --- a/frontend/components/App.js +++ b/frontend/components/App.js @@ -1,10 +1,52 @@ import React from 'react' +import Form from './Form' +import TodoList from './TodoList'; export default class App extends React.Component { + constructor() { + super(); + this.state = { + data: [{ + name: "Obtain Cat", + id: Date.now(), + completed: false + }], + } + } + + handleSubmit = (e,item) => { + e.preventDefault(); + if(item){ + const newItem = { + name: item, + id: Date.now(), + completed: false + } + this.setState({data: [...this.state.data, newItem]}) + } + } + + toggleCompleted = itemId => { + this.setState({...this.state, data: this.state.data.map(task => { + if(task.id === itemId) { + return {...task,completed: !task.completed} + } + return task + })}) + } + + clearCompleted = () => { + this.setState({data: this.state.data.filter(task => { + if(!task.completed) return task; + })}) + } + + render() { return (
- Todo App + +
) } diff --git a/frontend/components/Form.js b/frontend/components/Form.js index 30fbc48d..276f8076 100644 --- a/frontend/components/Form.js +++ b/frontend/components/Form.js @@ -1,10 +1,29 @@ import React from 'react' + export default class Form extends React.Component { + constructor () { + super(); + this.state = { + form: '' + } + } + submit = (e,item) => { + this.props.submit(e,this.state.form) + this.setState({form: ''}) + } + + change = (e) => { + e.preventDefault() + this.setState({...this.state.form, form: e.target.value}) + } render() { return (
- Form + + + +
) } diff --git a/frontend/components/Todo.js b/frontend/components/Todo.js index ca86f981..d3de4ffc 100644 --- a/frontend/components/Todo.js +++ b/frontend/components/Todo.js @@ -1,10 +1,13 @@ import React from 'react' export default class Todo extends React.Component { + render() { return ( -
- Todo +
this.props.toggleCompleted(this.props.task.id)}> +

{this.props.task.name}

+
) } diff --git a/frontend/components/TodoList.js b/frontend/components/TodoList.js index 95410373..c04688da 100644 --- a/frontend/components/TodoList.js +++ b/frontend/components/TodoList.js @@ -1,10 +1,18 @@ import React from 'react' +import Todo from './Todo' export default class TodoList extends React.Component { + + + + render() { return ( -
- TodoList +
+ {this.props.data.map(task => ( + + ))} +
) } diff --git a/frontend/styles/styles.css b/frontend/styles/styles.css index fda8a420..cd2b183d 100644 --- a/frontend/styles/styles.css +++ b/frontend/styles/styles.css @@ -83,3 +83,7 @@ ul, form { .todo:hover { cursor: pointer; } + +.itemcompleted { + text-decoration: line-through; +} \ No newline at end of file