summaryrefslogtreecommitdiff
path: root/scraper/client/paper/paper.verify.js
blob: 8cb14d84853c5deee4cb8ea323dec6d5ed6fce9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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,
  uses_dataset: false,
  doesnt_use_dataset: false,
  images_in_paper: false,
  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.getCitationState(sha256)
    console.log('DID MOUNT')
    this.setState(citationState)
  }

  componentDidUpdate(oldProps) {
    const { sha256 } = this.props.match.params
    const { verify } = this.props.api
    const { sha256: oldSha256 } = oldProps.match.params
    const { verify: oldVerify } = oldProps.api
    const oldPaper = oldVerify ? oldVerify.paper : null
    const paper = verify ? verify.paper : null

    if (oldSha256 && sha256 !== oldSha256) {
      console.log('update verification')
      this.props.actions.getVerification(sha256)
      const citationState = this.getCitationState(sha256)
      this.setState({
        ...initialState,
        ...citationState,
      })
    } else if (verify && !verify.loading && verify.paper && (!oldPaper || oldPaper !== verify.paper)) {
      if (paper.error) {
        console.log('USING PAPER VERIFICATION')
        const citationState = this.getCitationState(sha256)
        this.setState({
          ...initialState,
          ...citationState,
        })
      } else {
        // console.log(paper)
        console.log('GOT CUSTOM CITATION STATE', paper)
        const citationState = this.getCitationState(sha256)
        this.setState({
          ...citationState,
          uses_dataset: paper.uses_dataset === "TRUE",
          doesnt_use_dataset: paper.doesnt_use_dataset === "TRUE",
          images_in_paper: paper.images_in_paper === "TRUE",
          verified_by: paper.verified_by,
          notes: paper.notes,
        })
      }
    } 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 }
    return state
  }

  save() {
    console.log(this.state)
    this.props.actions.postVerification({
      paper_id: this.state.citation.id,
      title: this.state.citation.title,
      uses_dataset: this.state.uses_dataset,
      doesnt_use_dataset: this.state.doesnt_use_dataset,
      images_in_paper: this.state.images_in_paper,
      verified_by: this.state.verified_by,
      notes: this.state.notes,
    })
    this.next(false)
  }

  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)
    if (citationIndex === -1) {
      history.push('/paper/' + key + '/info/')
    } else {
      citationIndex += 1
      if (citationIndex >= paperInfo.citations.length) {
        history.push('/paper/' + key + '/info/')
      } else {
        let nextId = paperInfo.citations[citationIndex].id
        history.push('/paper/' + key + '/verify/' + nextId)
      }
    }
  }

  render() {
    let { paperInfo } = this.props.api
    if (paperInfo.loading) return <Loader />
    // console.log(this.state)
    const { citation } = this.state
    if (!citation) {
      return <div>Citation not found in this paper</div>
    }
    // console.log(citation)
    return (
      <div className='form'>
        <h3>{citation.title}</h3>
        <div className='gray'>
          {citation.id}
          {' | PDFs: '}
          {citation.pdf.map((pdf,i) => {
            const domain = pdf.replace('www.','').split('/').slice(2,3)[0] || 'unknown'
            return (
              <a
                key={i}
                onClick={() => this.setState({ pdf_index: i })}
                className={i === this.state.pdf_index ? 'selected pdfLink' : 'pdfLink'}
              >
                {'[' + domain + '] '}
              </a>
            )
          })}
          {' | '}
          <a
            href={'https://www.semanticscholar.org/paper/' + citation.id}
            target="_blank"
            className={i === this.state.pdf_index ? 'selected pdfLink' : 'pdfLink'}
          >
            {'[semantic scholar]'}
          </a>
        </div>

        <div className='param'>
          <label>Uses the dataset?</label>
          <input
            className='vetting'
            type='radio'
            name='uses_dataset'
            checked={!!this.state.uses_dataset}
            onChange={e => this.setState({
              uses_dataset: e.target.checked,
              doesnt_use_dataset: !e.target.checked,
            })}
          />
        </div>

        <div className='param'>
          <label>{"Doesn't use dataset"}</label>
          <input
            className='vetting'
            type='radio'
            name='uses_dataset'
            checked={!!this.state.doesnt_use_dataset}
            onChange={e => this.setState({
              uses_dataset: !e.target.checked,
              doesnt_use_dataset: e.target.checked
            })}
          />
        </div>

        <div className='param'>
          <label>{"Uses images from dataset"}</label>
          <input
            className='vetting'
            type='radio'
            name='images_in_paper'
            checked={!!this.state.images_in_paper}
            onChange={e => this.setState({
              images_in_paper: !e.target.checked,
            })}
          />
        </div>

        <div className='param'>
          <label>Verified by:</label>
          <input
            type='text'
            className='verified_by'
            value={this.state.verified_by}
            placeholder='Verified by'
            onChange={e => this.setState({ verified_by: e.target.value })}
          />
        </div>

        <div className='param'>
          <label>Notes</label>
          <textarea
            rows={4}
            cols={50}
            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 Verification</button>

          <button
            className='btn'
            onClick={this.next.bind(this)}
          >{'Next >'}</button>
        </div>

         <iframe className='pdfViewer' referrerPolicy='no-referrer' src={citation.pdf[this.state.pdf_index]} />
      </div>
    )
  }
}

const mapStateToProps = state => ({
  api: state.api,
})
const mapDispatchToProps = dispatch => ({
  actions: bindActionCreators({ ...actions }, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(PaperVerify)