From a8cfefc602a43753353940816633daae3e1692aa Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:25:23 +0100 Subject: abstract into citationList component --- scraper/client/paper/citationList.component.js | 96 ++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 scraper/client/paper/citationList.component.js (limited to 'scraper/client/paper/citationList.component.js') 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 + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + + return ( +
+

{title}

+
    + {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: {citation.id} + } + cite.pdf = { + _raw: true, + value: (cite.pdf && cite.pdf.length) + ? cite.pdf.map((pdf, i) => [pdf]) + : "no pdf" + } + cite.s2 = { + _raw: true, + value: {'[semantic scholar]'} + } + cite.addresses = { + _raw: true, + value: (cite.addresses || []).map((address, j) => ( +
    {address.name}{', '}{address.type}
    + )) + } + if (citation.id in verifiedLookup) { + const verification = verifiedLookup[citation.id] + cite.verified = { + _raw: true, + value: verification.uses_dataset === USES_DATASET.YES + ? uses dataset + : verification.uses_dataset === USES_DATASET.NO + ? {"doesn't use dataset"} + : {"not enough information"} + } + } + else { + cite.verified = { + _raw: true, + value: unknown + } + } + return ( +
  • + +
  • + ) + })} +
+
+ ) + } +} + +const mapStateToProps = state => ({ + api: state.api +}) +const mapDispatchToProps = dispatch => ({ + actions: bindActionCreators({ ...actions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(CitationList) -- cgit v1.2.3-70-g09d2 From b6a9e2c382ac5e1f6c67040c74077ac03674c549 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:28:27 +0100 Subject: better sorting / style --- scraper/client/paper/citationList.component.js | 2 +- scraper/client/types.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'scraper/client/paper/citationList.component.js') diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index 435dfde2..09060375 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -22,7 +22,7 @@ class CitationList extends Component {

{title}

    {citations - .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) + .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, citation]) .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) .map((pair, i) => { const [ title, uses_dataset, citation ] = pair diff --git a/scraper/client/types.js b/scraper/client/types.js index 95b7a4e3..e6b4142c 100644 --- a/scraper/client/types.js +++ b/scraper/client/types.js @@ -16,4 +16,5 @@ export const USES_DATASET = { YES: "1", NO: "-1", UNKNOWN: "0", + NO_DATA: "-2", } -- cgit v1.2.3-70-g09d2 From d13d1cdfa51a481d318fb37cd02ba93915bdc3d1 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:50:57 +0100 Subject: add pdf length search --- scraper/client/paper/citationList.component.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'scraper/client/paper/citationList.component.js') diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index 09060375..1443b24c 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -22,8 +22,13 @@ class CitationList extends Component {

    {title}

      {citations - .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, citation]) - .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) + .map(citation => [ + citation.title, + verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, + citation.pdf.length, + citation + ]) + .sort((a,b) => (b[2] - a[2] || b[1] - a[1] || (a[0].localeCompare(b[0])))) .map((pair, i) => { const [ title, uses_dataset, citation ] = pair let cite = { ...citation } -- cgit v1.2.3-70-g09d2 From 36a44fe10d2501312d16aa5f70b31fd3585fb996 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 16:52:54 +0100 Subject: add pdf length search --- scraper/client/paper/citationList.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scraper/client/paper/citationList.component.js') diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index 1443b24c..ca4d2482 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -28,7 +28,7 @@ class CitationList extends Component { citation.pdf.length, citation ]) - .sort((a,b) => (b[2] - a[2] || b[1] - a[1] || (a[0].localeCompare(b[0])))) + .sort((a,b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0])))) .map((pair, i) => { const [ title, uses_dataset, citation ] = pair let cite = { ...citation } -- cgit v1.2.3-70-g09d2 From 27a557b5c5af1fee23c8be1ffae668b5ed6ba28d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 17:10:40 +0100 Subject: fix sorting --- scraper/client/actions.js | 2 +- scraper/client/paper/citationList.component.js | 36 ++++++++++++++++---------- scraper/client/paper/paper.verify.js | 22 +++++++++------- scraper/client/store.js | 10 ++++++- scraper/client/types.js | 4 +++ 5 files changed, 49 insertions(+), 25 deletions(-) (limited to 'scraper/client/paper/citationList.component.js') diff --git a/scraper/client/actions.js b/scraper/client/actions.js index 1b5152ea..b5c477f6 100644 --- a/scraper/client/actions.js +++ b/scraper/client/actions.js @@ -49,5 +49,5 @@ export const postVerification = data => dispatch => ( api(dispatch, post, 'verify', '/api/verify/add', data) ) - +export const setSortedCitations = sortedCitations => dispatch => dispatch({ type: types.system.set_sorted_citations, sortedCitations }) diff --git a/scraper/client/paper/citationList.component.js b/scraper/client/paper/citationList.component.js index ca4d2482..10e3ba9a 100644 --- a/scraper/client/paper/citationList.component.js +++ b/scraper/client/paper/citationList.component.js @@ -9,28 +9,38 @@ import { TableObject, Loader } from '../common' import { USES_DATASET } from '../types' class CitationList extends Component { + componentDidMount() { + const { citations, api } = this.props + const { paperInfo, unknownCitations, verifications } = api + const { dataset } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) { + this.props.actions.setSortedCitations([]) + return + } + let verifiedLookup = verifications[dataset.key] || {} + const sortedCitations = citations.map(citation => [ + citation.title, + verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, + citation.pdf.length, + citation + ]) + .sort((a,b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0])))) + .map(tup => tup[3]) + this.props.actions.setSortedCitations(sortedCitations) + } + render() { const { citations, title, api } = this.props - const { paperInfo, unknownCitations, verifications } = api + const { paperInfo, unknownCitations, verifications, sortedCitations } = api const { dataset } = paperInfo if (!dataset || !citations || !verifications[dataset.key]) return let verifiedLookup = verifications[dataset.key] || {} // console.log(verifications) - return (

      {title}

        - {citations - .map(citation => [ - citation.title, - verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.NO_DATA, - citation.pdf.length, - citation - ]) - .sort((a,b) => (b[1] - a[1] || b[2] - a[2] || (a[0].localeCompare(b[0])))) - .map((pair, i) => { - const [ title, uses_dataset, citation ] = pair + {(sortedCitations || []).map((citation, i) => { let cite = { ...citation } cite.id = { _raw: true, @@ -92,7 +102,7 @@ class CitationList extends Component { } const mapStateToProps = state => ({ - api: state.api + api: state.api, }) const mapDispatchToProps = dispatch => ({ actions: bindActionCreators({ ...actions }, dispatch), diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 61faa24a..f5dbc13c 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -140,14 +140,15 @@ class PaperVerify extends Component { institution_3: this.state.institution_3, validate_3: this.state.validate_3, }) - this.next(false) + this.next() } prev() { const { key } = this.props.api.paperInfo.dataset - const { paperInfo } = this.props.api - let citationIndex = (paperInfo.citations || []) - .findIndex(f => f.id === this.state.citation.id) + 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 { @@ -155,7 +156,7 @@ class PaperVerify extends Component { if (citationIndex < 0) { history.push('/paper/' + key + '/info/') } else { - let nextId = paperInfo.citations[citationIndex].id + let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } @@ -163,17 +164,18 @@ class PaperVerify extends Component { next() { const { key } = this.props.api.paperInfo.dataset - const { paperInfo } = this.props.api - let citationIndex = (paperInfo.citations || []) - .findIndex(f => f.id === this.state.citation.id) + 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 >= paperInfo.citations.length) { + if (citationIndex >= citations.length) { history.push('/paper/' + key + '/info/') } else { - let nextId = paperInfo.citations[citationIndex].id + let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } diff --git a/scraper/client/store.js b/scraper/client/store.js index b199ae29..6da60cbe 100644 --- a/scraper/client/store.js +++ b/scraper/client/store.js @@ -15,7 +15,8 @@ const initialState = () => ({ unknownCitations: {}, verify: {}, verifications: {}, - options: {} + options: {}, + sortedCitations: [], }) export default function apiReducer(state = initialState(), action) { @@ -45,6 +46,13 @@ export default function apiReducer(state = initialState(), action) { paperKey: action.paperKey } + case types.system.set_sorted_citations: + console.log(action.sortedCitations || []) + return { + ...state, + sortedCitations: action.sortedCitations || [], + } + default: return state } diff --git a/scraper/client/types.js b/scraper/client/types.js index e6b4142c..22c93a89 100644 --- a/scraper/client/types.js +++ b/scraper/client/types.js @@ -10,6 +10,10 @@ export const api = tagAsType('api', [ 'loading', 'loaded', 'error', 'set_paper_key', ]) +export const system = tagAsType('system', [ + 'set_sorted_citations', +]) + export const init = '@@INIT' export const USES_DATASET = { -- cgit v1.2.3-70-g09d2