From 78d6a452ed48a5b25e60f9007940ad185c92b41c Mon Sep 17 00:00:00 2001 From: bee98 <43488353+bee98@users.noreply.github.com> Date: Tue, 31 Mar 2020 09:07:58 +0700 Subject: [PATCH 1/4] Update App.js --- src/App.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 93d4b5e..900e5d8 100644 --- a/src/App.js +++ b/src/App.js @@ -3,16 +3,105 @@ 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: '', + }, + } + } + + 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}); + } + + handleSubmit(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 + /> +