1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as actions from '../actions'
import { USES_DATASET, ADDRESS_TYPE_ENUM } from '../types'
import { Loader } from '../common'
class PaperManager extends Component {
componentDidMount() {
this.props.actions.getPaperInfo(this.props.match.params.key)
}
componentDidUpdate(oldProps) {
if (this.props.match.params.key !== oldProps.match.params.key) {
this.props.actions.getPaperInfo(this.props.match.params.key)
}
if (this.props.api.paperInfo.dataset !== oldProps.api.paperInfo.dataset && this.props.api.paperInfo.dataset && this.props.api.paperInfo.dataset.key) {
this.props.actions.getVerificationsDataset(this.props.api.paperInfo.dataset.key)
}
if (this.props.api.verifications !== oldProps.api.verifications && this.props.api.paperInfo.dataset) {
this.updateSortedCitations()
}
}
updateSortedCitations() {
const { api } = this.props
const { paperInfo, unknownCitations, verifications } = api
const { dataset } = paperInfo
if (!dataset || !paperInfo.citations || !unknownCitations.citations || !verifications[dataset.key]) {
this.props.actions.setSortedCitations([])
return
}
const citations = paperInfo.citations.concat(unknownCitations.citations)
let verifiedLookup = verifications[dataset.key] || {}
// first sort by verification status,
// then by a combination of its geolocated sources and paper count.
// penalize papers with no PDF
const sortedCitations = citations
.map(citation => [
citation.title,
verifiedLookup[citation.id]
? verifiedLookup[citation.id].uses_dataset
: USES_DATASET.NO_DATA,
(citation.addresses || [])
.map(address => (ADDRESS_TYPE_ENUM[address.type] || 0))
.reduce((a, b) => (a + b), 0)
+ (citation.pdf.length > 0
? Math.max(citation.pdf.length, 2)
: -2
),
citation
])
.sort((a, b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0]))))
.map(tup => ({
...tup[3],
verified: tup[1],
}))
console.log('updated')
this.props.actions.setSortedCitations(sortedCitations)
}
render() {
if (!this.props.match.params.key) return null
if (this.props.api.paperInfo.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)(PaperManager)
|