diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 17:10:40 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 17:10:40 +0100 |
| commit | 27a557b5c5af1fee23c8be1ffae668b5ed6ba28d (patch) | |
| tree | 3734eeb3e24b057a5191e18e2c80a2feef13f4e3 /scraper/client | |
| parent | 36a44fe10d2501312d16aa5f70b31fd3585fb996 (diff) | |
fix sorting
Diffstat (limited to 'scraper/client')
| -rw-r--r-- | scraper/client/actions.js | 2 | ||||
| -rw-r--r-- | scraper/client/paper/citationList.component.js | 36 | ||||
| -rw-r--r-- | scraper/client/paper/paper.verify.js | 22 | ||||
| -rw-r--r-- | scraper/client/store.js | 10 | ||||
| -rw-r--r-- | scraper/client/types.js | 4 |
5 files changed, 49 insertions, 25 deletions
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 <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.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 = { |
