From 5c176ce457f195dfad15d0c7d01d36fc2f9fdbdd Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 13 Feb 2019 19:19:10 +0100 Subject: possible PDF embed --- scraper/client/paper/paper.address.js | 85 ++++++++++++++++++++++++++++++--- scraper/client/paper/paper.citations.js | 3 +- scraper/client/paper/paper.css | 12 ++++- scraper/client/paper/paper.manager.js | 4 +- scraper/client/paper/paper.unknown.js | 4 +- 5 files changed, 95 insertions(+), 13 deletions(-) (limited to 'scraper/client/paper') diff --git a/scraper/client/paper/paper.address.js b/scraper/client/paper/paper.address.js index 2240388f..6d02c3db 100644 --- a/scraper/client/paper/paper.address.js +++ b/scraper/client/paper/paper.address.js @@ -4,27 +4,98 @@ import { connect } from 'react-redux' import * as actions from '../actions' -// import { Loader } from '../common' +import { Loader, Autocomplete } from '../common' +const initialState = { + citation: null, + institution_1: '', + institution_2: '', + institution_3: '', + institution_4: '', +} class PaperAddress extends Component { + state = { + ...initialState + } + componentDidMount() { const { sha256 } = this.props.match.params this.props.actions.getAddress(sha256) + const citation = this.getCitation(sha256) + this.setState({ citation }) } - componentDidUpdate(newProps) { - const { sha256: oldSha256 } = this.props.match.params - const { sha256 } = newProps.match.params - if (sha256 !== oldSha256) { - this.props.actions.getPaperInfo(this.props.match.params.key) + componentDidUpdate(oldProps) { + const { sha256 } = this.props.match.params + const { address } = this.props.api + const { sha256: oldSha256 } = oldProps.match.params + const { address: oldAddress } = oldProps.api + const oldPaper = oldAddress ? oldAddress.paper : null + const paper = address ? address.paper : null + + if (oldSha256 && sha256 !== oldSha256) { + console.log('update address') + this.props.actions.getAddress(sha256) + const citation = this.getCitation(sha256) + this.setState({ + ...initialState, + citation + }) + } else if (address && !address.loading && address.paper && (!oldPaper || oldPaper !== address.paper)) { + if (paper.error) { + const citation = this.getCitation(sha256) + this.setState({ + ...initialState, + citation, + }) + } else { + console.log(paper) + const citation = this.getCitation(sha256) + this.setState({ + citation, + institution_1: paper['Institution #1'], + institution_2: paper['Institution #2'], + institution_3: paper['Institution #3'], + institution_4: paper['Institution #4'], + }) + } + } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { + const citation = this.getCitation(sha256) + this.setState({ citation }) } } + getCitation(sha256) { + const { paperInfo, unknownCitations } = this.props.api + let citation = (unknownCitations.citations || []).find(f => f.id === sha256) + if (!citation) { + citation = (paperInfo.citations || []).find(f => f.id === sha256) + } + console.log(sha256, citation) + return citation + } + render() { // if (!this.props.match.params.key) return null // if (this.props.api.address.loading) return // if (!this.props.api.paperInfo.dataset) return
Metadata not found
- return null + let { paperInfo, unknownCitations } = this.props.api + if (paperInfo.loading || unknownCitations.loading) return + console.log(this.state) + const { citation } = this.state + if (!citation) { + return
Citation not found in this paper
+ } + return ( +
+

{citation.title}

+
{citation.id}
+ {this.state.institution_1} + {/* +