Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,612 changes: 2,746 additions & 3,866 deletions package-lock.json

Large diffs are not rendered by default.

69 changes: 68 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,80 @@
import React from 'react';
import TodoForm from './components/TodoForm';
import TodoList from './components/TodoList'

const list = [
{
task: 'Organize Garage',
id: 1528817077286,
completed: false
},
{
task: 'Bake Cookies',
id: 1528817084358,
completed: false
}
];

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 = {
list:list
}
}

toggleFinished = (todoId) => {
const updatedTodoList = this.state.list.map(todo => {
if (todo.id === todoId) {
return {...todo, finished: !todo.finished};
}
else{
return todo;
}
});
this.setState({
...this.state,
list: updatedTodoList
});
}

addTodo = (todoName) => {
this.setState({
...this.state,
list: [
...this.state.list,
{
task: todoName,
id: Date.now(),
finished: false
}
]
})
}

clearFinished = () => {
this.setState({
...this.state,
list: this.state.list.filter(todo => !todo.finished)
})
}

render() {
return (
<div>
<div className="App">
<div className="header">
<h2>Welcome to your Todo App!</h2>
<TodoForm addTodo={this.addTodo} />
</div>
<TodoList
list={this.state.list}
toggleFinished={this.toggleFinished}
clearFinished={this.clearFinished}
/>
</div>
);
}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

const Todo = props => {
return (
<div
onClick={() => props.toggleFinished(props.todo.id)}
className={`todo${props.todo.finished ? ' finished' : ''}`}
>
<p>{props.todo.task}</p>
</div>
);
};

export default Todo;
36 changes: 36 additions & 0 deletions src/components/TodoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react";

class TodoForm extends React.Component {
constructor() {
super();
this.state = {
newTask: ''
}
}
handleChanges = e => {
this.setState({
...this.state,
newTask: e.target.value
})
};

handleSubmit = e => {
e.preventDefault();
this.props.addTodo(this.state.newTask);
}
render(){
return (
<form onSubmit={this.handleSubmit}>
<input
type="text"
name="todo"
value={this.state.newTask}
onChange={this.handleChanges}
/>
<button>Add</button>
</form>
);
}
}

export default TodoForm;
19 changes: 17 additions & 2 deletions src/components/TodoList.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
// 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"

const TodoList = props => {
return (
<div className='todo-list'>
{props.list.map(todo => (
<Todo key={todo.id} todo={todo} toggleFinished={props.toggleFinished} />
))}
<button onClick={props.clearFinished} className="clear-button">
Clear Finished
</button>
</div>
);
};

export default TodoList;
4 changes: 4 additions & 0 deletions src/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.todo.finished {
background-color: #d17d7c;
text-decoration: line-through;
}