<commit_before>import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import { Person } from 'blockstack-profiles'

import AddressBar          from '../../components/AddressBar'
import { SocialAccountItem, Image } from '../../components/index'
import { IdentityActions } from '../../store/identities'
import { SearchActions } from '../../store/search'

const placeholderImage = "https://s3.amazonaws.com/65m/avatar-placeholder.png"

function mapStateToProps(state) {
  return {
    currentIdentity: state.identities.current,
    localIdentities: state.identities.localIdentities,
    nameLookupUrl: state.settings.api.nameLookupUrl
  }
}

function mapDispatchToProps(dispatch) {
  let actions = Object.assign(IdentityActions, SearchActions)
  return bindActionCreators(actions, dispatch)
}

class ViewProfilePage extends Component {
  static propTypes = {
    fetchCurrentIdentity: PropTypes.func.isRequired,
    updateCurrentIdentity: PropTypes.func.isRequired,
    updateQuery: PropTypes.func.isRequired,
    currentIdentity: PropTypes.object.isRequired,
    localIdentities: PropTypes.object.isRequired,
    nameLookupUrl: PropTypes.string.isRequired
  }

  constructor(props) {
    super(props)

    this.state = {
      currentIdentity: {
        id: null,
        profile: null,
        verifications: [],
        blockNumber: null,
        transactionNumber: null
      },
      isLoading: true
    }
  }

  componentHasNewRouteParams(props) {
    if (props.routeParams.index) {
      const newDomainIndex = props.routeParams.index,
            profile = props.localIdentities[newDomainIndex].profile,
            name = props.localIdentities[newDomainIndex].domainName,
            verifications = []
      this.props.updateCurrentIdentity(name, profile, verifications)
    } else if (props.routeParams.name) {
      this.props.fetchCurrentIdentity(props.routeParams.name, props.nameLookupUrl)
    }
  }

