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/paper/citationList.component.js | 36 ++++++++++++++++---------- scraper/client/paper/paper.verify.js | 22 +++++++++------- 2 files changed, 35 insertions(+), 23 deletions(-) (limited to 'scraper/client/paper') 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) } } -- cgit v1.2.3-70-g09d2