diff --git a/src/App.js b/src/App.js index 93d4b5e..5b27658 100644 --- a/src/App.js +++ b/src/App.js @@ -3,16 +3,110 @@ import ToDoListItem from "./ToDoListItem.js" import './App.css'; class App extends Component { + + constructor() { + super(); + this.state = { + toDoList: [ + { + title: "Me", + description: "Stay at home" + }, + { + title: "You", + description: "Stay at home" + }, + ], + item: { + title: '', + description: '', + }, + } + this.handleTitleEdit = this.handleTitleEdit.bind(this); + this.handleDesEdit = this.handleDesEdit.bind(this); + this.handleAddItem = this.handleAddItem.bind(this); + this.handleDeleteItem = this.handleDeleteItem.bind(this); + this.onSubmit = this.onSubmit.bind(this); + } + + handleTitleEdit(e) { + this.state.item.title = e.target.value; + this.setState({item: this.state.item}); + } + + handleDesEdit(e) { + this.state.item.description = e.target.value; + this.setState({item: this.state.item}); + } + + handleAddItem() { + this.state.toDoList.push(this.state.item); + } + + handleDeleteItem(index) { + this.state.toDoList.splice(index, 1); + this.setState({toDoList: this.state.toDoList}); + } + + onSubmit(e) { + this.handleAddItem(); + e.preventDefault(); + this.setState({ + item: { + title: '', + description: '' + } + }) + } + render() { + + const items = this.state.toDoList.map((item,index) => { + return ( + this.handleDeleteItem(index)} + /> + ) + }); + + return (
+ +
+
this.handleSubmit(e)}> + this.handleTitleEdit(e)} + placeholder="Title" + required + /> +