import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { courtesyS } from '../util' import * as actions from './faceSearch.actions' import { Loader } from '../common' const errors = { bbox: (

No face found

{"Sorry, we didn't detect a face in that image. "} {"Please choose an image where the face is large and clear."}
), nomatch: (

{"You're clear"}

{"No images in this dataset match your face. We show only matches above 70% probability."}
), error: (

{"No matches found"}

{"Sorry, an error occured."}
), } class FaceSearchResult extends Component { render() { const { dataset } = this.props.payload const { query, distances, results, loading, error } = this.props.result if (loading) { return (

Searching...

) } if (error) { console.log(error) let errorMessage = errors[error] || errors.error return (
{errorMessage}
) } if (!results) { return (
{errors.nomatch}
) } if (!this.props.result.results.length) { return (
{errors.nomatch}
) } const els = results.map((result, i) => { const distance = distances[i] const { uuid } = result.uuid const { fullname, gender, description, images } = result.identity return (
{fullname} {'('}{gender}{')'}
{description}
{courtesyS(images, 'image')}{' in dataset'}
{Math.round((1 - distance) * 100)}{'% match'}
) }) return (

Did we find you?

{'These faces matched images in the '} {dataset} {' dataset with over 70% probability.'}
Query took {query.timing.toFixed(2)} seconds
{els}
) } } 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)