Changed how we scroll to articles already on-screen.

master
Pacman Ghost 2 years ago
parent 1446d97ac3
commit 11c8f0dced
  1. 26
      web/src/PublicationSearchResult.js
  2. 12
      web/src/SearchResults.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( <div
dangerouslySetInnerHTML = {{__html: article.article_title}}
onClick = { () => this.props.onArticleClick( article.article_id ) }
style = {{ cursor: "pointer" }}
title = "Go to this article."
/> ) ;
} else {
// handle clicks on the article normally
articles.push( <Link title="Show this article."
to = { gAppRef.makeAppUrl( "/article/" + article.article_id ) }
dangerouslySetInnerHTML = {{ __html: article.article_title }}
/> ) ;
}
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( <Link title="Show this article."
to = { gAppRef.makeAppUrl( "/article/" + article.article_id ) }
onClick = {onArticleClick}
dangerouslySetInnerHTML = {{ __html: article.article_title }}
/> ) ;
}
}

@ -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 = [] ;

Loading…
Cancel
Save