Advertisement
jeffjeffjeff

jeff-todo.js

May 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. // import webdevlogo from './components/webdevlogo.png';
  3. import './todo.css';
  4.  
  5. // import Todo from './components/todo.js';
  6.  
  7. class Todo extends Component {
  8.   // constructor(props){
  9.   //   super(props);
  10.  
  11.   //   this.state = {
  12.   //     todos: [],
  13.   //     description: "",
  14.   //     class_name: "",
  15.   //     priority: "",
  16.   //     completed: false
  17.   //   };
  18.   //   // this.handleSubmit = this.handleSubmit.bind(this);
  19.   // }
  20.  
  21.   // handleSubmit(event){
  22.   //   event.preventDefault();
  23.   //   const form = document.getElementById("newTask").value;
  24.  
  25.   //   if (this.state.todos.find(todos => todos.description == form)){
  26.   //     this.setState({description : form });
  27.   //   }else {
  28.   //     fetch("/api/addpost/" + form)
  29.   //     .then(response => response.json())
  30.   //     .then(stats => {
  31.   //       console.log("all todos fetched: ");
  32.   //       console.log(todos);
  33.   //       this.setState({ todos: todos });
  34.   //     });
  35.   //     this.setState({ description : form });
  36.   //   }
  37.   // }
  38.  
  39.   componentDidMount(){
  40.     fetch("api/todos")
  41.     .then(response =>{
  42.       if(response.status !== 200) {
  43.         console.log("there was an issue - status code: " +response.status);
  44.         return;
  45.       }
  46.       response.json().then(todos => {
  47.         console.log("all tasks fetched: ");
  48.         console.log(todos);
  49.         this.setState({ todos : todos });
  50.       });
  51.     })
  52.     .catch(err => {
  53.       console.log("tasks fetch error :-S", err);
  54.     });
  55.   }
  56.  
  57.   render(){
  58.     return(
  59.       <div className="App">
  60.         <Todo />
  61.       </div>
  62.     );
  63.   }
  64. }
  65.  
  66.  
  67. export default Todo;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement