diff --git a/src/components/App.js b/src/components/App.js
index 8082369..24d5512 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -7,14 +7,6 @@ import TodoListCreationModal from './TodoListCreationModal';
class App extends React.Component {
- //state = {
- // todoArray: [{
- // id: 0,
- // isDone: false,
- // name: 'This is a quick task'
- // }]
- //}
-
state = {
mode: 'NONE',
todoArrayList: [{
@@ -23,8 +15,13 @@ class App extends React.Component {
todoList: [{
id: 0,
isDone: false,
- name: 'This is a quick task'
- }
+ name: 'hi'
+ },
+ {
+ id: 1,
+ isDone: false,
+ name: 'bye'
+ }
]
}
]
@@ -39,7 +36,7 @@ class App extends React.Component {
todoList: [{
id: 0,
isDone: false,
- name: 'This is a quick task'
+ name: ''
}
]
}
@@ -58,38 +55,43 @@ class App extends React.Component {
}
createNewTodo = listId => {
- const currentList = this.state.todoArrayList.filter(todo => {
- if(listId === todo.id) return true;
+ const currentList = this.state.todoArrayList.find(todo => {
+ if(listId == todo.id) return true;
});
+
+ console.log(currentList);
+
let lastTodoId = 0;
if(currentList.todoList.length > 0) lastTodoId = currentList.todoList[currentList.todoList.length-1].id;
- //let addToArray = {
- // id: lastTodoArray.id + 1,
- // isDone: false,
- // name: ''
- //}
-
- //currentArray.push(addToArray);
- //this.setState({
- // todoArray: currentArray
- //});
+ this.setState({
+ todoArrayList: this.state.todoArrayList.map(todoArray => {
+ if(listId === todoArray.id) todoArray.todoList = [...todoArray.todoList, {
+ id: lastTodoId + 1,
+ isDone: false,
+ name: 'ok'
+ }];
+ return todoArray;
+ })
+ },() => console.log(this.state))
}
- changeTodo = (id, changedTodo) => {
- let upcomingTodoArray = this.state.todoArray.map(todo => {
- if(id === todo.id) {
- todo = changedTodo;
- }
- return todo;
- })
- console.log(upcomingTodoArray);
+
+
+ changeTodo = (listId, changedTodo) => {
this.setState({
- todoArray: upcomingTodoArray
- })
+ todoArrayList: this.state.todoArrayList.map(todoArray => {
+ if(listId == todoArray.id){
+ todoArray.todoList = todoArray.todoList.map(todo => {
+ if(todo.id == changedTodo.id) return changedTodo;
+ return todo;
+ })
+ }
+ return todoArray;
+ })
+ },() => console.log(this.state))
}
-
deleteTodo = id => {
let upcomingTodoArray = this.state.todoArray.filter(todo => {
if(id == todo.id) {
@@ -105,20 +107,12 @@ class App extends React.Component {
render() {
return(
-
-
-
Tesonet Todo List
-
-
-
-
-
+
} />
} />
- } />
-
+ } />
diff --git a/src/components/CheckBox.js b/src/components/CheckBox.js
index 3c531f7..39b8f49 100644
--- a/src/components/CheckBox.js
+++ b/src/components/CheckBox.js
@@ -5,7 +5,7 @@ class Checkbox extends React.Component {
return(
diff --git a/src/components/TodoCard.js b/src/components/TodoCard.js
index f1646e4..a6aeb8e 100644
--- a/src/components/TodoCard.js
+++ b/src/components/TodoCard.js
@@ -3,19 +3,41 @@ import Checkbox from './CheckBox';
class TodoCard extends React.Component {
-
- onChange = () => {
-
+ state = {
+ id: 0,
+ isDone: false,
+ name: ''
}
- onCheckboxChange = () => {
- this.props.changeTodo(this.props.todo.id, {
+ componentDidMount() {
+ console.log(this.props)
+ this.setState({
id: this.props.todo.id,
- isDone: !this.props.isDone,
+ isDone: this.props.isDone,
name: this.props.name
})
}
+ onCheckboxChange = () => {
+ this.setState({
+ isDone: !this.state.isDone
+ }, () => this.props.changeTodo(this.props.listId, {
+ id: this.state.id,
+ isDone: this.state.isDone,
+ name: this.state.name
+ }))
+ }
+
+ onInputChange = (changedInput) => {
+ this.setState({
+ name: changedInput
+ }, () => this.props.changeTodo(this.props.listId, {
+ id: this.state.id,
+ isDone: this.state.isDone,
+ name: this.state.name
+ }))
+ }
+
render() {
return(
@@ -24,11 +46,10 @@ class TodoCard extends React.Component {
-
+
-
-
+ this.onInputChange(e.target.value)} type="text" placeholder="What do you want to do?" />
diff --git a/src/components/TodoList.js b/src/components/TodoList.js
index fdd4800..e85ed72 100644
--- a/src/components/TodoList.js
+++ b/src/components/TodoList.js
@@ -1,14 +1,58 @@
import React from 'react';
import TodoCard from './TodoCard';
-
+import TodoMenu from './TodoMenu';
class TodoList extends React.Component {
+ state = {
+ id: 0,
+ name: "",
+ todoList: [{
+ id: 0,
+ isDone: false,
+ name: ''
+ }]
+ };
+
+ componentDidMount() {
+ this.getStateFromParent();
+ console.log('TODOList:' );
+ console.log(this.state);
+ }
+
+
+
+
+ createNewTodo = () => {
+ this.props.createTodo(this.state.id);
+ let lastTodoId = 0;
+ if(this.state.todoList.length > 0) lastTodoId = this.state.todoList[this.state.todoList.length-1].id;
+
+ this.setState({
+ todoList: [...this.state.todoList, {
+ id: lastTodoId + 1,
+ isDone: false,
+ name: ''
+ }]
+ },console.log(this.state))
+ }
+
+ getStateFromParent = () => {
+ const todo = this.props.todoArray.find(todoParam => {
+ if(todoParam.id == this.props.match.params.id) return true;
+ })
+ console.log(this.props);
+ this.setState({
+ id: todo.id,
+ name: todo.name,
+ todoList: todo.todoList
+ },() => console.log(this.state))
+ }
renderCards = () => {
return(
- this.props.todoArray.map(todo => {
+ this.state.todoList.map(todo => {
return(
-
+
);
})
);
@@ -17,6 +61,7 @@ class TodoList extends React.Component {
render() {
return(
+
{this.renderCards()}
);
diff --git a/src/components/TodoListCard.js b/src/components/TodoListCard.js
index 6b63c09..dd5817a 100644
--- a/src/components/TodoListCard.js
+++ b/src/components/TodoListCard.js
@@ -1,10 +1,10 @@
import React from 'react';
+import history from '../history';
class TodoListCard extends React.Component {
-
render() {
return (
-
+
history.push(`/todo/${this.props.TodoList.id}`)}>
{this.props.TodoList.name}
diff --git a/src/components/TodoMenu.js b/src/components/TodoMenu.js
new file mode 100644
index 0000000..221857f
--- /dev/null
+++ b/src/components/TodoMenu.js
@@ -0,0 +1,16 @@
+import React from 'react'
+import history from '../history';
+
+
+const TodoMenu = (props) => {
+ return(
+
+
history.push('/')}>{props.menuName}
+
+
+
+
+ )
+}
+
+export default TodoMenu;
\ No newline at end of file
diff --git a/src/components/TodoPage.js b/src/components/TodoPage.js
index 889c097..4118cc1 100644
--- a/src/components/TodoPage.js
+++ b/src/components/TodoPage.js
@@ -1,6 +1,7 @@
import React from 'react';
+import history from '../history';
import TodoListCard from './TodoListCard';
-
+import TodoMenu from './TodoMenu';
class TodoPage extends React.Component {
@@ -17,10 +18,14 @@ class TodoPage extends React.Component {
render() {
return (
-
- {this.renderTodoListCards()}
+
+
history.push('/todo/create')}/>
+
+ {this.renderTodoListCards()}
+
+
);
}
}