  componentWillMount() {
    this.componentHasNewRouteParams(this.props)
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.routeParams !== this.props.routeParams) {
      this.componentHasNewRouteParams(nextProps)
    }
    this.setState({
      currentIdentity: nextProps.currentIdentity,
      isLoading: false
    })
  }

  render() {
    let identity = this.state.currentIdentity,
        domainName = identity.domainName

    let profile = identity.profile || null,
        verifications = identity.verifications,
        blockNumber = identity.blockNumber,
        transactionIndex = identity.transactionIndex

    let isLocal = false
    if (this.props.routeParams.hasOwnProperty('index')) {
      isLocal = true
    }

    let person = null,
        accounts = [],
        connections = []

    if (profile !== null) {
      if (profile.hasOwnProperty('@type')) {
        person = new Person(profile)
      } else {
        person = Person.fromLegacyFormat(profile)
      }
      accounts = person.profile().account || []
      connections = person.connections() || []
    }

    return (
      <div className="app-wrap-profiles">  
        { person !== null ?   
        <div className="container-fluid site-wrapper">
          <nav className="navbar navbar-toggleable-md navbar-light">
            <a className="navbar-brand" href="/profiles">
              <img src="/images/app-icon-profiles.png" />
            </a>
            <div className="navbar-collapse" id="navbarSupportedContent">
              <ul className="nav navbar-nav m-b-20">
                <li className="navbar-text">
                  Profiles
                </li>
                <li className="navbar-text navbar-text-secondary">
                  Utility
                </li>
              </ul>
              <AddressBar placeholder="Search for people" />
            </div>
          </nav>
          <div className="container-fluid pro-wrap m-t-50">
            <div className="col-sm-9">
              <div className="container">
                <div className="profile-container col-sm-12 center-block">
                  <div className="pro-avatar m-b-20">
                    <Image src={person.avatarUrl() || ''}
                      fallbackSrc="/images/avatar.png" className="img-circle" />
                  </div>
                  <div className="">
                    { (blockNumber && transactionIndex) ?
                    <div className="idcard-body dim">
                      Registered in block <span className="inverse">#{blockNumber}</span>,<br/>
                      transaction <span className="inverse">#{transactionIndex}</span>
                    </div>
                    : null }
                    <h1 className="pro-card-name">{person.name()}</h1>
                    <div className="pro-card-body">
                      {person.description()}
                    </div>
                    { person.address() ?
                    <div className="pro-card-body">
                      {person.address()}
                    </div>
                    : null }
                    { person.birthDate() ?
                    <div className="pro-card-body">
                      {person.birthDate()}
                    </div>
                    : null }
                  </div>
                  { isLocal ?
                  <div>
                    <p>
                      <Link to={this.props.location.pathname + "/edit"}
                        className="btn btn-block btn-primary m-t-1">
                        Edit
                      </Link>
                    </p>
                    <p>
                      <Link to={`/profiles/blockchain/${domainName}`}
                        className="btn btn-block btn-primary m-t-1">
                        View Publicly
                      </Link>
                    </p>
                  </div>
                  :
                  <div>
                    <button className="btn btn-sm btn-secondary m-t-10">
                      Connect<commit_msg>updated buttons on profile card to be secondary<commit_after>import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import { Person } from 'blockstack-profiles'

import AddressBar          from '../../components/AddressBar'
import { SocialAccountItem, Image } from '../../components/index'
import { IdentityActions } from '../../store/identities'
import { SearchActions } from '../../store/search'

const placeholderImage = "https://s3.amazonaws.com/65m/avatar-placeholder.png"

function mapStateToProps(state) {
  return {
    currentIdentity: state.identities.current,
    localIdentities: state.identities.localIdentities,
    nameLookupUrl: state.settings.api.nameLookupUrl
  }
}

function mapDispatchToProps(dispatch) {
  let actions = Object.assign(IdentityActions, SearchActions)
  return bindActionCreators(actions, dispatch)
}

class ViewProfilePage extends Component {
  static propTypes = {
    fetchCurrentIdentity: PropTypes.func.isRequired,
    updateCurrentIdentity: PropTypes.func.isRequired,
    updateQuery: PropTypes.func.isRequired,
    currentIdentity: PropTypes.object.isRequired,
    localIdentities: PropTypes.object.isRequired,
    nameLookupUrl: PropTypes.string.isRequired
  }

  constructor(props) {
    super(props)

    this.state = {
      currentIdentity: {
        id: null,
        profile: null,
        verifications: [],
        blockNumber: null,
        transactionNumber: null
      },
      isLoading: true
    }
  }

  componentHasNewRouteParams(props) {
    if (props.routeParams.index) {
      const newDomainIndex = props.routeParams.index,
            profile = props.localIdentities[newDomainIndex].profile,
            name = props.localIdentities[newDomainIndex].domainName,
            verifications = []
      this.props.updateCurrentIdentity(name, profile, verifications)
    } else if (props.routeParams.name) {
      this.props.fetchCurrentIdentity(props.routeParams.name, props.nameLookupUrl)
    }
  }

  componentWillMount() {
    this.componentHasNewRouteParams(this.props)
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.routeParams !== this.props.routeParams) {
      this.componentHasNewRouteParams(nextProps)
    }
    this.setState({
      currentIdentity: nextProps.currentIdentity,
      isLoading: false
    })
  }

  render() {
    let identity = this.state.currentIdentity,
        domainName = identity.domainName

    let profile = identity.profile || null,
        verifications = identity.verifications,
        blockNumber = identity.blockNumber,
        transactionIndex = identity.transactionIndex

    let isLocal = false
    if (this.props.routeParams.hasOwnProperty('index')) {
      isLocal = true
    }

    let person = null,
        accounts = [],
        connections = []

    if (profile !== null) {
      if (profile.hasOwnProperty('@type')) {
        person = new Person(profile)
      } else {
        person = Person.fromLegacyFormat(profile)
      }
      accounts = person.profile().account || []
      connections = person.connections() || []
    }

    return (
      <div className="app-wrap-profiles">  
        { person !== null ?   
        <div className="container-fluid site-wrapper">
          <nav className="navbar navbar-toggleable-md navbar-light">
            <a className="navbar-brand" href="/profiles">
              <img src="/images/app-icon-profiles.png" />
            </a>
            <div className="navbar-collapse" id="navbarSupportedContent">
              <ul className="nav navbar-nav m-b-20">
                <li className="navbar-text">
                  Profiles
                </li>
                <li className="navbar-text navbar-text-secondary">
                  Utility
                </li>
              </ul>
              <AddressBar placeholder="Search for people" />
            </div>
          </nav>
          <div className="container-fluid pro-wrap m-t-50">
            <div className="col-sm-9">
              <div className="container">
                <div className="profile-container col-sm-12 center-block">
                  <div className="pro-avatar m-b-20">
                    <Image src={person.avatarUrl() || ''}
                      fallbackSrc="/images/avatar.png" className="img-circle" />
                  </div>
                  <div className="">
                    { (blockNumber && transactionIndex) ?
                    <div className="idcard-body dim">
                      Registered in block <span className="inverse">#{blockNumber}</span>,<br/>
                      transaction <span className="inverse">#{transactionIndex}</span>
                    </div>
                    : null }
                    <h1 className="pro-card-name">{person.name()}</h1>
                    <div className="pro-card-body">
                      {person.description()}
                    </div>
                    { person.address() ?
                    <div className="pro-card-body">
                      {person.address()}
                    </div>
                    : null }
                    { person.birthDate() ?
                    <div className="pro-card-body">
                      {person.birthDate()}
                    </div>
                    : null }
                  </div>
                  { isLocal ?
                  <div>
                    <p>
                      <Link to={this.props.location.pathname + "/edit"}
                        className="btn btn-sm btn-secondary m-t-10">
                        Edit
                      </Link>
                    </p>
                    <p>
                      <Link to={`/profiles/blockchain/${domainName}`}
                        className="btn btn-sm btn-secondary m-t-10">
                        View Publicly
                      </Link>
                    </p>
                  </div>
                  :
                  <div>
                    <button className="btn btn-sm btn-secondary m-t-10">
                      Connect
{'fraction_non_alphanumeric': 0.11509495743287491, 'fraction_numerical': 0.003110674525212836, 'mean_word_length': 1.7343330349149508, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 107, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '6121884', 'n_tokens_mistral': 3198, 'n_tokens_neox': 3075, 'n_words': 598}