diff options
Diffstat (limited to 'scraper/client/paper')
| -rw-r--r-- | scraper/client/paper/paper.citations.js | 42 | ||||
| -rw-r--r-- | scraper/client/paper/paper.verify.js | 68 |
2 files changed, 75 insertions, 35 deletions
diff --git a/scraper/client/paper/paper.citations.js b/scraper/client/paper/paper.citations.js index 5c8e0e0c..c55599e0 100644 --- a/scraper/client/paper/paper.citations.js +++ b/scraper/client/paper/paper.citations.js @@ -5,26 +5,32 @@ import { Link } from 'react-router-dom' import * as actions from '../actions' -import { TableObject } from '../common' +import { TableObject, Loader } from '../common' import { USES_DATASET } from '../types' class PaperCitations extends Component { - componentDidMount() { - this.props.actions.getVerifications() + componentDidUpdate(prevProps) { + if (this.props.api.paperInfo.dataset !== prevProps.api.paperInfo.dataset) { + this.props.actions.getVerificationsDataset(this.props.api.paperInfo.dataset.key) + } } render() { - const { dataset, citations } = this.props.api.paperInfo - let { verifications } = this.props.api.verifications - verifications = verifications || {} - if (!dataset || !citations) return null - console.log('rendering citations...') - // console.log(citations) + const { paperInfo, unknownCitations, verifications } = this.props.api + const { dataset, citations } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return <Loader /> + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + return ( <div className='citations'> <h2>{dataset.name_full}: Citations</h2> <ul> - {citations.map((citation, i) => { + {citations.concat(unknownCitations.citations) + .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) + .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) + .map((pair, i) => { + const [ title, uses_dataset, citation ] = pair let cite = { ...citation } cite.id = { _raw: true, @@ -32,7 +38,9 @@ class PaperCitations extends Component { } cite.pdf = { _raw: true, - value: (cite.pdf && cite.pdf.length) ? <a href={cite.pdf[0]} rel='noopener noreferrer' target="_blank">[pdf]</a> : "no pdf" + value: (cite.pdf && cite.pdf.length) + ? cite.pdf.map((pdf, i) => <a key={'pdf_' + i} href={pdf} rel='noopener noreferrer' target="_blank">[pdf]</a>) + : "no pdf" } cite.s2 = { _raw: true, @@ -45,23 +53,19 @@ class PaperCitations extends Component { } cite.addresses = { _raw: true, - value: cite.addresses.map((address, j) => ( + value: (cite.addresses || []).map((address, j) => ( <div key={j}>{address.name}{', '}<span className='type'>{address.type}</span></div> )) } - if (citation.id in verifications && verifications[citation.id].dataset === dataset.key) { - const verification = verifications[citation.id] + if (citation.id in verifiedLookup) { + const verification = verifiedLookup[citation.id] cite.verified = { _raw: true, value: verification.uses_dataset === USES_DATASET.YES ? <span className='verified'>uses dataset</span> : verification.uses_dataset === USES_DATASET.NO ? <span className='unverified'>{"doesn't use dataset"}</span> - : verification.uses_dataset === 'TRUE' - ? <span className='verified'>uses dataset</span> - : verification.uses_dataset === 'FALSE' - ? <span className='unverified'>{"doesn't use dataset"}</span> - : <span className='unknown'>{"not enough information"}</span> + : <span className='unknown'>{"not enough information"}</span> } } else { diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 65342adf..1b55186a 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -9,13 +9,16 @@ 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, } class PaperVerify extends Component { @@ -26,6 +29,7 @@ class PaperVerify extends Component { 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') @@ -34,52 +38,66 @@ class PaperVerify extends Component { componentDidUpdate(oldProps) { const { sha256 } = this.props.match.params - const { verify } = this.props.api + const { address, verify } = this.props.api const { sha256: oldSha256 } = oldProps.match.params - const { verify: oldVerify } = oldProps.api + 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) - this.setState({ + 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) - this.setState({ + newState = { ...initialState, ...citationState, - }) + ...address.paper, + } + this.setState(newState) } else { // console.log(paper) console.log('GOT CUSTOM CITATION STATE', paper) const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...citationState, + ...address.paper, uses_dataset: paper.uses_dataset === "TRUE", images_in_paper: paper.images_in_paper === "TRUE", verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, - }) + } + this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { const citationState = this.getCitationState(sha256) - this.setState(citationState) + newState = citationState + this.setState(newState) } } getCitationState(sha256) { const { paperInfo, unknownCitations } = this.props.api let citation = (unknownCitations.citations || []).find(f => f.id === sha256) - if (!citation) { + 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 } @@ -148,7 +166,7 @@ class PaperVerify extends Component { } render() { - let { paperInfo } = this.props.api + const { paperInfo, unknownCitations } = this.props.api if (paperInfo.loading) return <Loader /> // console.log(this.state) const { citation } = this.state @@ -185,6 +203,8 @@ class PaperVerify extends Component { </a> </div> + {this.renderLocationForm()} + <div className='row vettingRow'> <div className='rowHeading'> {'Uses dataset'} @@ -194,7 +214,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.YES, })} @@ -207,7 +227,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.NO, })} @@ -220,7 +240,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.UNKNOWN, })} @@ -230,8 +250,8 @@ class PaperVerify extends Component { </div> <div - className={this.state.uses_dataset === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} - disabled={this.state.uses_dataset === USES_DATASET.YES ? false : true} + className={parseInt(this.state.uses_dataset) === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} + disabled={parseInt(this.state.uses_dataset) === USES_DATASET.YES ? false : true} > <div className='rowHeading'> {'Paper shows images'} @@ -355,6 +375,22 @@ class PaperVerify extends Component { </div> ) } + renderLocationForm() { + if (!this.state.citation.isUnknown) return + return ( + <div> + <div className='param'> + <label>Institution</label> + <input + type='text' + value={this.state.address.institution_1} + placeholder='Institution' + onChange={e => this.setState({ institution_1: e.target.value })} + /> + </div> + </div> + ) + } } /* |
