diff --git a/package-lock.json b/package-lock.json index a86dbc13..b73187de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6864,8 +6864,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -6883,13 +6882,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6902,18 +6899,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -7016,8 +7010,7 @@ }, "inherits": { "version": "2.0.4", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -7027,7 +7020,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7040,20 +7032,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7070,7 +7059,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -7151,8 +7139,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -7162,7 +7149,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7238,8 +7224,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -7269,7 +7254,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7287,7 +7271,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7326,13 +7309,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } } @@ -12889,8 +12870,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -12908,13 +12888,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -12927,18 +12905,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -13041,8 +13016,7 @@ }, "inherits": { "version": "2.0.4", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -13052,7 +13026,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -13065,20 +13038,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -13095,7 +13065,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -13176,8 +13145,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -13187,7 +13155,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -13263,8 +13230,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -13294,7 +13260,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -13312,7 +13277,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -13351,13 +13315,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -13671,8 +13633,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -13690,13 +13651,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -13709,18 +13668,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -13823,8 +13779,7 @@ }, "inherits": { "version": "2.0.4", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -13834,7 +13789,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -13847,20 +13801,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -13877,7 +13828,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -13958,8 +13908,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -13969,7 +13918,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -14045,8 +13993,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -14076,7 +14023,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -14094,7 +14040,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -14133,13 +14078,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } }, diff --git a/src/App.js b/src/App.js index 556b5fbc..589f9dad 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,62 @@ -import React from 'react'; +import React from "react"; +import TodoList from "./components/TodoList"; +import TodoForm from "./components/TodoForm"; class App extends React.Component { - // you will need a place to store your state in this component. - // design `App` to be the parent component of your application. - // this component is going to take care of state, and any change handlers you need to work with your state + constructor() { + super(); + this.state = { + todos: [ + { + task: "Organize Garage", + id: 1528817077286, + completed: false + }, + { + task: "Bake Cookies", + id: 1528817084358, + completed: false + } + ] + }; + } + + addItem = taskName => { + const newTodo = { + task: taskName, + id: new Date(), + completed: false + }; + this.setState({ + todos: [...this.state.todos, newTodo] + }); + }; + + toggleCompleted = id => { + this.setState({ + todos: this.set.todos.map(todo => { + if (todo.id === id) { + return { + ...todo, + completed: !todo.completed + }; + } else { + return todo; + } + }) + }); + }; render() { return (
-

Welcome to your Todo App!

+

Todo List: MVP

+ +
); } } - export default App; diff --git a/src/components/Todo.js b/src/components/Todo.js index e69de29b..cec93604 100644 --- a/src/components/Todo.js +++ b/src/components/Todo.js @@ -0,0 +1,16 @@ +import React, { useState } from "react"; + +function Todo(props) { + return ( +
+

props.toggleCompleted(props.todo.id)} + > + {props.todo.task} +

+
+ ); +} + +export default Todo; diff --git a/src/components/TodoForm.js b/src/components/TodoForm.js index e69de29b..1d26a299 100644 --- a/src/components/TodoForm.js +++ b/src/components/TodoForm.js @@ -0,0 +1,41 @@ +import React, { Component } from "react"; + +export default class TodoForm extends Component { + constructor() { + super(); + this.state = { + todoText: "" + }; + } + + handleChanges = e => { + const { name, value } = e.target; + this.setState({ + [name]: value + }); + }; + + handleSubmit = e => { + e.preventDefault(); + this.props.addItem(this.state.todoText); + this.setState({ + todoText: "" + }); + }; + render() { + return ( +
+
+ + + +
+
+ ); + } +} diff --git a/src/components/TodoList.js b/src/components/TodoList.js index dfd3d8f1..b2a9c8e3 100644 --- a/src/components/TodoList.js +++ b/src/components/TodoList.js @@ -1,2 +1,12 @@ -// your components will all go in this `component` directory. -// feel free to change this component.js into TodoList.js +import React from "react"; +import Todo from "./Todo"; + +export default function TodoList(props) { + return ( +
+ {props.todos.map(todo => ( + + ))} +
+ ); +} diff --git a/src/index.js b/src/index.js index b597a442..466f4017 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import App from './App'; +import React from "react"; +import ReactDOM from "react-dom"; +import App from "./App"; -ReactDOM.render(, document.getElementById('root')); + ReactDOM.render(, document.getElementById("root"));