Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
15,289 changes: 15,289 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"grid-styled": "^5.0.2",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "2.0.4"
"react-scripts": "2.0.4",
"styled-components": "^4.0.2",
"yarn": "^1.10.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
24 changes: 24 additions & 0 deletions src/components/ToDoContainer/NewTodoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import { Flex, Box } from "grid-styled";
import { AddInputField, SubmitButton } from "./styles";

const NewTodoForm = ({ formSubmitted, newTodoChanged, newTodo }) => (
<div>
<Flex>
<Box ml={550} mt={50}>
<AddInputField
onChange={newTodoChanged}
id="newTodo"
name="newTodo"
placeholder="Add todo"
value={newTodo}
/>{" "}
<SubmitButton type="submit" onClick={formSubmitted}>
Add{" "}
</SubmitButton>{" "}
</Box>{" "}
</Flex>{" "}
</div>
);

export default NewTodoForm;
11 changes: 11 additions & 0 deletions src/components/ToDoContainer/TodoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import { DeleteButton } from "./styles";

const TodoItem = ({ index, todo, removeTodo }) => (
<li key={index}>
{" "}
{todo.title} <DeleteButton onClick={removeTodo}> Delete </DeleteButton>{" "}
</li>
);

export default TodoItem;
50 changes: 50 additions & 0 deletions src/components/ToDoContainer/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import TodoItem from "./TodoItem";
import { Flex, Box } from "grid-styled";
import { SearchInputField, Text } from "./styles";

const TodoList = ({ todos, filter, removeTodo, searchTodos }) => {
let filtered = todos.filter(todo => todo.title.match(filter));
if (filtered.length > 0) {
return (
<div>
<Flex>
<Box width={[1, 1 / 2, 1 / 4]} ml={200}>
<ul>
{" "}
{filtered.map((todo, index) => {
return (
<TodoItem
key={index}
todo={todo}
removeTodo={() => removeTodo(index)}
/>
);
})}{" "}
</ul>{" "}
</Box>{" "}
<Box ml={0} pl={0}>
<SearchInputField placeholder="search" onChange={searchTodos} />{" "}
</Box>{" "}
</Flex>
</div>
);
} else {
return filter ? (
<Flex>
<Box ml={550}>
<Text> No matches found </Text>{" "}
<SearchInputField placeholder="search" onChange={searchTodos} />{" "}
</Box>
</Flex>
) : (
<Flex>
<Box ml={550}>
<Text> No Todos to complete </Text>{" "}
</Box>
</Flex>
);
}
};

export default TodoList;
80 changes: 79 additions & 1 deletion src/components/ToDoContainer/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,87 @@
import React, { Component } from "react";

import NewTodoForm from "./NewTodoForm";
import TodoList from "./TodoList";
import { Flex, Box } from "grid-styled";
import styled from "styled-components";

class ToDoContainer extends Component {
constructor() {
super();
this.state = {
newTodo: "",
todos: [],
filter: ""
};
}

// Create new todo
newTodoChanged = event => {
this.setState({
newTodo: event.target.value
});
};

// Form submission event handler
formSubmitted = event => {
let id = this.state.todos.length;
this.setState({
newTodo: "",
todos: [
...this.state.todos,
{
id: id,
title: this.state.newTodo
}
]
});
};

// Remove clicked todolist
removeTodo = index => {
let arr = this.state.todos.filter(todo => todo.id !== index);
let todos = arr.map(todo => {
todo.id = todo.id - 1;
return todo;
});
this.setState({
todos
});
};

// Search todolist by substring
searchTodos = event => {
console.log(event.target.value);
this.setState({
filter: event.target.value
});
};

render() {
const Header = styled.h1`
margin: 1em;
padding: 0.25em 1em;
`;

return (
<div>Welcome to the onboarding project. Add your todo list here!</div>
<div className="app">
<Flex justifyContent="Center">
<Box>
<Header>Todo List</Header>
</Box>
</Flex>
<NewTodoForm
newTodo={this.state.newTodo}
formSubmitted={this.formSubmitted}
newTodoChanged={this.newTodoChanged}
/>
<TodoList
todos={this.state.todos}
filter={this.state.filter}
removeTodo={this.removeTodo}
searchTodos={this.searchTodos}
/>{" "}
</div>
);
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/components/ToDoContainer/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import styled from "styled-components";

export const SubmitButton = styled.button`
background: white;
color: black;
font-size: 1em;
margin: ;
padding: 0.25em 1em;
border: 2px solid blue;
border-radius: 10px;
&:hover {
background: blue;
color: white;
}
`;

export const AddInputField = styled.input`
background: white;
color: black;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid black;
border-radius: 10px;
width: 180px;
&:hover {
border: 2px solid blue;
}
`;

export const SearchInputField = styled.input`
background: white;
color: black;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid black;
width: 280px;
border-radius: 10px;
&:hover {
border: 2px solid blue;
}
`;

export const Text = styled.p`
margin: 1em;
padding: 0.25em 1em;
`;

export const DeleteButton = styled.button`
background: white;
color: palevioletred;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 10px;
&:hover {
background: palevioletred;
color: white;
}
`;