Пример #1
0
// TODO: fix src url for each prof pic
//componentWillReceiveProps(nextProps){
componentDidMount(){
  console.log("nextProps")
//  console.log(nextProps)
//const user = firebaseAuth().currentUser.uid
var thisUser = this.props.match.creator
console.log(thisUser)
    // Create a reference to the file we want to download
  //var starsRef = firebaseStorageRef.child('profilePics/Classic_Singleton.png');
var starsRef = firebaseStorageRef.child(`profilePics/${thisUser}`)

  console.log("afterRef")
  // Get the download URL
  starsRef.getDownloadURL().then(function(url) {

    // Insert url into an <img> tag to "download"
  //  var img = document.getElementById('myimg');
  var img =  document.getElementsByClassName(`img-circle avatar ${thisUser}`)

  for (var i = 0; i < img.length; i++) {
    img[i].src = url
}

    //img[i].src = url;
    console.log("url")
    console.log(url)
    //this.setState({url})
    console.log("Done image")
  }).catch(function(error) {

    // A full list of error codes is available at
    // https://firebase.google.com/docs/storage/web/handle-errors
    switch (error.code) {
      case 'storage/object_not_found':
        // File doesn't exist
        break;

      case 'storage/unauthorized':
        // User doesn't have permission to access the object
        break;

      case 'storage/canceled':
        // User canceled the upload
        break;

      case 'storage/unknown':
        // Unknown error occurred, inspect the server response
        break;
    }
  });
}
Пример #2
0
  componentWillReceiveProps(nextProps){
  console.log("Recieved Props")
  //  var that = this
  console.log('nextProps')
  console.log(nextProps)

  //var that = this
  var user =  firebaseAuth().currentUser.uid



  ref.child(`users/${nextProps.userID}/personal-info`).on('value', (snapshot)=> {

  const profInfo = snapshot.val()
  if (profInfo !== null) {
  console.log('profInfo')
   console.log(profInfo)
   console.log(profInfo.FirstName)
   console.log(profInfo.JoinTime)
   //var joinTime = profInfo.joinTime
   //var clippedJoin = joinTime.slice(4, 14)
   //console.log(clippedJoin)
   //profileInfo.push(persInfo)
   this.setState({
     profInfo,
     FirstName: profInfo.FirstName,
     LastName: profInfo.LastName,
     aboutMe: profInfo.aboutMe,
     favSports: profInfo.favSports,
     userID: nextProps.userID,
     location: profInfo.location
   })
   }
  })



    // Create a reference to the file we want to download
  //var starsRef = firebaseStorageRef.child('profilePics/Classic_Singleton.png');
  var starsRef = firebaseStorageRef.child(`profilePics/${nextProps.userID}`)
  if (starsRef == null) {
    starsRef = firebaseStorageRef.child(`defaultPics/default.jpeg`)
  }

  // Get the download URL
  starsRef.getDownloadURL().then(function(url) {
    // Insert url into an <img> tag to "download"
    var img = document.getElementById('myimg');
  //  var imgBar = document.getElementById('imgBar');
    //imgBar.src = url
    img.src = url;
  }).catch(function(error) {

    // A full list of error codes is available at
    // https://firebase.google.com/docs/storage/web/handle-errors
    switch (error.code) {
      case 'storage/object_not_found':
        // File doesn't exist
        break;

      case 'storage/unauthorized':
        // User doesn't have permission to access the object
        break;

      case 'storage/canceled':
        // User canceled the upload
        break;

      case 'storage/unknown':
        // Unknown error occurred, inspect the server response
        break;
    }
  });

  // //ref.child(`users/${user.uid}/personal-info`).on('value', (snapshot)=> {
  // ref.child(`users/${nextProps.userID}/personal-info`).on('value', (snapshot)=> {
  //
  // const profInfo = snapshot.val()
  // console.log('profInfo')
  //  console.log(profInfo)
  //  console.log(profInfo.FirstName)
  //
  //  //    profInfo.aboutMe
  //  //    profInfo.sports
  //  //    profInfo.location
  //
  //  this.setState({
  //    profInfo,
  //    FirstName: profInfo.FirstName,
  //    LastName: profInfo.LastName
  //  })
  // })

  //ref.child(`users/${user.uid}/personal-info`).on('value', (snapshot)=> {

  ref.child(`users/${nextProps.userID}/account-info/rep`).on('value', (snapshot)=> {

  const rep = snapshot.val()
   console.log('rep')
   console.log(rep)
   console.log(rep)

    var rep_sum = 0
    var keys = Object.keys(rep)

    for (var i =0; i < keys.length; i++) {
      var k = keys[i];
      var this_rep = rep[k];

      console.log(this_rep.this_rep)
      rep_sum = rep_sum + this_rep.this_rep

    }
      console.log((rep_sum/keys.length))
      this.setState({ rep: Math.round(100*(rep_sum/(5*keys.length))) })
  })


  }
Пример #3
0
  firebaseAuth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.

var otherUser = "******"

   ref.child(`users/${user.uid}/personal-info`).on('value', (snapshot)=> {
//    ref.child(`users/${otherUser}/personal-info`).on('value', (snapshot)=> {

    const persInfo = snapshot.val()
     console.log(persInfo)
     that.setState({
    fName: persInfo.FirstName,
    lName: persInfo.LastName,
    email: persInfo.email,
    gender: persInfo.Gender,
    aboutUser: persInfo.aboutMe,
    favSports: persInfo.favSports,
    location: persInfo.location
     })
    })

    // Create a reference to the file we want to download
  var starsRef = firebaseStorageRef.child(`profilePics/${user.uid}`);

  // Get the download URL
  starsRef.getDownloadURL().then(function(url) {
    // Insert url into an <img> tag to "download"
  //  var img = document.getElementById('myimg');
    var imgBar = document.getElementById('imgBar')
    var img = document.getElementById('myimg')
    imgBar.src = url
    img.src = url
  }).catch(function(error) {

    // A full list of error codes is available at
    // https://firebase.google.com/docs/storage/web/handle-errors
    switch (error.code) {
      case 'storage/object_not_found':
        // File doesn't exist
        break;

      case 'storage/unauthorized':
        // User doesn't have permission to access the object
        break;

      case 'storage/canceled':
        // User canceled the upload
        break;

      case 'storage/unknown':
        // Unknown error occurred, inspect the server response
        break;
    }
  });

//set consts to state, pass as props to rendering comps
} else {
// No user is signed in.
}
})