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' import { USES_DATASET } from '../types' const initialState = { citation: null, address: {}, uses_dataset: USES_DATASET.UNKNOWN, images_in_paper: "FALSE", used_as_model: "FALSE", verified_by: localStorage.getItem('verify.username') || '', reference: '', notes: '', location: '', pdf_index: 0, isUnknown: false, institution_1: '', institution_2: '', institution_3: '', validate_1: false, validate_2: false, validate_3: false, } class PaperVerify extends Component { state = { ...initialState } componentDidMount() { const { sha256 } = this.props.match.params this.props.actions.getInstitutions() this.props.actions.getAddress(sha256) this.props.actions.getVerification(sha256) const citationState = this.getCitationState(sha256) console.log('DID MOUNT') this.setState(citationState) } componentDidUpdate(oldProps) { const { sha256 } = this.props.match.params const { address, verify } = this.props.api const { sha256: oldSha256 } = oldProps.match.params const { verify: oldVerify, address: oldAddress } = oldProps.api const oldPaper = oldVerify ? oldVerify.paper : null const paper = verify ? verify.paper : null let newState = {} if (oldSha256 && sha256 !== oldSha256) { console.log('update verification') this.props.actions.getAddress(sha256) this.props.actions.getVerification(sha256) const citationState = this.getCitationState(sha256) newState = { ...initialState, ...citationState, ...address.paper, } this.setState(newState) } else if (verify && !verify.loading && verify.paper && (!oldPaper || oldPaper !== verify.paper)) { if (paper.error) { console.log('USING PAPER VERIFICATION') const citationState = this.getCitationState(sha256) newState = { ...initialState, ...citationState, ...address.paper, } this.setState(newState) } else { // console.log(paper) console.log('GOT CUSTOM CITATION STATE', paper) const citationState = this.getCitationState(sha256) newState = { ...citationState, ...address.paper, uses_dataset: paper.uses_dataset, images_in_paper: paper.images_in_paper, verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, } this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { console.log('loaded unknown citations') const citationState = this.getCitationState(sha256) newState = citationState this.setState(newState) } } getCitationState(sha256) { const { paperInfo, unknownCitations } = this.props.api let citation = (unknownCitations.citations || []).find(f => f.id === sha256) if (citation) { citation.isUnknown = true } else { citation = (paperInfo.citations || []).find(f => f.id === sha256) if (citation) { citation.isUnknown = false } } // console.log(sha256, citation) let state = { citation } return state } save() { console.log(this.state) let date = new Date() let mon = date.getMonth() + 1 if (mon < 10) mon = "0" + mon let day = date.getDate() if (day < 10) day = "0" + day let time = date.toTimeString().split(" ")[0] let dateString = date.getFullYear() + '-' + mon + '-' + day + ' ' + time localStorage.setItem('verify.username', this.state.verified_by) this.props.actions.postVerification({ paper_id: this.state.citation.id, title: this.state.citation.title, dataset: this.props.api.paperInfo.dataset.key, uses_dataset: this.state.uses_dataset, images_in_paper: this.state.images_in_paper, used_as_model: this.state.used_as_model, verified_by: this.state.verified_by, reference: this.state.reference, notes: this.state.notes, date: dateString, isUnknown: this.state.citation.isUnknown, institution_1: this.state.institution_1, validate_1: this.state.validate_1, institution_2: this.state.institution_2, validate_2: this.state.validate_2, institution_3: this.state.institution_3, validate_3: this.state.validate_3, }) this.next() } prev() { const { key } = this.props.api.paperInfo.dataset const { paperInfo, sortedCitations } = this.props.api const citations = sortedCitations || paperInfo.citations || [] let citationIndex = citations.findIndex(f => f.id === this.state.citation.id) if (citationIndex === -1) { history.push('/paper/' + key + '/info/') } else { citationIndex -= 1 if (citationIndex < 0) { history.push('/paper/' + key + '/info/') } else { let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } } next() { const { key } = this.props.api.paperInfo.dataset const { paperInfo, sortedCitations } = this.props.api const citations = sortedCitations || paperInfo.citations || [] let citationIndex = citations.findIndex(f => f.id === this.state.citation.id) if (citationIndex === -1) { history.push('/paper/' + key + '/info/') } else { citationIndex += 1 if (citationIndex >= citations.length) { history.push('/paper/' + key + '/info/') } else { let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } } render() { const { paperInfo, unknownCitations } = this.props.api if (paperInfo.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 + '] '} ) })} {' | '} {'[semantic scholar]'}
{this.renderLocationForm()}
{'Uses dataset'}
{'Paper shows images'}
{'Used as model'}
this.setState({ verified_by: e.target.value })} />