Advertisement
karamarimo

Untitled

Oct 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fetchStarredUser(onchange) {
  2.   const self1 = this
  3.   const myUserId = self1.state.userId
  4.   var onValueChange1 = firebase.database().ref('/users/' + myUserId + '/starred_users').on('value', function(snapshot) {
  5.     const starred_users = [];
  6.     snapshot.forEach(function(childSnapshot) {
  7.       starred_users.push(childSnapshot.val())
  8.       console.log(childSnapshot.val())
  9.     })
  10.     self1.setState({
  11.       starred_users: starred_users
  12.     }, function() {
  13.       if (onchange) onchange();
  14.     });
  15.   });
  16.   this.setState({
  17.     off_starred_user: onValueChange1
  18.   })
  19. }
  20.  
  21. fetchStarredUserPosts() {
  22.   const self2 = this
  23.   const posts = [];
  24.   const stateStarredUsers = this.state.starred_users
  25.   console.log("Hello")
  26.   for (var i = 0; i < stateStarredUsers.length; i++) {
  27.     const starredUser = stateStarredUsers[i]
  28.     console.log(starredUser)
  29.     firebase.database().ref('/users/' + starredUser + '/user_posts/').limitToFirst(1).once('value', function(snapshot) {
  30.       console.log(snapshot.val())
  31.       snapshot.forEach(function(childSnapshot) {
  32.         posts.push(childSnapshot.val())
  33.         self2.setState({
  34.           posts: posts
  35.         });
  36.       })
  37.     });
  38.   }
  39. }
  40.  
  41. fetchStarAll() {
  42.   const self = this
  43.   this.fetchStarredUser(function() {
  44.     self.fetchStarredUserPosts()
  45.   })
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement