<commit_before>import React from 'react';
import Avatar from 'material-ui/Avatar';
import {List, ListItem} from 'material-ui/List';
import Subheader from 'material-ui/Subheader';
import Divider from 'material-ui/Divider';
import CommunicationChatBubble from 'material-ui/svg-icons/communication/chat-bubble';
import { getConvoIds, getUserProfile } from 'APP/fire/refs'
import store, { constantlyUpdateUser } from '../store'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'

const img = 'https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAfRAAAAJGY5YjFhN2Q2LTUyNjMtNDQ4OS04Mzk5LTcyMGQyM2E0MTgwOA.jpg'

class Inbox extends React.Component {
  constructor(props){
    super(props)
    this.state = {
      convoIds: {},
      convoUsers: []
    }
  }


  componentWillReceiveProps(nextProps){
    if (this.props.user.uid !== nextProps.user.uid){
      getConvoIds(nextProps.user.uid)
        .then(convoIds => {
          this.setState({convoIds})
          //for each convoid, get the user object
          let convoIdKeys = Object.keys(convoIds)
          let convoUsers = []
          convoIdKeys.forEach((convoIdKey)=> {
            getUserProfile(convoIdKey)
            .then(userProfile => {
              convoUsers.push(userProfile)
            })
          })
          this.setState({convoUsers})
        })
    }
  }

  componentDidMount(){
    store.dispatch(constantlyUpdateUser())
    const uid = this.props.user.uid 
    getConvoIds(uid)
      .then(convoIds => {
        this.setState({convoIds})
        let convoIdKeys = Object.keys(convoIds)
        let convoUsers = []
        convoIdKeys.forEach((convoIdKey)=> {
          getUserProfile(convoIdKey)
          .then(userProfile => {
            convoUsers.push(userProfile)
          })
        })
        this.setState({convoUsers})
      })
  }


  render(){
    const convoArray = Object.entries(this.state.convoIds)
    console.log("convoArray", convoArray)
    console.log("THISSTATECONVOUSERS", this.state.convoUsers)
    
    return (
    <div>
      <List>
      <Subheader>Recent chats</Subheader>
        {convoArray.length && convoArray.map(convo => {
          if (convo[0]!== "undefined") {
            return (
            <ListItem key = {convo[1]}
            primaryText={convo[0]}
            leftAvatar={<Avatar src={img} />}
            rightIcon={<CommunicationChatBubble />}
            />
            ) 
          }
        })}
      </List>
    </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    user: state.user
  }
}

export default withRouter(connect(mapStateToProps)(Inbox))


// export default() => (
//   <div>
//     {console.log("GET CONVO IDS!", getConvoIds())}
//     <List>
//       <Subheader>Recent chats</Subheader>
//       <ListItem<commit_msg>why is this object not an object<commit_after>import React from 'react';
import Avatar from 'material-ui/Avatar';
import {List, ListItem} from 'material-ui/List';
import Subheader from 'material-ui/Subheader';
import Divider from 'material-ui/Divider';
import CommunicationChatBubble from 'material-ui/svg-icons/communication/chat-bubble';
import { getConvoIds, getUserProfile } from 'APP/fire/refs'
import store, { constantlyUpdateUser } from '../store'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'

const img = 'https://media.licdn.com/mpr/mpr/shrinknp_200_200/AAEAAQAAAAAAAAfRAAAAJGY5YjFhN2Q2LTUyNjMtNDQ4OS04Mzk5LTcyMGQyM2E0MTgwOA.jpg'

class Inbox extends React.Component {
  constructor(props){
    super(props)
    this.state = {
      convoIds: {},
      convoUsers: {}
    }
  }


  componentWillReceiveProps(nextProps){
    if (this.props.user.uid !== nextProps.user.uid){
      getConvoIds(nextProps.user.uid)
        .then(convoIds => {
          this.setState({convoIds})
          //for each convoid, get the user object
          let convoIdKeys = Object.keys(convoIds)
          let convoUsers = {}
          convoIdKeys.forEach((convoIdKey)=> {
            getUserProfile(convoIdKey)
            .then(userProfile => {
              convoUsers[convoIdKey] = userProfile
              // convoUsers.push(userProfile)
            })
          })
          this.setState({convoUsers})
        })
    }
  }

  componentDidMount(){
    store.dispatch(constantlyUpdateUser())
    const uid = this.props.user.uid 
    getConvoIds(uid)
      .then(convoIds => {
        this.setState({convoIds})
        let convoIdKeys = Object.keys(convoIds)
        let convoUsers = {}
        convoIdKeys.forEach((convoIdKey)=> {
          getUserProfile(convoIdKey)
          .then(userProfile => {
            convoUsers[convoIdKey] = userProfile
            // convoUsers.push(userProfile)
          })
        })
        this.setState({convoUsers})
      })
  }


  render(){
    const convoArray = Object.entries(this.state.convoIds)
    const { convoUsers } = this.state;

    console.log("convoArray", convoArray)
    console.log("CONVO USERS", convoUsers)
    console.log("convoUsers an an array for funsies", Object.entries(convoUsers))
    console.log("convoUsers as an array of keys for funsies", Object.keys(convoUsers))
    console.log("Convo Users object for juan", convoUsers['spotify:user:jpvelez'])
    return (
    <div>
      <List>
      {/* <Subheader>Recent chats</Subheader> */}
        {convoArray.length && convoArray.map(convo => {
          if (convo[0]!== "undefined") {
            return (
            <ListItem key = {convo[1]}
            /* primaryText = {convo[0]} */
            /* primaryText={convoUsers[convo[0]].displayName} */
            leftAvatar={<Avatar src={img} />}
            rightIcon={<CommunicationChatBubble />}
            />
            ) 
          }
        })}
      </List>
    </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    user: state.user
  }
}

export default withRouter(connect(mapStateToProps)(Inbox))


// export default() => (
//   <div>
//     {console.log("GET CONVO IDS!", getConvoIds())}
//     <List>
//       <Subheader>Recent chats</Subheader>
//       <ListItem
{'fraction_non_alphanumeric': 0.1322083879423329, 'fraction_numerical': 0.006061598951507209, 'mean_word_length': 2.453054298642534, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 47, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1539215', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1974, 'n_words': 327}