diff --git a/frontend/components/App.js b/frontend/components/App.js index 38b7a2f5..7fb6f5a1 100644 --- a/frontend/components/App.js +++ b/frontend/components/App.js @@ -1,11 +1,53 @@ import React from 'react' +import Form from './Form' +import TodoList from './TodoList'; export default class App extends React.Component { + constructor() { + super(); + this.state = { + data: [{ + name: "Walk Jasia", + id: Date.now(), + completed: false + }], + } + } + + handleSubmit = (e,item) => { + e.preventDefault(); + if(item){ + const newItem = { + name: item, + id: Date.now(), + completed: false + } + this.setState({data: [...this.state.data, newItem]}) + } + } + + toggleCompleted = itemId => { + this.setState({...this.state, data: this.state.data.map(task => { + if(task.id === itemId) { + return {...task,completed: !task.completed} + } + return task + })}) + } + + clearCompleted = () => { + this.setState({data: this.state.data.filter(task => { + if(!task.completed) return task; + })}) + } + + render() { return (
- Todo App + +
) } -} +} \ No newline at end of file diff --git a/frontend/components/Form.js b/frontend/components/Form.js index 30fbc48d..059291c5 100644 --- a/frontend/components/Form.js +++ b/frontend/components/Form.js @@ -1,11 +1,30 @@ import React from 'react' + export default class Form extends React.Component { + constructor () { + super(); + this.state = { + form: '' + } + } + submit = (e,item) => { + this.props.submit(e,this.state.form) + this.setState({form: ''}) + } + + change = (e) => { + e.preventDefault() + this.setState({...this.state.form, form: e.target.value}) + } render() { return (
- Form + + + +
) } -} +} \ No newline at end of file diff --git a/frontend/components/Todo.js b/frontend/components/Todo.js index ca86f981..33834e0b 100644 --- a/frontend/components/Todo.js +++ b/frontend/components/Todo.js @@ -1,11 +1,14 @@ import React from 'react' export default class Todo extends React.Component { + render() { return ( -
- Todo +
this.props.toggleCompleted(this.props.task.id)}> +

{this.props.task.name}

+
) } -} +} \ No newline at end of file diff --git a/frontend/components/TodoList.js b/frontend/components/TodoList.js index 95410373..98ea5d0c 100644 --- a/frontend/components/TodoList.js +++ b/frontend/components/TodoList.js @@ -1,11 +1,19 @@ import React from 'react' +import Todo from './Todo' export default class TodoList extends React.Component { + + + + render() { return ( -
- TodoList +
+ {this.props.data.map(task => ( + + ))} +
) } -} +} \ No newline at end of file diff --git a/frontend/index.js b/frontend/index.js index 4e1f0aa5..ab43b1ad 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -6,7 +6,7 @@ import './styles/styles.css' render( -

Todo App

+

What to get Done! Todo App

, document.getElementById('root') diff --git a/frontend/styles/styles.css b/frontend/styles/styles.css index fda8a420..50c863c6 100644 --- a/frontend/styles/styles.css +++ b/frontend/styles/styles.css @@ -69,6 +69,7 @@ nav a.active { } #todos { + color: black; margin: 0 0 1rem 0; } @@ -83,3 +84,13 @@ ul, form { .todo:hover { cursor: pointer; } + +.itemcompleted { +text-decoration: line-through; +} +.Todo-list { + background-image: url(https://images.unsplash.com/photo-1591195852468-03a01d1375d6?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OTB8fHN0aWNreSUyMG5vdGVzfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=400&q=60); + border: dashed black .05rem; + background-repeat: no-repeat; + +} \ No newline at end of file