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
17,427 changes: 17,427 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"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.2.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
52 changes: 52 additions & 0 deletions src/components/ToDoContainer/AddTodo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { Component } from "react";
import { SubmitButton, Container, Input } from "./styles";

class AddTodo extends Component {
constructor() {
super();
this.state = {
currentText: "" // Todo inputted by user
};
}

// Update what the current item is based on user input
handleInput = item => {
const todo = item.target.value;
const currentText = todo;
this.setState({ currentText });
};

// Add an item to the list
addTodo = obj => {
obj.preventDefault();

// Make sure the current item is not empty before adding
if (this.state.currentText !== "") {
const items = [
...this.props.parentState.items,
{
id: this.props.parentState.currentID + 1,
text: this.state.currentText
}
];
this.setState({
currentText: "" // Reset text the next user input
});
this.props.updateParent(items, this.props.parentState.currentID + 1);
}
};

render() {
return (
/* When the user clicks submit, call the addTodo func */
<Container>
<Input value={this.state.currentText} onChange={this.handleInput} />
<SubmitButton type="submit" onClick={this.addTodo}>
Add
</SubmitButton>
</Container>
);
}
}

export default AddTodo;
35 changes: 35 additions & 0 deletions src/components/ToDoContainer/AddTodo/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Flex } from "grid-styled";
import styled from "styled-components";

export const SubmitButton = styled.button`
border: 2px solid blue;
border-radius: 8px;
border-width: 3px;
height: 24px;
:hover {
background-color: blue;
color: white;
}
outline-color: transparent;
outline-style: none;
`;

export const Container = styled(Flex)`
/* justify-content: space-between; */
`;

export const Input = styled.input`
margin-right: 4px;
height: 16px;
border: 2px solid black;
border-radius: 8px;
border-width: 3px;

:focus {
border: 2px solid blue;
border-radius: 8px;
border-width: 3px;
outline-color: transparent;
outline-style: none;
}
`;
12 changes: 12 additions & 0 deletions src/components/ToDoContainer/SearchTodos/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { Input } from "./styles";

const SearchTodos = ({ searchText, handleSearch }) => (
<Input
value={searchText}
placeholder="Search Todos"
onChange={handleSearch}
/>
);

export default SearchTodos;
19 changes: 19 additions & 0 deletions src/components/ToDoContainer/SearchTodos/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// import { Flex } from "grid-styled";
import styled from "styled-components";

export const Input = styled.input`
width: 175px;
height: 24px;
margin-top: 6px;
border-radius: 8px;
border: 2px solid black;
border-width: 3px;

:focus {
border: 2px solid blue;
border-width: 3px;
border-radius: 8px;
outline-color: transparent;
outline-style: none;
}
`;
32 changes: 32 additions & 0 deletions src/components/ToDoContainer/TodoItems/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { Component } from "react";
import { ListItem, DeleteButton, Text } from "./styles";

class TodoItems extends Component {
// Function to create the list
makeList = todo => {
if (todo.text.match(this.props.searchText) != null) {
return (
<ListItem key={todo.id}>
{todo.text} {" "}
{/* When button is clicked, run anonymous function delete */}
<DeleteButton onClick={() => this.props.deleteTodo(todo.id)}>
<Text>Delete </Text>
</DeleteButton>
</ListItem>
);
}
};

render() {
// Message if there are no todos
if (this.props.todos.length === 0) {
return <p>No todos to complete</p>;
}

// Otherwise, create the list of todos
const listed = this.props.todos.map(this.makeList);
return <ul>{listed}</ul>;
}
}

export default TodoItems;
38 changes: 38 additions & 0 deletions src/components/ToDoContainer/TodoItems/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Flex } from "grid-styled";
import styled from "styled-components";

export const Container = styled(Flex)`
background-color: blue;
width: 100%;
margin-top: 10px;
`;

export const DeleteButton = styled.button`
border: 2px solid red;
border-radius: 8px;
border-width: 3px;
display: inline-block;
:hover {
background-color: red;
color: white;
}
outline-color: transparent;
outline-style: none;
`;

export const ListItem = styled.li`
text-align: left;
font: Arial;
font-size: 14px;
width: 200px;
justify-content: space-between;
margin: auto;
margin-bottom: 5px;
/* align-items: flex-end; */
word-wrap: break-word;
`;

export const Text = styled(Flex)`
font-size: 14px;
font: Arial;
`;
63 changes: 62 additions & 1 deletion src/components/ToDoContainer/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,70 @@
import React, { Component } from "react";
import AddTodo from "./AddTodo/index.js";
import TodoItems from "./TodoItems/index.js";
import SearchTodos from "./SearchTodos/index.js";
import { Container, Text, SubContainer } from "./styles";

class ToDoContainer extends Component {
// Set up the state
constructor() {
super();
this.state = {
items: [], // Will store all the todos and display
currentID: 1,
searchText: ""
};
}

// Delete an item from the list
deleteTodo = id => {
// id.preventDefault();

// Filter to create new array that doesn't include deleted item
const newList = this.state.items.filter(obj => {
return obj.id !== id;
});

this.setState({
items: newList
});
};

// Update parent state
updateParent = (items, currentID) => {
this.setState({ items: items, currentID: currentID });
};

// Handle inputs from search
handleSearch = text => {
const item = text.target.value;
const searchText = item;
this.setState({ searchText });
};

render() {
return (
<div>Welcome to the onboarding project. Add your todo list here!</div>
<Container id="root">
<SubContainer>
<Text>Current Todos:</Text>
<TodoItems
todos={this.state.items}
deleteTodo={this.deleteTodo}
searchText={this.state.searchText}
/>
</SubContainer>
<SubContainer>
<AddTodo
addTodo={this.addTodo}
handleInput={this.handleInput}
updateParent={this.updateParent}
parentState={this.state}
/>
<SearchTodos
currentText={this.state.searchText}
handleSearch={this.handleSearch}
/>
</SubContainer>
</Container>
);
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/components/ToDoContainer/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Flex } from "grid-styled";
import styled from "styled-components";

export const Container = styled(Flex)`
justify-content: space-between;
flex-direction: row;
width: 50%;
margin: auto;
margin-top: 15px;
`;

export const SubContainer = styled(Container)`
flex-direction: column;
width: 177.9px;
`;

export const Text = styled(Flex)`
font: Arial;
font-size: 24px;
font-weight: bold;
border-bottom: 3px solid black;
`;