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
|
import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { courtesyS } from '../util'
import * as actions from './nameSearch.actions'
import { Loader } from '../common'
const errors = {
nomatch: (
<div>
<h3>Name not found</h3>
{"No names matched your query."}
</div>
),
error: (
<div>
<h3>{"No matches found"}</h3>
</div>
),
}
class NameSearchResult extends Component {
render() {
const { dataset } = this.props.payload
const { query, results, loading, error } = this.props.result
console.log(this.props.result)
if (loading) {
return (
<div className='result'>
<div>
<Loader />
</div>
</div>
)
}
if (error) {
console.log(error)
let errorMessage = errors[error] || errors.error
return (
<div className='result'>{errorMessage}</div>
)
}
if (!results) {
return <div className='result'></div>
}
if (!results.length) {
return (
<div className='result'>{errors.nomatch}</div>
)
}
const els = results.map((result, i) => {
const { uuid } = result.uuid
const { fullname, gender, description, images } = result.identity
return (
<div key={i}>
<img src={'https://megapixels.nyc3.digitaloceanspaces.com/v1/media/' + dataset + '/' + uuid + '.jpg'} />
{fullname} {'('}{gender}{')'}<br/>
{description}<br/>
{courtesyS(images, 'image')}{' in dataset'}<br />
</div>
)
})
return (
<div className='result'>
<div className="timing">
{'Search took '}{Math.round(query.timing * 1000) + ' ms'}
</div>
<div className='results'>
{els}
</div>
</div>
)
}
}
const mapStateToProps = state => ({
query: state.nameSearch.query,
result: state.nameSearch.result,
options: state.nameSearch.options,
})
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators({ ...actions }, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(NameSearchResult)
|