From 7eb3c04ef85fa0311bdf30b24df2aba102757878 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 19 Mar 2019 20:45:24 +0100 Subject: rebuild site --- scraper/client/actions.js | 10 ++ scraper/client/app.js | 1 + scraper/client/common/header.component.js | 1 - scraper/client/paper/paper.address.js | 1 + scraper/client/paper/paper.verify.js | 205 ++++++++++++++++++++++ scraper/client/search/browse.component.js | 77 --------- scraper/client/search/index.js | 17 -- scraper/client/search/panicButton.component.js | 49 ------ scraper/client/search/search.actions.js | 162 ----------------- scraper/client/search/search.container.js | 101 ----------- scraper/client/search/search.css | 230 ------------------------- scraper/client/search/search.menu.js | 96 ----------- scraper/client/search/search.meta.js | 68 -------- scraper/client/search/search.query.js | 227 ------------------------ scraper/client/search/search.reducer.js | 84 --------- scraper/client/search/search.results.js | 49 ------ scraper/client/search/search.safety.js | 17 -- scraper/s2-geocode-server.py | 42 ++++- 18 files changed, 258 insertions(+), 1179 deletions(-) create mode 100644 scraper/client/paper/paper.verify.js delete mode 100644 scraper/client/search/browse.component.js delete mode 100644 scraper/client/search/index.js delete mode 100644 scraper/client/search/panicButton.component.js delete mode 100644 scraper/client/search/search.actions.js delete mode 100644 scraper/client/search/search.container.js delete mode 100644 scraper/client/search/search.css delete mode 100644 scraper/client/search/search.menu.js delete mode 100644 scraper/client/search/search.meta.js delete mode 100644 scraper/client/search/search.query.js delete mode 100644 scraper/client/search/search.reducer.js delete mode 100644 scraper/client/search/search.results.js delete mode 100644 scraper/client/search/search.safety.js (limited to 'scraper') diff --git a/scraper/client/actions.js b/scraper/client/actions.js index 4e1fd620..8a1f13a6 100644 --- a/scraper/client/actions.js +++ b/scraper/client/actions.js @@ -30,3 +30,13 @@ export const getAddress = sha256 => dispatch => { export const postAddress = data => dispatch => { api(dispatch, post, 'address', '/api/address/add', data) } + +export const getVerification = sha256 => dispatch => { + api(dispatch, get, 'address', '/api/verify/' + sha256, {}) +} + +export const postVerification = data => dispatch => { + api(dispatch, post, 'address', '/api/verify/add', data) +} + + diff --git a/scraper/client/app.js b/scraper/client/app.js index 7600fe52..ab7e2ca7 100644 --- a/scraper/client/app.js +++ b/scraper/client/app.js @@ -21,6 +21,7 @@ export default class App extends Component { + diff --git a/scraper/client/common/header.component.js b/scraper/client/common/header.component.js index 4da5af8a..2f084979 100644 --- a/scraper/client/common/header.component.js +++ b/scraper/client/common/header.component.js @@ -10,7 +10,6 @@ import * as actions from '../actions' class Header extends Component { componentDidMount() { this.props.actions.getPapers() - this.props.actions.getInstitutions() } pickPaper(e) { diff --git a/scraper/client/paper/paper.address.js b/scraper/client/paper/paper.address.js index 267fe16b..90e28139 100644 --- a/scraper/client/paper/paper.address.js +++ b/scraper/client/paper/paper.address.js @@ -28,6 +28,7 @@ class PaperAddress extends Component { componentDidMount() { const { sha256 } = this.props.match.params + this.props.actions.getInstitutions() this.props.actions.getAddress(sha256) const citationState = this.getCitationState(sha256) console.log('DID MOUNT') diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js new file mode 100644 index 00000000..cfce8f28 --- /dev/null +++ b/scraper/client/paper/paper.verify.js @@ -0,0 +1,205 @@ +import React, { Component } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import * as actions from '../actions' + +import { history } from '../store' + +import { Loader, Autocomplete } from '../common' + +const initialState = { + citation: null, + verify: '', + verified_by: '', + notes: '', + pdf_index: 0, +} +class PaperVerify extends Component { + state = { + ...initialState + } + + componentDidMount() { + const { sha256 } = this.props.match.params + this.props.actions.getInstitutions() + this.props.actions.getVerification(sha256) + const citationState = this.getVerificationState(sha256) + console.log('DID MOUNT') + this.setState(citationState) + } + + componentDidUpdate(oldProps) { + const { sha256 } = this.props.match.params + const { address } = this.props.api + const { sha256: oldSha256 } = oldProps.match.params + const { address: oldAddress } = oldProps.api + const oldPaper = oldAddress ? oldAddress.paper : null + const paper = address ? address.paper : null + + if (oldSha256 && sha256 !== oldSha256) { + console.log('update address') + this.props.actions.getVerification(sha256) + const citationState = this.getCitationState(sha256) + this.setState({ + ...initialState, + ...citationState, + }) + } else if (address && !address.loading && address.paper && (!oldPaper || oldPaper !== address.paper)) { + if (paper.error) { + console.log('USING PAPER ADDRESS') + const citationState = this.getCitationState(sha256) + this.setState({ + ...initialState, + ...citationState, + }) + } else { + // console.log(paper) + console.log('GOT CUSTOM ADDRESS') + const citationState = this.getCitationState(sha256) + this.setState({ + ...citationState, + verified: paper.verified, + verified_by: paper.verified_by, + }) + } + } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { + const citationState = this.getCitationState(sha256) + this.setState(citationState) + } + } + + getCitationState(sha256) { + const { paperInfo, unknownCitations } = this.props.api + let citation = (unknownCitations.citations || []).find(f => f.id === sha256) + if (!citation) { + citation = (paperInfo.citations || []).find(f => f.id === sha256) + } + // console.log(sha256, citation) + let state = { citation } + let addresses = citation ? citation.addresses : [] + if (addresses) { + addresses.forEach((address, i) => { + state['institution_' + (i + 1)] = address.address + }) + } + return state + } + + save() { + console.log(this.state) + this.props.actions.postVerification({ + paper_id: this.state.citation.id, + title: this.state.citation.title, + verified: this.state.verified, + verified_by: this.state.verified_by, + notes: this.state.notes, + }) + this.next(false) + } + + next() { + const { key } = this.props.api.paperInfo.dataset + const { unknownCitations } = this.props.api + let citationIndex = (unknownCitations.citations || []) + .findIndex(f => f.id === this.state.citation.id) + if (citationIndex === -1) { + history.push('/paper/' + key + '/info/') + } else { + citationIndex += 1 + if (citationIndex >= unknownCitations.length) { + history.push('/paper/' + key + '/info/') + } else { + let nextId = unknownCitations.citations[citationIndex].id + history.push('/paper/' + key + '/address/' + nextId) + } + } + } + + render() { + let { paperInfo, unknownCitations } = this.props.api + if (paperInfo.loading || unknownCitations.loading) return + console.log(this.state) + const { citation } = this.state + if (!citation) { + return
Citation not found in this paper
+ } + console.log(citation) + return ( +
+

{citation.title}

+
+ {citation.id} + {' | PDFs: '} + {citation.pdf.map((pdf,i) => { + const domain = pdf.replace('www.','').split('/').slice(2,3)[0] || 'unknown' + return ( + this.setState({ pdf_index: i })} + className={i === this.state.pdf_index ? 'selected pdfLink' : 'pdfLink'} + > + {'[' + domain + '] '} + + ) + })} +
+ +
+ this.setState({ + verified: e.target.value, + })} + /> +
+ +
+ this.setState({ notes: e.target.value })} + /> +
+ +
+ this.setState({ notes: e.target.value })} + /> +
+ +
+ + + +
+ +