diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 16:25:23 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 16:25:23 +0100 |
| commit | a8cfefc602a43753353940816633daae3e1692aa (patch) | |
| tree | dea6f928b639777070c9bd9c9a3d7cc8cbfea9a4 /scraper/client/paper/citationList.component.js | |
| parent | b94cad3271d8269b5965d0096ce5564abed9ad53 (diff) | |
abstract into citationList component
Diffstat (limited to 'scraper/client/paper/citationList.component.js')
| -rw-r--r-- | scraper/client/paper/citationList.component.js | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js new file mode 100644 index 00000000..435dfde2 --- /dev/null +++ b/scraper/client/paper/citationList.component.js @@ -0,0 +1,96 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import { Link } from 'react-router-dom' + +import * as actions from '../actions' + +import { TableObject, Loader } from '../common' +import { USES_DATASET } from '../types' + +class CitationList extends Component { + render() { + const { citations, title, api } = this.props + const { paperInfo, unknownCitations, verifications } = api + const { dataset } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return <Loader /> + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + + return ( + <div className='citations'> + <h2>{title}</h2> + <ul> + {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, + value: <Link to={'/paper/' + dataset.key + '/verify/' + citation.id}>{citation.id}</Link> + } + cite.pdf = { + _raw: true, + 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, + value: <a + href={'https://www.semanticscholar.org/paper/' + citation.id} + target="_blank" + rel="noopener noreferrer" + className={'pdfLink'} + >{'[semantic scholar]'}</a> + } + cite.addresses = { + _raw: true, + value: (cite.addresses || []).map((address, j) => ( + <div key={j}>{address.name}{', '}<span className='type'>{address.type}</span></div> + )) + } + 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> + : <span className='not_enough_info'>{"not enough information"}</span> + } + } + else { + cite.verified = { + _raw: true, + value: <span className='unknown'>unknown</span> + } + } + return ( + <li key={i}> + <TableObject + summary + object={cite} + tag={cite.title} + order={['id', 'pdf', 's2', 'year', 'addresses', 'verified']} + /> + </li> + ) + })} + </ul> + </div> + ) + } +} + +const mapStateToProps = state => ({ + api: state.api +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(CitationList) |
