import React from "react" ;
import { Link } from "react-router-dom" ;
import { Menu, MenuList, MenuButton, MenuItem } from "@reach/menu-button" ;
import "./PublicationSearchResult.css" ;
import { PublicationSearchResult2 } from "./PublicationSearchResult2.js" ;
import { PreviewableImage } from "./PreviewableImage.js" ;
import { PUBLICATION_EXCESS_ARTICLE_THRESHOLD } from "./constants.js" ;
import { gAppRef } from "./App.js" ;
import { makeCollapsibleList, pluralString, updateRecord } from "./utils.js" ;
const axios = require( "axios" ) ;
// --------------------------------------------------------------------
export class PublicationSearchResult extends React.Component
{
render() {
// prepare the basic details
const display_description = PreviewableImage.adjustHtmlForPreviewableImages(
this.props.data[ "pub_description!" ] || this.props.data.pub_description
) ;
const parent_publ = this.props.data._parent_publ ;
const image_url = PublicationSearchResult._makeImageUrl( this.props.data ) ;
// prepare the publication's URL
let pub_url = this.props.data.pub_url ;
if ( pub_url )
pub_url = gAppRef.makeExternalDocUrl( pub_url ) ;
// prepare the tags
let tags = [] ;
if ( this.props.data[ "tags!" ] ) {
// the backend has provided us with a list of tags (possibly highlighted) - use them directly
// NOTE: We don't normally show HTML in tags, but in this case we need to, in order to be able to highlight
// matching search terms. This will have the side-effect of rendering any HTML that may be in the tag,
// but we can live with that.
for ( let i=0 ; i < this.props.data["tags!"].length ; ++i ) {
const tag = this.props.data.pub_tags[ i ] ; // nb: this is the actual tag (without highlights)
tags.push( ) ;
}
} else {
if ( this.props.data.pub_tags ) {
this.props.data.pub_tags.map(
tag => tags.push( {tag} )
) ;
}
}
// prepare the articles
let articles = [] ;
if ( this.props.data.articles ) {
for ( let i=0 ; i < this.props.data.articles.length ; ++i ) {
const article = this.props.data.articles[ i ] ;
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( ) ;
}
}
// prepare the menu
const menu = (