From 356b885e218afd7912ccbf522e963f33a760e420 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 25 Feb 2017 14:16:14 -0800 Subject: [PATCH] move mapCount and synapseCount hover/click logic to react --- app/assets/stylesheets/base.scss.erb | 14 --- frontend/src/components/TopicCard/Links.js | 122 +++++++++++---------- 2 files changed, 62 insertions(+), 74 deletions(-) diff --git a/app/assets/stylesheets/base.scss.erb b/app/assets/stylesheets/base.scss.erb index dcc3ea1e..ab8bf101 100644 --- a/app/assets/stylesheets/base.scss.erb +++ b/app/assets/stylesheets/base.scss.erb @@ -330,7 +330,6 @@ top: 44px; left: 0px; font-size: 12px !important; - display: none; position: absolute; background: black; color: white; @@ -340,10 +339,6 @@ z-index: 100; } - &:hover .hoverTip { - display: block; - } - .tip a { color: white; } @@ -365,10 +360,6 @@ line-height: 14px; position: relative; } - - li.hideExtra { - display: none; - } } .synapseCount { @@ -404,10 +395,6 @@ z-index: 100; } - &:hover .tip { - display: block; - } - .tip:before { content: ''; position: absolute; @@ -626,7 +613,6 @@ background-color: #E0E0E0; display:block; } .CardOnGraph .tip { - display:none; position: absolute; background: black; top: 35px; diff --git a/frontend/src/components/TopicCard/Links.js b/frontend/src/components/TopicCard/Links.js index 1e28f374..f5f60c53 100644 --- a/frontend/src/components/TopicCard/Links.js +++ b/frontend/src/components/TopicCard/Links.js @@ -8,70 +8,20 @@ import Permission from './Permission' // TODO use a callback instead of an import import Visualize from '../../Metamaps/Visualize' -const inmaps = (topic) => { - const inmapsArray = topic.get('inmaps') || [] - const inmapsLinks = topic.get('inmapsLinks') || [] - - let html = '' - if (inmapsArray.length < 6) { - for (let i = 0; i < inmapsArray.length; i++) { - const url = '/maps/' + inmapsLinks[i] - html += '
  • ' + inmapsArray[i] + '
  • ' - } - } else { - for (let i = 0; i < 5; i++) { - const url = '/maps/' + inmapsLinks[i] - html += '
  • ' + inmapsArray[i] + '
  • ' - } - const extra = inmapsArray.length - 5 - html += '
  • See ' + extra + ' more...
  • ' - for (let i = 5; i < inmapsArray.length; i++) { - const url = '/maps/' + inmapsLinks[i] - html += '
  • ' + inmapsArray[i] + '
  • ' - } - } - - return html -} - -// TODO all of these should be largely turned into passed-in callbacks -const bindShowCardListeners = (topic, ActiveMapper) => { - $('.links .mapCount').unbind().click(function(event) { - $('.mapCount .tip').toggle() - $('.showcard .hoverTip').toggleClass('hide') - }) - $('.showcard').unbind('.hideTip').bind('click.hideTip', function() { - $('.mapCount .tip').hide() - $('.showcard .hoverTip').removeClass('hide') - }) - - var originalText = $('.showMore').html() - $('.mapCount .tip .showMore').unbind().toggle( - function(event) { - $('.extraText').toggleClass('hideExtra') - $('.showMore').html('Show less...') - }, - function(event) { - $('.extraText').toggleClass('hideExtra') - $('.showMore').html(originalText) - } - ) -} - class Links extends Component { constructor(props) { super(props) this.state = { showMetacodeTitle: false, - showMetacodeSelect: false + showMetacodeSelect: false, + showInMaps: false, + showMoreMaps: false, + hoveringMapCount: false, + hoveringSynapseCount: false } } - componentDidMount = () => { - bindShowCardListeners(this.props.topic, this.props.ActiveMapper) - } - handleMetacodeSelect = metacodeId => { this.props.updateTopic({ metacode_id: metacodeId @@ -79,6 +29,47 @@ class Links extends Component { Visualize.mGraph.plot() } + toggleShowMoreMaps = () => { + 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) { + const text = this.state.showMoreMaps ? 'See less...' : `See ${extraLinks.length} more...` + output.push(
  • {text}
  • ) + if (this.state.showMoreMaps) { + extraLinks.forEach(obj => { + output.push(
  • {obj.mapName}
  • ) + }) + } + } + + return output + } + render = () => { const { topic, ActiveMapper } = this.props const metacode = topic.getMetacode() @@ -112,16 +103,27 @@ class Links extends Component {
    {topic.get('user_name')}
    -
    +
    {topic.get('map_count').toString()} -
    Click to see which maps topic appears on
    -
      {inmaps(topic)}
    + {!this.state.showInMaps && this.state.hoveringMapCount && ( +
    Click to see which maps topic appears on
    + )} + {this.state.showInMaps &&
      {this.inMaps(topic)}
    }
    - +
    {topic.get('synapse_count').toString()} -
    Click to see this topics synapses
    + {this.state.hoveringSynapseCount &&
    Click to see this topics synapses
    }