diff --git a/README.md b/README.md index e3e663b6..8e854ad9 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ In this project you will build an application that allows for todos to be added, - Once a todo is submitted, the Todo List should re-render and show the added todo. ## Submission Format -- [ ] Only work on main. -- [ ] Make sure to push your code at regular intervals. -- [ ] Copy your github repo url and paste it into Canvas to submit your project \ No newline at end of file +- [ ] If this is your first time connecting a submission, authorize your github account within the codegrade assignment. +- [ ] Connect your fork to Codegrade using the "Connect Git" button. +- [ ] Find your newly created fork from the list and push your work to main. +- [ ] Check this video for details: www.youtube.com/watch?v=fC2BO7dI6IQ diff --git a/src/App.js b/src/App.js index 556b5fbc..3feffd5f 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,86 @@ import React from 'react'; +import ReactDOM from 'react-dom'; + +import TodoForm from './components/TodoForm'; +import TodoList from './components/TodoList'; + +const checkList = [ + { + 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 = { + checkList: checkList + } + } + + handleClear = () => { + this.setState({ + ...this.state, + checkList: this.state.checkList.filter(item => !item.completed) + }); + } + + handleAddItems = (item) => { + const newItem = { + name: item, + id: Date.now, + completed: false + }; + + this.setState({ + ...this.state, + checkList: [...this.state.checkList, newItem] + }); + } + + handleToggle = (item) => { + this.setState({ + ...this.state, + checkList: this.state.checkList.map(list => { + if(list.id === item.id){ + return ({ + ...list, + completed: !list.completed + }) + } + return list; + }) + }) + } + render() { return ( -
-

Welcome to your Todo App!

+
+
+

My Todo Checklist

+ +
+ + {/* */}
); } } export default App; +const rootElement = document.getElementById('root'); + ReactDOM.render(, rootElement); \ No newline at end of file diff --git a/src/components/Todo.js b/src/components/Todo.js index e69de29b..283cc3ac 100644 --- a/src/components/Todo.js +++ b/src/components/Todo.js @@ -0,0 +1,15 @@ +import React from 'react' + +const Todo = props => { + const handleClick = () => { + props.handleToggle(props.item); + } + + return ( +
+

{props.item.name}

+
+ ); +}; + +export default Todo; \ No newline at end of file diff --git a/src/components/TodoForm.js b/src/components/TodoForm.js index e69de29b..7a9c06b7 100644 --- a/src/components/TodoForm.js +++ b/src/components/TodoForm.js @@ -0,0 +1,36 @@ +import React from 'react' + +class TodoForm extends React.Component { + // create a constructor with state + constructor(){ + super(); + this.state = { + input: '' + } + } + + // handle any changes with state + handleChanges = e => { + this.setState({ + ...this.state, + input: e.target.value + }); + }; + + // class property to submit form + handleSubmit = (event) => { + event.preventDefault(); + this.props.handleAddItems(this.state.input); + } + + render() { + return ( +
+ + +
+ ) + } +} + +export default TodoForm; \ No newline at end of file diff --git a/src/components/TodoList.js b/src/components/TodoList.js index dfd3d8f1..aa18926a 100644 --- a/src/components/TodoList.js +++ b/src/components/TodoList.js @@ -1,2 +1,15 @@ -// 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 ( +
+ {props.checkList.map(item => ( + + ))} +
+ ) +} + +export default TodoList; \ No newline at end of file