From 7eb3c04ef85fa0311bdf30b24df2aba102757878 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 19 Mar 2019 20:45:24 +0100 Subject: rebuild site --- scraper/client/paper/paper.verify.js | 205 +++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 scraper/client/paper/paper.verify.js (limited to 'scraper/client/paper/paper.verify.js') diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js new file mode 100644 index 00000000..cfce8f28 --- /dev/null +++ b/scraper/client/paper/paper.verify.js @@ -0,0 +1,205 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import * as actions from '../actions' + +import { history } from '../store' + +import { Loader, Autocomplete } from '../common' + +const initialState = { + citation: null, + verify: '', + verified_by: '', + notes: '', + pdf_index: 0, +} +class PaperVerify extends Component { + state = { + ...initialState + } + + componentDidMount() { + const { sha256 } = this.props.match.params + this.props.actions.getInstitutions() + this.props.actions.getVerification(sha256) + const citationState = this.getVerificationState(sha256) + console.log('DID MOUNT') + this.setState(citationState) + } + + 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.getVerification(sha256) + const citationState = this.getCitationState(sha256) + this.setState({ + ...initialState, + ...citationState, + }) + } else if (address && !address.loading && address.paper && (!oldPaper || oldPaper !== address.paper)) { + if (paper.error) { + console.log('USING PAPER ADDRESS') + const citationState = this.getCitationState(sha256) + this.setState({ + ...initialState, + ...citationState, + }) + } else { + // console.log(paper) + console.log('GOT CUSTOM ADDRESS') + const citationState = this.getCitationState(sha256) + this.setState({ + ...citationState, + verified: paper.verified, + verified_by: paper.verified_by, + }) + } + } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { + const citationState = this.getCitationState(sha256) + this.setState(citationState) + } + } + + getCitationState(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) + let state = { citation } + let addresses = citation ? citation.addresses : [] + if (addresses) { + addresses.forEach((address, i) => { + state['institution_' + (i + 1)] = address.address + }) + } + return state + } + + save() { + console.log(this.state) + this.props.actions.postVerification({ + paper_id: this.state.citation.id, + title: this.state.citation.title, + verified: this.state.verified, + verified_by: this.state.verified_by, + notes: this.state.notes, + }) + this.next(false) + } + + next() { + const { key } = this.props.api.paperInfo.dataset + const { unknownCitations } = this.props.api + let citationIndex = (unknownCitations.citations || []) + .findIndex(f => f.id === this.state.citation.id) + if (citationIndex === -1) { + history.push('/paper/' + key + '/info/') + } else { + citationIndex += 1 + if (citationIndex >= unknownCitations.length) { + history.push('/paper/' + key + '/info/') + } else { + let nextId = unknownCitations.citations[citationIndex].id + history.push('/paper/' + key + '/address/' + nextId) + } + } + } + + render() { + 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
+ } + console.log(citation) + return ( +
+

{citation.title}

+
+ {citation.id} + {' | PDFs: '} + {citation.pdf.map((pdf,i) => { + const domain = pdf.replace('www.','').split('/').slice(2,3)[0] || 'unknown' + return ( + this.setState({ pdf_index: i })} + className={i === this.state.pdf_index ? 'selected pdfLink' : 'pdfLink'} + > + {'[' + domain + '] '} + + ) + })} +
+ +
+ this.setState({ + verified: e.target.value, + })} + /> +
+ +
+ this.setState({ notes: e.target.value })} + /> +
+ +
+ this.setState({ notes: e.target.value })} + /> +
+ +
+ + + +
+ +