Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request Alexis and Jesse React-I #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import TodoList from './Components/TodoList';

const App = () => (
<div>
<h2>Todo App</h2>

<TodoList />
</div>
);

Expand Down
19 changes: 19 additions & 0 deletions src/Components/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

function Todo(props) {
const strikeHandler = () => {
props.toggleCompleted(props.index)
}

const strikeThrough = {textDecoration: props.todo.clicked ? 'line-through' : 'none'}

return (
<div style={strikeThrough} className="todo">
<input type="checkbox" value={props.clicked} onClick={strikeHandler} />
{props.todo.body}
</div>

);
}

export default Todo
55 changes: 55 additions & 0 deletions src/Components/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { Component } from 'react';
import Todo from './Todo'


class TodoList extends Component {
constructor() {
super();

this.state = {
Todos: [],
nextTodo: "",
};
}


toggleCompleted = (index) => {
const todos = this.state.Todos;
todos[index].clicked = !todos[index].clicked
this.setState({todos})
}

todoChange = event => {
this.setState({nextTodo: event.target.value });
}

todoSubmit = event => {
event.preventDefault();
const nextTodos = {body: this.state.nextTodo, clicked: false};
const todosArray = this.state.Todos;
todosArray.push(nextTodos);
this.setState({Todos: todosArray, nextTodo: "" });
};

render() {
return (
<div>
{this.state.Todos.map((todo, index) => {
return(
<Todo todo={todo} toggleCompleted={this.toggleCompleted} index={index} key={index} />
);
})}
<form onSubmit={this.todoSubmit}>
<input
type="text"
value={this.state.nextTodo}
onChange={this.todoChange}
/>
</form>

</div>
);
}
}

export default TodoList;
Loading