diff --git a/web/src/PublicationSearchResult.js b/web/src/PublicationSearchResult.js index 8e0bda1..8293f14 100644 --- a/web/src/PublicationSearchResult.js +++ b/web/src/PublicationSearchResult.js @@ -58,21 +58,17 @@ export class PublicationSearchResult extends React.Component if ( this.props.data.articles ) { for ( let i=0 ; i < this.props.data.articles.length ; ++i ) { const article = this.props.data.articles[ i ] ; - if ( this.props.onArticleClick ) { - // forward clicks on the article to the parent - articles.push(
this.props.onArticleClick( article.article_id ) } - style = {{ cursor: "pointer" }} - title = "Go to this article." - /> ) ; - } else { - // handle clicks on the article normally - articles.push( ) ; - } + let onArticleClick = (evt) => { + // NOTE: We let the parent take a look at clicks first, so that they can scroll + // to the article if it's already on-screen. + if ( this.props.onArticleClick && this.props.onArticleClick( article.article_id ) ) + evt.preventDefault() ; + } ; + articles.push( ) ; } } diff --git a/web/src/SearchResults.js b/web/src/SearchResults.js index 6e7f167..e1adfb2 100644 --- a/web/src/SearchResults.js +++ b/web/src/SearchResults.js @@ -34,11 +34,17 @@ export class SearchResults extends React.Component // track articles let articleRefs = {} ; function scrollToArticle( article_id ) { + // NOTE: If the user has clicked on an article that has been listed as part of a publication, + // we just scroll to that article (since articles are also returned as part of the search results + // when searching for a publication). + // NOTE: We could do the same thing when clicking on a publication that has been listed as part + // of a publisher, but in this case, it's probably better UX to show the publication's page, + // along with its articles. const node = ReactDOM.findDOMNode( articleRefs[article_id] ) ; - if ( node ) + if ( node ) { node.scrollIntoView() ; - else - document.location = gAppRef.makeAppUrl( "/article/" + article_id ) ; + return true ; + } } // render the search results results = [] ;