summaryrefslogtreecommitdiff
path: root/client/faceSearch
diff options
context:
space:
mode:
Diffstat (limited to 'client/faceSearch')
-rw-r--r--client/faceSearch/faceSearch.actions.js57
-rw-r--r--client/faceSearch/faceSearch.container.js31
-rw-r--r--client/faceSearch/faceSearch.query.js73
-rw-r--r--client/faceSearch/faceSearch.reducer.js32
-rw-r--r--client/faceSearch/faceSearch.result.js30
-rw-r--r--client/faceSearch/index.js5
6 files changed, 228 insertions, 0 deletions
diff --git a/client/faceSearch/faceSearch.actions.js b/client/faceSearch/faceSearch.actions.js
new file mode 100644
index 00000000..ccd51201
--- /dev/null
+++ b/client/faceSearch/faceSearch.actions.js
@@ -0,0 +1,57 @@
+// import fetchJsonp from 'fetch-jsonp'
+import * as types from '../types'
+// import { hashPath } from '../util'
+import { store } from '../store'
+import { post, preloadImage } from '../util'
+// import querystring from 'query-string'
+
+// urls
+
+const url = {
+ upload: (dataset) => process.env.API_HOST + '/api/dataset/' + dataset + '/face/',
+}
+export const publicUrl = {
+}
+
+// standard loading events
+
+const loading = (tag, offset) => ({
+ type: types.faceSearch.loading,
+ tag,
+ offset
+})
+const loaded = (tag, data, offset = 0) => ({
+ type: types.faceSearch.loaded,
+ tag,
+ data,
+ offset
+})
+const error = (tag, err) => ({
+ type: types.faceSearch.error,
+ tag,
+ err
+})
+
+// search UI functions
+
+export const updateOptions = opt => dispatch => {
+ dispatch({ type: types.faceSearch.update_options, opt })
+}
+
+// API functions
+
+export const upload = (file, query) => dispatch => {
+ // const { options } = store.getState().faceSearch
+ const tag = 'result'
+ const fd = new FormData()
+ fd.append('query_img', file)
+ // fd.append('limit', options.perPage)
+ if (!query) {
+ dispatch(loading(tag))
+ }
+ post(url.upload(), fd)
+ .then(data => {
+ dispatch(loaded(tag, data))
+ })
+ .catch(err => dispatch(error(tag, err)))
+}
diff --git a/client/faceSearch/faceSearch.container.js b/client/faceSearch/faceSearch.container.js
new file mode 100644
index 00000000..e5fae24b
--- /dev/null
+++ b/client/faceSearch/faceSearch.container.js
@@ -0,0 +1,31 @@
+import React, { Component } from 'react'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+import * as actions from './faceSearch.actions'
+
+import FaceSearchQuery from './faceSearch.query'
+import FaceSearchResult from './faceSearch.result'
+
+class FaceSearchContainer extends Component {
+ render() {
+ return (
+ <div className='searchContainer'>
+ <FaceSearchQuery />
+ <FaceSearchResult />
+ </div>
+ )
+ }
+}
+
+const mapStateToProps = state => ({
+ query: state.faceSearch.query,
+ result: state.faceSearch.result,
+ options: state.faceSearch.options,
+})
+
+const mapDispatchToProps = dispatch => ({
+ actions: bindActionCreators({ ...actions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(FaceSearchContainer)
diff --git a/client/faceSearch/faceSearch.query.js b/client/faceSearch/faceSearch.query.js
new file mode 100644
index 00000000..9313c538
--- /dev/null
+++ b/client/faceSearch/faceSearch.query.js
@@ -0,0 +1,73 @@
+import React, { Component } from 'react'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+import * as actions from './faceSearch.actions'
+
+class FaceSearchQuery extends Component {
+ upload(e) {
+ 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
+ this.props.actions.upload(file)
+ }
+
+ render() {
+ const { result } = this.props
+ return (
+ <div className='query row'>
+ <div className='uploadContainer'>
+ {result.loading ?
+ <div className='loading'>
+ Loading...
+ </div>
+ :
+ <div>
+ <img src="/assets/img/icon_camera.svg" />
+ <input
+ type="file"
+ name="img"
+ accept="image/*"
+ onChange={this.upload.bind(this)}
+ required
+ />
+ </div>
+ }
+ </div>
+ <div class='cta'>
+ <h2>Search This Dataset</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)
diff --git a/client/faceSearch/faceSearch.reducer.js b/client/faceSearch/faceSearch.reducer.js
new file mode 100644
index 00000000..da8bd25e
--- /dev/null
+++ b/client/faceSearch/faceSearch.reducer.js
@@ -0,0 +1,32 @@
+import * as types from '../types'
+
+const initialState = () => ({
+ query: {},
+ result: {},
+ loading: false,
+})
+
+export default function faceSearchReducer(state = initialState(), action) {
+ switch (action.type) {
+ case types.faceSearch.loading:
+ return {
+ ...state,
+ [action.tag]: { loading: true },
+ }
+
+ case types.faceSearch.loaded:
+ return {
+ ...state,
+ [action.tag]: action.data,
+ }
+
+ case types.faceSearch.error:
+ return {
+ ...state,
+ [action.tag]: { error: action.err },
+ }
+
+ default:
+ return state
+ }
+}
diff --git a/client/faceSearch/faceSearch.result.js b/client/faceSearch/faceSearch.result.js
new file mode 100644
index 00000000..844a5a70
--- /dev/null
+++ b/client/faceSearch/faceSearch.result.js
@@ -0,0 +1,30 @@
+import React, { Component } from 'react'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+import * as actions from './faceSearch.actions'
+
+class FaceSearchResult extends Component {
+ componentDidMount() {
+ }
+
+ render() {
+ return (
+ <div className='result'>
+ Result here
+ </div>
+ )
+ }
+}
+
+const mapStateToProps = state => ({
+ query: state.faceSearch.query,
+ result: state.faceSearch.result,
+ options: state.faceSearch.options,
+})
+
+const mapDispatchToProps = dispatch => ({
+ actions: bindActionCreators({ ...actions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(FaceSearchResult)
diff --git a/client/faceSearch/index.js b/client/faceSearch/index.js
new file mode 100644
index 00000000..32f6dcc6
--- /dev/null
+++ b/client/faceSearch/index.js
@@ -0,0 +1,5 @@
+import Container from './faceSearch.container'
+
+export {
+ Container,
+}