import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as actions from './faceAnalysis.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."}
),
not_an_image: (
{"Not an image"}
{"Sorry, the file you uploaded was not recognized as an image. Please upload a JPG or PNG image and try again."}
),
}
class FaceAnalysisResult extends Component {
render() {
const { result, timing } = this.props
const { data, error, loading, message } = result
let { step, total } = data || {}
// console.log(step, total)
if (loading) {
return (
)
}
if (error) {
// console.log(error)
let errorMessage = errors[error] || errors.error
return (
{errorMessage}
)
}
// console.log(result)
if (!total) {
return (
)
}
console.log(data.data)
const results = ['blur_fn', 'points_3d_68', 'landmarks_3d_68', 'landmarks_2d_68', 'pose'].map(tag => {
if (tag in data.data) {
const { title, url } = data.data[tag]
return (
{title}
)
}
return null
}).filter(a => a)
return (
{!(step && total && message) ? '' : (
{step} / {total}: {message})}
{results}
Query took {(timing / 1000).toFixed(2)} s.
)
}
}
const mapStateToProps = state => ({
query: state.faceAnalysis.query,
result: state.faceAnalysis.result,
timing: state.faceAnalysis.timing,
options: state.faceAnalysis.options,
})
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators({ ...actions }, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(FaceAnalysisResult)