import _ from 'underscore' import React from 'react' import {DOMUtils, RegExpUtils, Utils} from 'nylas-exports' import {RetinaImg} from 'nylas-component-kit' import ParticipantProfileStore from './participant-profile-store' export default class SidebarParticipantProfile extends React.Component { static displayName = "SidebarParticipantProfile"; static propTypes = { contact: React.PropTypes.object, contactThreads: React.PropTypes.array, } static containerStyles = { order: 0, } constructor(props) { super(props); /* We expect ParticipantProfileStore.dataForContact to return the * following schema: * { * profilePhotoUrl: string * bio: string * location: string * currentTitle: string * currentEmployer: string * socialProfiles: hash keyed by type: ('twitter', 'facebook' etc) * url: string * handle: string * } */ this.state = ParticipantProfileStore.dataForContact(props.contact) } componentDidMount() { this.usub = ParticipantProfileStore.listen(() => { this.setState(ParticipantProfileStore.dataForContact(this.props.contact)) }) } componentWillUnmount() { this.usub() } _renderProfilePhoto() { if (this.state.profilePhotoUrl) { return (
Profile
) } return this._renderDefaultProfileImage() } _renderDefaultProfileImage() { const hue = Utils.hueForString(this.props.contact.email); const bgColor = `hsl(${hue}, 50%, 45%)` const abv = this.props.contact.nameAbbreviation() return (
{abv}
) } _renderCorePersonalInfo() { const fullName = this.props.contact.fullName(); let renderName = false; if (fullName !== this.props.contact.email) { renderName =
{this.props.contact.fullName()}
} return (
{renderName}
{this.props.contact.email}
{this._renderSocialProfiles()}
) } _renderSocialProfiles() { if (!this.state.socialProfiles) { return false } const profiles = _.map(this.state.socialProfiles, (profile, type) => { return ( ) }); return
{profiles}
} _renderAdditionalInfo() { return (
{this._renderCurrentJob()} {this._renderBio()} {this._renderLocation()}
) } _renderCurrentJob() { if (!this.state.employer) { return false; } let title = false; if (this.state.title) { title = {this.state.title},  } return (

{title}{this.state.employer}

) } _renderBio() { if (!this.state.bio) { return false; } const bioNodes = []; const hashtagOrMentionRegex = RegExpUtils.hashtagOrMentionRegex(); let bioRemainder = this.state.bio; let match = null; let count = 0; /* I thought we were friends. */ /* eslint no-cond-assign: 0 */ while (match = hashtagOrMentionRegex.exec(bioRemainder)) { // the first char of the match is whitespace, match[1] is # or @, match[2] is the tag itself. bioNodes.push(bioRemainder.substr(0, match.index + 1)); if (match[1] === '#') { bioNodes.push({`#${match[2]}`}); } if (match[1] === '@') { bioNodes.push({`@${match[2]}`}); } bioRemainder = bioRemainder.substr(match.index + match[0].length); count += 1; } bioNodes.push(bioRemainder); return (

{bioNodes}

) } _renderLocation() { if (!this.state.location) { return false; } return (

{this.state.location}

) } _select(event) { const el = event.target; const sel = document.getSelection() if (el.contains(sel.anchorNode) && !sel.isCollapsed) { return } const anchor = DOMUtils.findFirstTextNode(el) const focus = DOMUtils.findLastTextNode(el) if (anchor && focus && focus.data) { sel.setBaseAndExtent(anchor, 0, focus, focus.data.length) } } render() { return (
{this._renderProfilePhoto()} {this._renderCorePersonalInfo()} {this._renderAdditionalInfo()}
) } }