/* global $ */ import React, { PropTypes, Component } from 'react' import { Link } from 'react-router' class Info extends Component { constructor(props) { super(props) this.state = { showInMaps: false, showMoreMaps: false, hoveringMapCount: false, hoveringSynapseCount: false } } toggleShowMoreMaps = e => { e.stopPropagation() e.preventDefault() this.setState({ showMoreMaps: !this.state.showMoreMaps }) } updateState = (key, value) => () => { this.setState({ [key]: value }) } inMaps = (topic) => { const inmapsArray = topic.get('inmaps') || [] const inmapsLinks = topic.get('inmapsLinks') || [] let firstFiveLinks = [] let extraLinks = [] for (let i = 0; i < inmapsArray.length; i++) { if (i < 5) { firstFiveLinks.push({ mapName: inmapsArray[i], mapId: inmapsLinks[i] }) } else { extraLinks.push({ mapName: inmapsArray[i], mapId: inmapsLinks[i] }) } } let output = [] firstFiveLinks.forEach(obj => { output.push(
  • {obj.mapName}
  • ) }) if (extraLinks.length > 0) { if (this.state.showMoreMaps) { extraLinks.forEach(obj => { output.push(
  • {obj.mapName}
  • ) }) } const text = this.state.showMoreMaps ? 'See less...' : `See ${extraLinks.length} more...` output.push(
  • {text}
  • ) } return output } render = () => { const { topic } = this.props return (
    {topic.get('user_name')}
    {topic.get('synapse_count').toString()} {this.state.hoveringSynapseCount &&
    Click to see this topics synapses
    }
    {topic.get('map_count').toString()} {!this.state.showInMaps && this.state.hoveringMapCount && (
    Click to see which maps topic appears on
    )} {this.state.showInMaps &&
      {this.inMaps(topic)}
    }
    ) } } Info.propTypes = { topic: PropTypes.object // backbone object } export default Info