diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-02-13 18:05:35 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-02-13 18:05:35 +0100 |
| commit | 83063b97105c7514d71ec2afaaf66def49116214 (patch) | |
| tree | b538a8b913cec7e563d23778a0cc4c523f559bda /scraper/client/paper | |
| parent | 8d17c7b8491f270ae1785921b0ae0d89f8290c7b (diff) | |
listing citations, known and unknown
Diffstat (limited to 'scraper/client/paper')
| -rw-r--r-- | scraper/client/paper/index.js | 8 | ||||
| -rw-r--r-- | scraper/client/paper/paper.address.js | 38 | ||||
| -rw-r--r-- | scraper/client/paper/paper.citations.js | 58 | ||||
| -rw-r--r-- | scraper/client/paper/paper.css | 16 | ||||
| -rw-r--r-- | scraper/client/paper/paper.random.js | 36 | ||||
| -rw-r--r-- | scraper/client/paper/paper.unknown.js | 53 |
6 files changed, 209 insertions, 0 deletions
diff --git a/scraper/client/paper/index.js b/scraper/client/paper/index.js index c10ea011..4fad0316 100644 --- a/scraper/client/paper/index.js +++ b/scraper/client/paper/index.js @@ -1,5 +1,9 @@ import Manager from './paper.manager' import Info from './paper.info' +import Citations from './paper.citations' +import UnknownCitations from './paper.unknown' +import Random from './paper.random' +import Address from './paper.address' import './paper.css' // import './search.css' @@ -7,4 +11,8 @@ import './paper.css' export { Manager, Info, + Citations, + UnknownCitations, + Random, + Address, } diff --git a/scraper/client/paper/paper.address.js b/scraper/client/paper/paper.address.js new file mode 100644 index 00000000..2240388f --- /dev/null +++ b/scraper/client/paper/paper.address.js @@ -0,0 +1,38 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import * as actions from '../actions' + +// import { Loader } from '../common' + +class PaperAddress extends Component { + componentDidMount() { + const { sha256 } = this.props.match.params + this.props.actions.getAddress(sha256) + } + + componentDidUpdate(newProps) { + const { sha256: oldSha256 } = this.props.match.params + const { sha256 } = newProps.match.params + if (sha256 !== oldSha256) { + this.props.actions.getPaperInfo(this.props.match.params.key) + } + } + + render() { + // if (!this.props.match.params.key) return null + // if (this.props.api.address.loading) return <Loader /> + // if (!this.props.api.paperInfo.dataset) return <div className='paperInfo'>Metadata not found</div> + return null + } +} + +const mapStateToProps = state => ({ + api: state.api, +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(PaperAddress) diff --git a/scraper/client/paper/paper.citations.js b/scraper/client/paper/paper.citations.js new file mode 100644 index 00000000..de423a77 --- /dev/null +++ b/scraper/client/paper/paper.citations.js @@ -0,0 +1,58 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import * as actions from '../actions' + +import { TableObject } from '../common' + +class PaperCitations extends Component { + render() { + const { dataset, citations } = this.props.api.paperInfo + if (!dataset || !citations) return null + console.log('rendering citations...') + return ( + <div className='citations'> + <h2>{dataset.name_full}: Citations</h2> + <ul> + {citations.map((citation, i) => { + let cite = { ...citation } + cite.id = { + _raw: true, + value: <a href={'/api/address/' + dataset.key + '/' + citation.id}>{citation.id}</a> + } + cite.pdf = { + _raw: true, + value: cite.pdf ? <a href={cite.pdf} rel='noopener noreferrer' target="_blank">[pdf]</a> : "no pdf" + } + cite.addresses = { + _raw: true, + value: cite.addresses.map((address, j) => ( + <div key={j}>{address.address}{', '}<span className='type'>{address.type}</span></div> + )) + } + return ( + <li key={i}> + <TableObject + summary + object={cite} + tag={cite.title} + order={['id', 'pdf', 'year', 'addresses']} + /> + </li> + ) + })} + </ul> + </div> + ) + } +} + +const mapStateToProps = state => ({ + api: state.api +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(PaperCitations) diff --git a/scraper/client/paper/paper.css b/scraper/client/paper/paper.css index c1a775c1..cd2f8529 100644 --- a/scraper/client/paper/paper.css +++ b/scraper/client/paper/paper.css @@ -1,3 +1,19 @@ .paperInfo { padding: 10px; +} + +.citations ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +.citations li { + list-style-type: none; + margin: 0; + padding-bottom: 40px; +} + +.type { + color: #888; }
\ No newline at end of file diff --git a/scraper/client/paper/paper.random.js b/scraper/client/paper/paper.random.js new file mode 100644 index 00000000..aab22172 --- /dev/null +++ b/scraper/client/paper/paper.random.js @@ -0,0 +1,36 @@ +import React, { Component } from 'react' +// import { NavLink } from 'react-router-dom' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import { choice } from '../util' +import { history } from '../store' + +import * as actions from '../actions' + +class PaperRandom extends Component { + componentDidUpdate() { + const { citations } = this.props.api.unknownCitations + if (!citations) return + const citation = choice(citations) + console.log(citation) + if (citation.id) { + history.push('/paper/' + this.props.match.params.key + '/address/' + citation.id) + } + } + + render() { + return ( + <div>Sending you to a random citation...</div> + ) + } +} + +const mapStateToProps = state => ({ + api: state.api +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(PaperRandom) diff --git a/scraper/client/paper/paper.unknown.js b/scraper/client/paper/paper.unknown.js new file mode 100644 index 00000000..7a20f398 --- /dev/null +++ b/scraper/client/paper/paper.unknown.js @@ -0,0 +1,53 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import * as actions from '../actions' + +import { TableObject } from '../common' + +class PaperUnknown extends Component { + render() { + const { dataset } = this.props.api.paperInfo + const { citations } = this.props.api.unknownCitations + if (!dataset || !citations) return null + console.log('rendering unknown citations...') + return ( + <div className='citations'> + <h2>{dataset.name_full}: Unknown Citations</h2> + <ul> + {citations.map((citation, i) => { + let cite = { ...citation } + cite.id = { + _raw: true, + value: <a href={'/api/address/' + dataset.key + '/' + citation.id}>{citation.id}</a> + } + cite.pdf = { + _raw: true, + value: cite.pdf ? <a href={cite.pdf} rel='noopener noreferrer' target="_blank">[pdf]</a> : "no pdf" + } + return ( + <li key={i}> + <TableObject + summary + object={cite} + tag={cite.title} + /> + </li> + ) + })} + </ul> + </div> + ) + } +} + // order={['id', 'pdf', 'year']} + +const mapStateToProps = state => ({ + api: state.api +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(PaperUnknown) |
