import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { courtesyS } from '../util' import * as actions from './faceSearch.actions' const errors = { 'bbox': "Sorry, we couldn't find a face in that image. Please choose an image where the face is large and clear.", 'nomatch': "We didn't find a match.", 'default': "There was an error!", } class FaceSearchResult extends Component { render() { const { dataset } = this.props.payload const { distances, results, error } = this.props.result if (error) { let errorMessage = errors[error.message] || errors.default return (
{errorMessage}
) } if (!results) { return (
) } if (!this.props.result.results.length) { return (
No results
) } 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')}
{distance}
) }) return (
{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)