From 424f92c831bbc249f7281d3685a3c0b1193a0502 Mon Sep 17 00:00:00 2001 From: DJ1 Date: Tue, 13 Jun 2023 16:20:12 -0400 Subject: [PATCH 1/4] App.js complete --- frontend/components/App.js | 66 +++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/frontend/components/App.js b/frontend/components/App.js index 815684369..d27dc03ff 100644 --- a/frontend/components/App.js +++ b/frontend/components/App.js @@ -1,9 +1,73 @@ +/* eslint-disable no-unused-vars */ import React from 'react' +import TodoList from "./TodoList" +import axios from "axios" const URL = 'http://localhost:9000/api/todos' export default class App extends React.Component { + state = { + todos: [], + error: "", + todonameinput: "", + } + fetchalltodos = () => { + axios.get(URL) + .then(res => { + this.setState({...this.state, todos: res.data.data}) + }) + .catch(err => {this.setState({...this.state, error: err.response.data.message}) + }) + }; + componentDidMount(){ + this.fetchalltodos() + } + oninputchange = evt => { + const {value} = evt.target + this.setState({...this.state, todoname: value}) + } + postnewtodo = () => { + axios.post(URL, {name: this.state.todonameinput}) + .then(res => { + this.fetchalltodos(); + this.setState({...this.state, todonameinput: "" }) + }) + .catch(err => {this.setState({...this.state, error: err.response.data.message}) + }) + } + onsubmit = (e) => { + e.preventDefault(); + this.postnewtodo() + } + clearcompleted = (e) => { + + } + togglecompleted = id => { + axios.patch(`${URL}/${id}`) + .then(res => { + this.setState({...this.state, todos: [this.state.todos.map(td => { + if (td.id !== id) return td + else { + return res.dtat.data + } + })]}) + }) + .catch(err => {this.setState({...this.state, error: err.response.data.message})}) + } + onclickhandler = id => e => { + this.togglecompleted(id) + } render() { - return null + return ( + <> +

error: {this.state.error}

+ +
+ + + +
+ + ) } } From 342302ab2b39947d383a86c6ef0f2dc3dfc50895 Mon Sep 17 00:00:00 2001 From: DJ1 Date: Tue, 13 Jun 2023 18:59:14 -0400 Subject: [PATCH 2/4] TodoList.js complete --- frontend/components/TodoList.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/components/TodoList.js b/frontend/components/TodoList.js index ce08a27ba..1d8f81122 100644 --- a/frontend/components/TodoList.js +++ b/frontend/components/TodoList.js @@ -2,6 +2,14 @@ import React from 'react' export default class TodoList extends React.Component { render() { - return null + return ( +
+

TO DO

+ { + this.props.todos.map((td) => { return (
{td.name} {td.completed + ? " completed" : ""}
) }) + } +
+ ) } } From 6d2ff499d43589c3307be970db435491e1d3334c Mon Sep 17 00:00:00 2001 From: DJ1 Date: Tue, 13 Jun 2023 19:12:47 -0400 Subject: [PATCH 3/4] Todo.js completed --- frontend/components/Todo.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/components/Todo.js b/frontend/components/Todo.js index aac687f6d..d14618292 100644 --- a/frontend/components/Todo.js +++ b/frontend/components/Todo.js @@ -1,7 +1,16 @@ import React from 'react' export default class Todo extends React.Component { + toggle = (evt) => { + evt.preventDefault(); + this.props.toggleCompleted(this.props.todo.id); + }; render() { - return null + return ( +
  • + {this.props.todo.name}{" "} + {this.props.todo.completed ? : } +
  • + ); } } From bbfd469f1bf15f61fe481bc5468687a412d8b81a Mon Sep 17 00:00:00 2001 From: DJ1 Date: Tue, 13 Jun 2023 19:30:03 -0400 Subject: [PATCH 4/4] Form.js completed --- frontend/components/Form.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/frontend/components/Form.js b/frontend/components/Form.js index 3932207be..029103daf 100644 --- a/frontend/components/Form.js +++ b/frontend/components/Form.js @@ -1,7 +1,38 @@ +/* eslint-disable no-undef */ +/* eslint-disable no-unused-vars */ import React from 'react' - +import axios from "axios" export default class Form extends React.Component { + state = { + newTask: "", + }; + completedTask = (evt) => { + evt.preventDefault(); + this.props.handleCompleted(); + }; + handleChange = (evt) => { + evt.preventDefault(); + this.setState({ ...this.state, newTask: evt.target.value }); + }; + handlePost = (evt) => { + evt.preventDefault(); + this.props.ToDo(this.state.newTask); + this.setState({ ...this.state, newTask: "" }); + }; render() { - return null + return ( +
    +
    + + +
    + +
    + ); } }