diff --git a/frontend/components/App.js b/frontend/components/App.js
index 38b7a2f5..b131a7c9 100644
--- a/frontend/components/App.js
+++ b/frontend/components/App.js
@@ -1,11 +1,66 @@
-import React from 'react'
+import React from "react";
+import Form from "./Form";
+import TodoList from "./TodoList";
+
+const list = [
+ {
+ name: "Wash Dishes",
+ id: 100,
+ completed: false,
+ },
+];
export default class App extends React.Component {
+ constructor() {
+ super();
+ this.state = {
+ list: list,
+ };
+ }
+
+ addItem = (e, item) => {
+ e.preventDefault();
+ const newList = {
+ name: item,
+ id: Date.now(),
+ completed: false,
+ };
+ this.setState({
+ ...this.state,
+ list: [...this.state.list, newList],
+ });
+ };
+
+ toggleItem = (itemId) => {
+ console.log(itemId);
+ this.setState({
+ ...this.state,
+ list: this.state.list.map((items) => {
+ if (itemId === items.id) {
+ return { ...items, completed: !items.completed };
+ }
+ return items;
+ }),
+ });
+ };
+
+ clearCompleted = () => {
+ this.setState({
+ ...this.state,
+ list: this.state.list.filter((item) => {
+ if (!item.completed) return item;
+ }),
+ });
+ };
render() {
return (
-
- Todo App
+
+
+
+
+
+
- )
+ );
}
}
diff --git a/frontend/components/Form.js b/frontend/components/Form.js
index 30fbc48d..ce7dc070 100644
--- a/frontend/components/Form.js
+++ b/frontend/components/Form.js
@@ -1,11 +1,38 @@
-import React from 'react'
+import React from "react";
export default class Form extends React.Component {
+ constructor() {
+ super();
+ this.state = {
+ item: "",
+ };
+ }
+ handleChange = (evt) => {
+ evt.preventDefault();
+ this.setState({ ...this.state, item: evt.target.value });
+ };
+
+ submitForm = (evt) => {
+ evt.preventDefault();
+ this.props.addItem(evt, this.state.item);
+ this.setState({ ...this.state, item: "" });
+ };
render() {
return (
-
- Form
-
- )
+
+ );
}
}
diff --git a/frontend/components/Todo.js b/frontend/components/Todo.js
index ca86f981..d77f0aa5 100644
--- a/frontend/components/Todo.js
+++ b/frontend/components/Todo.js
@@ -1,11 +1,17 @@
-import React from 'react'
+import React from "react";
export default class Todo extends React.Component {
+ constructor(props) {
+ super(props);
+ }
render() {
return (
-
- Todo
+
this.props.toggleItem(this.props.item.id)}
+ >
+
{this.props.item.name}
- )
+ );
}
}
diff --git a/frontend/components/TodoList.js b/frontend/components/TodoList.js
index 95410373..2d2db857 100644
--- a/frontend/components/TodoList.js
+++ b/frontend/components/TodoList.js
@@ -1,11 +1,18 @@
-import React from 'react'
+import React from "react";
+import Todo from "./Todo";
export default class TodoList extends React.Component {
+ constructor(props) {
+ super(props);
+ }
render() {
return (
-
- TodoList
+
+
TodoList
+ {this.props.list.map((item) => (
+
+ ))}
- )
+ );
}
}