summaryrefslogtreecommitdiff
path: root/scraper/client/paper/paper.verify.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-03-19 20:45:24 +0100
committerJules Laplace <julescarbon@gmail.com>2019-03-19 20:45:24 +0100
commit7eb3c04ef85fa0311bdf30b24df2aba102757878 (patch)
treebfb1354dcbed9486b43e75c7d2507a725212db24 /scraper/client/paper/paper.verify.js
parent46885570e527a2bb8a374e7044afdf0a4c5ba07e (diff)
rebuild site
Diffstat (limited to 'scraper/client/paper/paper.verify.js')
-rw-r--r--scraper/client/paper/paper.verify.js205
1 files changed, 205 insertions, 0 deletions
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 <Loader />
+ console.log(this.state)
+ const { citation } = this.state
+ if (!citation) {
+ return <div>Citation not found in this paper</div>
+ }
+ console.log(citation)
+ return (
+ <div className='form'>
+ <h3>{citation.title}</h3>
+ <div className='gray'>
+ {citation.id}
+ {' | PDFs: '}
+ {citation.pdf.map((pdf,i) => {
+ const domain = pdf.replace('www.','').split('/').slice(2,3)[0] || 'unknown'
+ return (
+ <a
+ key={i}
+ onClick={() => this.setState({ pdf_index: i })}
+ className={i === this.state.pdf_index ? 'selected pdfLink' : 'pdfLink'}
+ >
+ {'[' + domain + '] '}
+ </a>
+ )
+ })}
+ </div>
+
+ <div className='param'>
+ <input
+ className='vetting'
+ type='checkbox'
+ value={this.state.verified}
+ onChange={e => this.setState({
+ verified: e.target.value,
+ })}
+ />
+ </div>
+
+ <div className='param'>
+ <input
+ type='text'
+ className='verified_by'
+ value={this.state.verified_by}
+ placeholder='Verified by'
+ onChange={e => this.setState({ notes: e.target.value })}
+ />
+ </div>
+
+ <div className='param'>
+ <input
+ type='text'
+ className='notes'
+ value={this.state.notes}
+ placeholder='Notes'
+ onChange={e => this.setState({ notes: e.target.value })}
+ />
+ </div>
+
+ <div className='param'>
+ <button
+ className='btn btn-primary'
+ onClick={this.save.bind(this)}
+ ref={ref => this.button = ref}
+ >Save Verification</button>
+
+ <button
+ className='btn'
+ onClick={this.next.bind(this)}
+ >{'Next >'}</button>
+ </div>
+
+ <iframe className='pdfViewer' src={citation.pdf[this.state.pdf_index]} />
+ </div>
+ )
+ }
+}
+
+const mapStateToProps = state => ({
+ api: state.api,
+})
+const mapDispatchToProps = dispatch => ({
+ actions: bindActionCreators({ ...actions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(PaperVerify)