summaryrefslogtreecommitdiff
path: root/scraper/client/paper/paper.address.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-02-13 22:56:35 +0100
committerJules Laplace <julescarbon@gmail.com>2019-02-13 22:56:35 +0100
commit41247c08ea359d0a72a247992d2019ae2120536c (patch)
tree89becc97e6831dd95cb5d96b297a2ce5d4395009 /scraper/client/paper/paper.address.js
parenta2f1969b2c7c185e04e19c22a83245ad22f8df0c (diff)
interface working
Diffstat (limited to 'scraper/client/paper/paper.address.js')
-rw-r--r--scraper/client/paper/paper.address.js71
1 files changed, 51 insertions, 20 deletions
diff --git a/scraper/client/paper/paper.address.js b/scraper/client/paper/paper.address.js
index ff2bf032..09b20758 100644
--- a/scraper/client/paper/paper.address.js
+++ b/scraper/client/paper/paper.address.js
@@ -4,6 +4,8 @@ import { connect } from 'react-redux'
import * as actions from '../actions'
+import { history } from '../store'
+
import { Loader, Autocomplete } from '../common'
const initialState = {
@@ -16,6 +18,7 @@ const initialState = {
institution_2_vetting: '',
institution_3_vetting: '',
institution_4_vetting: '',
+ notes: '',
}
class PaperAddress extends Component {
state = {
@@ -25,8 +28,9 @@ class PaperAddress extends Component {
componentDidMount() {
const { sha256 } = this.props.match.params
this.props.actions.getAddress(sha256)
- const citation = this.getCitation(sha256)
- this.setState({ citation })
+ const citationState = this.getCitationState(sha256)
+ console.log('DID MOUNT')
+ this.setState(citationState)
}
componentDidUpdate(oldProps) {
@@ -40,23 +44,25 @@ class PaperAddress extends Component {
if (oldSha256 && sha256 !== oldSha256) {
console.log('update address')
this.props.actions.getAddress(sha256)
- const citation = this.getCitation(sha256)
+ const citationState = this.getCitationState(sha256)
this.setState({
...initialState,
- citation
+ ...citationState,
})
} else if (address && !address.loading && address.paper && (!oldPaper || oldPaper !== address.paper)) {
if (paper.error) {
- const citation = this.getCitation(sha256)
+ console.log('USING PAPER ADDRESS')
+ const citationState = this.getCitationState(sha256)
this.setState({
...initialState,
- citation,
+ ...citationState,
})
} else {
// console.log(paper)
- const citation = this.getCitation(sha256)
+ console.log('GOT CUSTOM ADDRESS')
+ const citationState = this.getCitationState(sha256)
this.setState({
- citation,
+ ...citationState,
institution_1: paper.institution_1,
institution_2: paper.institution_2,
institution_3: paper.institution_3,
@@ -68,24 +74,31 @@ class PaperAddress extends Component {
})
}
} else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) {
- const citation = this.getCitation(sha256)
- this.setState({ citation })
+ const citationState = this.getCitationState(sha256)
+ this.setState(citationState)
}
}
- getCitation(sha256) {
+ 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)
- return 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.actions.postAddress({
+ this.props.actions.postAddress({
paper_id: this.state.citation.id,
title: this.state.citation.title,
institution_1: this.state.institution_1,
@@ -96,7 +109,9 @@ class PaperAddress extends Component {
institution_2_vetting: this.state.institution_2_vetting,
institution_3_vetting: this.state.institution_3_vetting,
institution_4_vetting: this.state.institution_4_vetting,
+ notes: this.state.notes,
})
+ history.push('/paper/' + this.props.api.paperInfo.dataset.key + '/random/')
}
render() {
@@ -118,6 +133,7 @@ class PaperAddress extends Component {
autoFocus
className='vetting'
type='text'
+ value={this.state.institution_1_vetting}
placeholder='Paste Institution #1'
onChange={e => this.setState({
institution_1_vetting: e.target.value,
@@ -127,7 +143,6 @@ class PaperAddress extends Component {
autoFocus={false}
placeholder='Institution #1'
value={this.state.institution_1}
- vetting={this.state.institution_1_vetting}
onSelect={value => {
this.setState({ institution_1: value })
// this.institution_2._el.focus()
@@ -141,6 +156,7 @@ class PaperAddress extends Component {
className='vetting'
type='text'
placeholder='Paste Institution #2'
+ value={this.state.institution_2_vetting}
onChange={e => this.setState({
institution_2_vetting: e.target.value,
})}
@@ -160,6 +176,7 @@ class PaperAddress extends Component {
className='vetting'
type='text'
placeholder='Paste Institution #3'
+ value={this.state.institution_3_vetting}
onChange={e => this.setState({
institution_3_vetting: e.target.value,
})}
@@ -180,6 +197,7 @@ class PaperAddress extends Component {
className='vetting'
type='text'
placeholder='Paste Institution #4'
+ value={this.state.institution_4_vetting}
onChange={e => this.setState({
institution_4_vetting: e.target.value,
})}
@@ -195,12 +213,25 @@ class PaperAddress extends Component {
/>
</div>
- <button
- className='btn btn-primary'
- onClick={this.save.bind(this)}
- ref={ref => this.button = ref}
- >Save Institutions</button>
- <iframe className='pdfViewer' src={citation.pdf} />
+ <div className='param'>
+ <input
+ type='text'
+ className='notes'
+ value={this.state.notes}
+ placeholder='Notes'
+ onChange={e => this.setState({ notes: e.target.value })}
+ />
+ </div>
+
+ <div className='param'>
+ <button
+ className='btn btn-primary'
+ onClick={this.save.bind(this)}
+ ref={ref => this.button = ref}
+ >Save Institutions</button>
+ </div>
+
+ <iframe className='pdfViewer' src={citation.pdf} />
</div>
)
}