Skip to content

spolat/react-native-todo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 : ''});
  }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors