Skip to content

Latest commit

 

History

History
77 lines (73 loc) · 2.36 KB

File metadata and controls

77 lines (73 loc) · 2.36 KB

React Native Android Todo App

image image

Run project

react-native run-android
react-native-start

For virtual device after app installation click Reload(R,R) or double press "R" key on your keyboard.
For real device shake the phone and click Reload

Send notes to rest api

addNote() {
    if(this.state.noteText){
      var d = new Date();
    fetch('https://androidtodoapp.herokuapp.com/saveNote' , {
        method : 'POST',
        headers: {
          'Accept':       'application/json',
          'Content-Type': 'application/json',
        },
          body : JSON.stringify({
            date : d.getFullYear() + "/" + (d.getMonth() +1) + "/" +  d.getDate(),
            note : this.state.noteText
          })
      })
      .then((response) => {
        if(response.status == 200)
        {
          this.state.noteArray.push({'date': d.getFullYear() + "/" + (d.getMonth() +1) + "/" +  d.getDate() , 'note': this.state.noteText});
          this.setState({noteArray : this.state.noteArray});
          this.setState({noteText : ''});
        }
      })
      .catch((error) => {
      });
    }
  }

Get notes from rest api

getNotes(){
    fetch('http://androidtodoapp.herokuapp.com/getNotes' , {
      method : 'POST',
      headers : {
        'Accept':       'application/json',
        'Content-Type': 'application/json',
      },
    })
    .then((response) => response.json())
    .then((responseData) => {
      for(var i = 0; i < responseData.length; i++)
      {
        this.state.noteArray.push({'date' : responseData[i].date , 'note' : responseData[i].note});
        this.setState({noteArray : this.state.noteArray});
        this.setState({noteText : ''});
      }
    })
    .catch((error) => {
      Alert.alert(error.toString());
    })
  }

Fill notes to view

for(var i = 0; i < responseData.length; i++)
  {
    this.state.noteArray.push({'date' : responseData[i].date , 'note' : responseData[i].note});
    this.setState({noteArray : this.state.noteArray});
    this.setState({noteText : ''});
  }