summaryrefslogtreecommitdiff
path: root/client/faceSearch/faceSearch.query.js
blob: 9f778ca089ee5c9b0181e41d3af3e6a3545235ad (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
import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import { Loader } from '../common'
import * as actions from './faceSearch.actions'

// function parse_bbox(s) {
//   // "BBox: (77,86), (166, 177), width:89, height:91"
//   try {
//     const [x, y, w, h, width, height] = s.replace(/\D/g, ' ').replace(/\s+/g, ' ').trim().split(' ')
//     return { x, y, w, h }
//   }
// }

class FaceSearchQuery extends Component {
  state = {
    image: null
  }

  upload(e) {
    const { payload } = this.props
    const files = e.dataTransfer ? e.dataTransfer.files : e.target.files
    let i
    let file
    for (i = 0; i < files.length; i++) {
      file = files[i]
      if (file && file.type.match('image.*')) break
    }
    if (!file) return
    const fr = new FileReader()
    fr.onload = () => {
      fr.onload = null
      this.setState({ image: fr.result })
    }
    fr.readAsDataURL(files[0])
    this.props.actions.upload(this.props.payload, file)
  }

  render() {
    const { result } = this.props
    const { image } = this.state
    console.log(result)
    const style = {}
    if (image) {
      style.backgroundImage = 'url(' + image + ')'
      style.backgroundSize = 'cover'
      style.opacity = 1
    }
    return (
      <div className='query row'>
        <div className='uploadContainer'>
        {result.loading ?
          <div className='loading' style={style}>
            <Loader />
          </div>
         : <div style={style}>
            {image ? null : <img src="/assets/img/icon_camera.svg" />}

            <input
              type="file"
              name="img"
              accept="image/*"
              onChange={this.upload.bind(this)}
              required
            />
          </div>
        }
        </div>
        <div className='cta'>
          <h2>Search by Image</h2>
          <h3>Searching {13456} images</h3>
          <p>
            {'Use facial recognition to reverse search into the LFW dataset '}
            {'and see if it contains your photos.'}
          </p>
          <ol>
            <li>Upload a photo of yourself</li>
            <li>Use a photo similar to examples below</li>
            <li>Only matches over 85% will be displayed</li>
            <li>Read more tips to improve search results</li>
            <li>{'Your search data is never stored and immediately cleared '}
            {'once you leave this page.'}</li>
          </ol>
          <p>
            Read more about <a href='/about/privacy/'>privacy</a>.
          </p>
        </div>
      </div>
    )
  }
}

const mapStateToProps = state => ({
  result: state.faceSearch.result,
  options: state.faceSearch.options,
})

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

export default connect(mapStateToProps, mapDispatchToProps)(FaceSearchQuery)